6.1.0
This commit is contained in:
@@ -1,23 +1,12 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
# Copyright: ...
|
||||
# ...
|
||||
|
||||
DOCUMENTATION = r'''
|
||||
---
|
||||
module: decort_account
|
||||
|
||||
version_added: "2.16"
|
||||
|
||||
description: See L(Module Documentation,https://repository.basistech.ru/BASIS/decort-ansible/wiki/Home).
|
||||
'''
|
||||
|
||||
# EXAMPLES = r'''
|
||||
# '''
|
||||
|
||||
# RETURN = r'''
|
||||
# '''
|
||||
|
||||
from typing import Iterable
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.decort_utils import DecortController
|
||||
|
||||
@@ -1,23 +1,12 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
# Copyright: ...
|
||||
# ...
|
||||
|
||||
DOCUMENTATION = r'''
|
||||
---
|
||||
module: decort_account_info
|
||||
|
||||
version_added: "2.16"
|
||||
|
||||
description: See L(Module Documentation,https://repository.basistech.ru/BASIS/decort-ansible/wiki/Home).
|
||||
'''
|
||||
|
||||
# EXAMPLES = r'''
|
||||
# '''
|
||||
|
||||
# RETURN = r'''
|
||||
# '''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.decort_utils import DecortController
|
||||
|
||||
|
||||
@@ -1,22 +1,17 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Digital Enegry Cloud Orchestration Technology (DECORT) modules for Ansible
|
||||
# Copyright: (c) 2018-2021 Digital Energy Cloud Solutions LLC
|
||||
#
|
||||
# Apache License 2.0 (see http://www.apache.org/licenses/LICENSE-2.0.txt)
|
||||
#
|
||||
|
||||
#
|
||||
# Author: Alexey Dankov (alexey Dankov@digitalenergy.online)
|
||||
DOCUMENTATION = r'''
|
||||
---
|
||||
module: decort_bservice
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'}
|
||||
description: See L(Module Documentation,https://repository.basistech.ru/BASIS/decort-ansible/wiki/Home).
|
||||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.basic import env_fallback
|
||||
from ansible.module_utils.decort_utils import *
|
||||
|
||||
|
||||
class decort_bservice(DecortController):
|
||||
def __init__(self,arg_amodule):
|
||||
super(decort_bservice, self).__init__(arg_amodule)
|
||||
@@ -157,7 +152,6 @@ class decort_bservice(DecortController):
|
||||
return dict(
|
||||
account_id=dict(type='int', required=False),
|
||||
account_name=dict(type='str', required=False, default=''),
|
||||
annotation=dict(type='str', required=False, default=''),
|
||||
app_id=dict(type='str',
|
||||
required=False,
|
||||
fallback=(env_fallback, ['DECORT_APP_ID'])),
|
||||
@@ -193,7 +187,6 @@ class decort_bservice(DecortController):
|
||||
id=dict(type='int', required=False, default=0),
|
||||
rg_id=dict(type='int', default=0),
|
||||
rg_name=dict(type='str',default=""),
|
||||
description=dict(type='str', default="Created by decort ansible module"),
|
||||
verify_ssl=dict(type='bool', required=False, default=True),
|
||||
workflow_callback=dict(type='str', required=False),
|
||||
workflow_context=dict(type='str', required=False),)
|
||||
|
||||
@@ -1,256 +1,18 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Digital Enegry Cloud Orchestration Technology (DECORT) modules for Ansible
|
||||
# Copyright: (c) 2018-2021 Digital Energy Cloud Solutions LLC
|
||||
#
|
||||
# Apache License 2.0 (see http://www.apache.org/licenses/LICENSE-2.0.txt)
|
||||
#
|
||||
|
||||
#
|
||||
# Author: Sergey Shubin (sergey.shubin@digitalenergy.online)
|
||||
#
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'}
|
||||
|
||||
DOCUMENTATION = '''
|
||||
DOCUMENTATION = r'''
|
||||
---
|
||||
module: decort_disk
|
||||
short_description: Manage Disks (virtualized storage resources) in DECORT cloud
|
||||
description: >
|
||||
This module can be used to create new disk in DECORT cloud platform, obtain or
|
||||
modify its characteristics, and delete it.
|
||||
version_added: "2.2"
|
||||
author:
|
||||
- Sergey Shubin <sergey.shubin@digitalenergy.online>
|
||||
requirements:
|
||||
- python >= 2.6
|
||||
- PyJWT Python module
|
||||
- requests Python module
|
||||
- netaddr Python module
|
||||
- decort_utils utility library (module)
|
||||
- DECORT cloud platform version 3.6.1 or higher
|
||||
notes:
|
||||
- Environment variables can be used to pass selected parameters to the module, see details below.
|
||||
- Specified Oauth2 provider must be trusted by the DECORT cloud controller on which JWT will be used.
|
||||
- 'Similarly, JWT supplied in I(authenticator=jwt) mode should be received from Oauth2 provider trusted by
|
||||
the DECORT cloud controller on which this JWT will be used.'
|
||||
options:
|
||||
account_id:
|
||||
description:
|
||||
- ID of the account, which owns this disk. This is the alternative to I(account_name) option.
|
||||
- If both I(account_id) and I(account_name) specified, then I(account_name) is ignored.
|
||||
default: 0
|
||||
required: no
|
||||
account_name:
|
||||
description:
|
||||
- 'Name of the account, which will own this disk.'
|
||||
- 'This parameter is ignored if I(account_id) is specified.'
|
||||
default: empty string
|
||||
required: no
|
||||
annotation:
|
||||
description:
|
||||
- Optional text description of this disk.
|
||||
default: empty string
|
||||
required: no
|
||||
app_id:
|
||||
description:
|
||||
- 'Application ID for authenticating to the DECORT controller when I(authenticator=oauth2).'
|
||||
- 'Required if I(authenticator=oauth2).'
|
||||
- 'If not found in the playbook or command line arguments, the value will be taken from DECORT_APP_ID
|
||||
environment variable.'
|
||||
required: no
|
||||
app_secret:
|
||||
description:
|
||||
- 'Application API secret used for authenticating to the DECORT controller when I(authenticator=oauth2).'
|
||||
- This parameter is required when I(authenticator=oauth2) and ignored in other modes.
|
||||
- 'If not found in the playbook or command line arguments, the value will be taken from DECORT_APP_SECRET
|
||||
environment variable.'
|
||||
required: no
|
||||
authenticator:
|
||||
description:
|
||||
- Authentication mechanism to be used when accessing DECORT controller and authorizing API call.
|
||||
default: jwt
|
||||
choices: [ jwt, oauth2, legacy ]
|
||||
required: yes
|
||||
controller_url:
|
||||
description:
|
||||
- URL of the DECORT controller that will be contacted to manage the RG according to the specification.
|
||||
- 'This parameter is always required regardless of the specified I(authenticator) type.'
|
||||
required: yes
|
||||
id:
|
||||
description:
|
||||
- `ID of the disk to manage. If I(id) is specified it is assumed, that this disk already
|
||||
exists. In other words, you cannot create new disk by specifying its ID, use I(name)
|
||||
when creating new disk.`
|
||||
- `If non-zero I(id) is specified, then I(name), I(account_id) and I(account_name)
|
||||
are ignored.`
|
||||
default: 0
|
||||
required: no
|
||||
name:
|
||||
description:
|
||||
- `Name of the disk to manage. To manage disk by name you also need to specify either
|
||||
I(account_id) or I(account_name).`
|
||||
- If non-zero I(id) is specified, I(name) is ignored.
|
||||
- `Note that the platform does not enforce uniqueness of disk names, so if more than one
|
||||
disk with this name exists under the specified account, module will return the first
|
||||
occurence.`
|
||||
default: empty string
|
||||
required: no
|
||||
force_detach:
|
||||
description:
|
||||
- `By default it is not allowed to delete or destroy disk that is currently attached to a compute
|
||||
instance (e.g. virtual machine or bare metal server). Set this argument to true to change this
|
||||
behavior.`
|
||||
- This argument is meaningful for I(state=absent) operations only and ignored otherwise.
|
||||
default: false
|
||||
required: no
|
||||
jwt:
|
||||
description:
|
||||
- 'JWT (access token) for authenticating to the DECORT controller when I(authenticator=jwt).'
|
||||
- 'This parameter is required if I(authenticator=jwt) and ignored for other authentication modes.'
|
||||
- If not specified in the playbook, the value will be taken from DECORT_JWT environment variable.
|
||||
required: no
|
||||
oauth2_url:
|
||||
description:
|
||||
- 'URL of the oauth2 authentication provider to use when I(authenticator=oauth2).'
|
||||
- 'This parameter is required when when I(authenticator=oauth2).'
|
||||
- 'If not specified in the playbook, the value will be taken from DECORT_OAUTH2_URL environment variable.'
|
||||
password:
|
||||
description:
|
||||
- 'Password for authenticating to the DECORT controller when I(authenticator=legacy).'
|
||||
- 'This parameter is required if I(authenticator=legacy) and ignored in other authentication modes.'
|
||||
- If not specified in the playbook, the value will be taken from DECORT_PASSWORD environment variable.
|
||||
required: no
|
||||
place_with:
|
||||
description:
|
||||
- `This argument can be used to simplify data disks creation along with a new compute, by placing
|
||||
disks in the same storage, where corresponding OS image is deployed.`
|
||||
- `Specify ID of an OS image, and the newly created disk will be provisioned from the same
|
||||
storage, where this OS image is located. You may optionally specify I(pool) to control
|
||||
actual disk placement within that storage, or leave I(pool=default) to let platform manage
|
||||
it automatically.`
|
||||
- This parameter is used when creating new disks and ignored for all other operations.
|
||||
- This is an alternative to specifying I(sep_id).
|
||||
default: 0
|
||||
required: no
|
||||
pool:
|
||||
description:
|
||||
- Name of the pool where to place new disk. Once disk is created, its pool cannot be changed.
|
||||
- This parameter is used when creating new disk and igonred for all other operations.
|
||||
default: empty string
|
||||
required: no
|
||||
sep_id:
|
||||
description:
|
||||
- `ID of the Storage Endpoint Provider (SEP) where to place new disk. Once disk is created,
|
||||
its SEP cannot be changed.`
|
||||
- `You may think of SEP as an identifier of a storage system connected to DECORT platform. There
|
||||
may be several different storage systems and, consequently, several SEPs available to choose from.`
|
||||
- This parameter is used when creating new disk and igonred for all other operations.
|
||||
- See also I(place_with) for an alternative way to specify disk placement.
|
||||
default: 0
|
||||
required: no
|
||||
size:
|
||||
description:
|
||||
- Size of the disk in GB. This parameter is mandatory when creating new disk.
|
||||
- `If specified for an existing disk, and it is greater than current disk size, platform will try to resize
|
||||
the disk on the fly. Downsizing disk is not allowed.`
|
||||
required: no
|
||||
limitIO:
|
||||
description:
|
||||
- Disk input / output limit, used to limit the speed of interaction with the disk.
|
||||
required: no
|
||||
type:
|
||||
description:
|
||||
- Type of the disk.
|
||||
- `Disks can be of the following types: "D"-Data, "B"-Boot, "T"-Tmp.`
|
||||
default: "D"
|
||||
required: no
|
||||
state:
|
||||
description:
|
||||
- Specify the desired state of the disk at the exit of the module.
|
||||
- 'If desired I(state=present):'
|
||||
- ' - Disk does not exist or is in [DESTROYED, PURGED] states, create new disk according to the specifications.'
|
||||
- ' - Disk is in DELETED state, restore it and change size if necessary.'
|
||||
- ' - Disk is in one of [CREATED, ASSIGNED] states, do nothing.'
|
||||
- ' - Disk in any other state, abort with an error.'
|
||||
- 'If desired I(state=absent):'
|
||||
- ' - Disk is in one of [CREATED, ASSIGNED, DELETED] states, destroy it.'
|
||||
- ' - Disk not found or in [DESTROYED, PURGED] states, do nothing.'
|
||||
- ' - Disk in any other state, abort with an error.'
|
||||
default: present
|
||||
choices: [ absent, present ]
|
||||
user:
|
||||
description:
|
||||
- 'Name of the legacy user for authenticating to the DECORT controller when I(authenticator=legacy).'
|
||||
- 'This parameter is required when I(authenticator=legacy) and ignored for other authentication modes.'
|
||||
- If not specified in the playbook, the value will be taken from DECORT_USER environment variable.
|
||||
required: no
|
||||
verify_ssl:
|
||||
description:
|
||||
- 'Controls SSL verification mode when making API calls to DECORT controller. Set it to False if you
|
||||
want to disable SSL certificate verification. Intended use case is when you run module in a trusted
|
||||
environment that uses self-signed certificates. Note that disabling SSL verification in any other
|
||||
scenario can lead to security issues, so please know what you are doing.'
|
||||
default: True
|
||||
required: no
|
||||
workflow_callback:
|
||||
description:
|
||||
- 'Callback URL that represents an application, which invokes this module (e.g. up-level orchestrator or
|
||||
end-user portal) and may except out-of-band updates on progress / exit status of the module run.'
|
||||
- API call at this URL will be used to relay such information to the application.
|
||||
- 'API call payload will include module-specific details about this module run and I(workflow_context).'
|
||||
required: no
|
||||
workflow_context:
|
||||
description:
|
||||
- 'Context data that will be included into the payload of the API call directed at I(workflow_callback) URL.'
|
||||
- 'This context data is expected to uniquely identify the task carried out by this module invocation so
|
||||
that up-level orchestrator could match returned information to the its internal entities.'
|
||||
required: no
|
||||
|
||||
description: See L(Module Documentation,https://repository.basistech.ru/BASIS/decort-ansible/wiki/Home).
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- name: create new Disk named "MyDataDisk01" of size 50 GB, on SEP ID 1, in default pool, under the account "MyAccount".
|
||||
decort_vins:
|
||||
authenticator: oauth2
|
||||
app_id: "{{ MY_APP_ID }}"
|
||||
app_secret: "{{ MY_APP_SECRET }}"
|
||||
controller_url: "https://cloud.digitalenergy.online"
|
||||
name: "MyDataDisk01"
|
||||
sep_id: 1
|
||||
size: 50
|
||||
account_name: "MyAccount"
|
||||
state: present
|
||||
delegate_to: localhost
|
||||
register: my_disk
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
facts:
|
||||
description: facts about the disk
|
||||
returned: always
|
||||
type: dict
|
||||
sample:
|
||||
facts:
|
||||
id: 50
|
||||
name: data01
|
||||
size: 10
|
||||
sep_id: 1
|
||||
pool: datastore
|
||||
state: ASSIGNED
|
||||
account_id: 7
|
||||
computes: {vm_id: vm_name}
|
||||
gid: 1001
|
||||
'''
|
||||
|
||||
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.basic import env_fallback
|
||||
|
||||
from ansible.module_utils.decort_utils import *
|
||||
|
||||
|
||||
class decort_disk(DecortController):
|
||||
def __init__(self,arg_amodule):
|
||||
super(decort_disk, self).__init__(arg_amodule)
|
||||
@@ -308,7 +70,7 @@ class decort_disk(DecortController):
|
||||
|
||||
self.disk_id = self.disk_create(accountId=self.acc_id,
|
||||
name = self.amodule.params['name'],
|
||||
description=self.amodule.params['annotation'],
|
||||
description=self.amodule.params['description'],
|
||||
size=self.amodule.params['size'],
|
||||
type=self.amodule.params['type'],
|
||||
iops=self.amodule.params['iops'],
|
||||
@@ -422,7 +184,7 @@ class decort_disk(DecortController):
|
||||
return dict(
|
||||
account_id=dict(type='int', required=False, default=0),
|
||||
account_name=dict(type='str', required=False, default=''),
|
||||
annotation=dict(type='str', required=False, default='Disk by decort_disk'),
|
||||
description=dict(type='str', required=False, default='Disk by decort_disk'),
|
||||
app_id=dict(type='str',
|
||||
required=False,
|
||||
fallback=(env_fallback, ['DECORT_APP_ID'])),
|
||||
|
||||
@@ -1,22 +1,17 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Digital Enegry Cloud Orchestration Technology (DECORT) modules for Ansible
|
||||
# Copyright: (c) 2018-2021 Digital Energy Cloud Solutions LLC
|
||||
#
|
||||
# Apache License 2.0 (see http://www.apache.org/licenses/LICENSE-2.0.txt)
|
||||
#
|
||||
|
||||
#
|
||||
# Author: Alexey Dankov (alexey.dankov@digitalenergy.online)
|
||||
DOCUMENTATION = r'''
|
||||
---
|
||||
module: decort_group
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'}
|
||||
description: See L(Module Documentation,https://repository.basistech.ru/BASIS/decort-ansible/wiki/Home).
|
||||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.basic import env_fallback
|
||||
from ansible.module_utils.decort_utils import *
|
||||
|
||||
|
||||
class decort_group(DecortController):
|
||||
def __init__(self,arg_amodule):
|
||||
super(decort_group, self).__init__(arg_amodule)
|
||||
@@ -154,7 +149,6 @@ class decort_group(DecortController):
|
||||
state="CHECK_MODE",
|
||||
account_id=0,
|
||||
rg_id=0,
|
||||
config=None,
|
||||
)
|
||||
|
||||
if check_mode:
|
||||
@@ -180,7 +174,6 @@ class decort_group(DecortController):
|
||||
return dict(
|
||||
account_id=dict(type='int', required=False),
|
||||
account_name=dict(type='str', required=False, default=''),
|
||||
annotation=dict(type='str', required=False, default=''),
|
||||
app_id=dict(type='str',
|
||||
required=False,
|
||||
fallback=(env_fallback, ['DECORT_APP_ID'])),
|
||||
@@ -235,7 +228,6 @@ class decort_group(DecortController):
|
||||
)
|
||||
)
|
||||
),
|
||||
description=dict(type='str', default="Created by decort ansible module"),
|
||||
verify_ssl=dict(type='bool', required=False, default=True),
|
||||
workflow_callback=dict(type='str', required=False),
|
||||
workflow_context=dict(type='str', required=False),)
|
||||
|
||||
@@ -1,86 +1,10 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Digital Enegry Cloud Orchestration Technology (DECORT) modules for Ansible
|
||||
# Copyright: (c) 2018-2021 Digital Energy Cloud Solutions LLC
|
||||
#
|
||||
# Apache License 2.0 (see http://www.apache.org/licenses/LICENSE-2.0.txt)
|
||||
#
|
||||
|
||||
#
|
||||
# Author: Sergey Shubin (sergey.shubin@digitalenergy.online)
|
||||
#
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'}
|
||||
|
||||
DOCUMENTATION = '''
|
||||
DOCUMENTATION = r'''
|
||||
---
|
||||
module: decort_jwt
|
||||
short_description: Obtain access token to be used for authentication to DECORT cloud controller
|
||||
description:
|
||||
- Obtain JWT (JSON Web Token) from the specified Oauth2 provider. This JWT can be used in subsequent DECS modules'
|
||||
invocations to authenticate them to the DECS cloud controller.
|
||||
version_added: "2.4"
|
||||
author: "Sergey Shubin (sergey.shubin@digitalenergy.online)"
|
||||
notes:
|
||||
- Environment variables can be used to pass parameters to the module (see options below for details).
|
||||
- Specified Oauth2 provider must be trusted by the DECORT cloud controller on which JWT will be used.
|
||||
- 'If you register module output as I(my_jwt), the JWT value is accessed as I(my_jwt.jwt)'
|
||||
requirements:
|
||||
- python >= 2.6
|
||||
- PyJWT module
|
||||
- requests module
|
||||
- decort_utils utility library (module)
|
||||
- DECORT cloud platform version 3.6.1 or higher
|
||||
options:
|
||||
app_id:
|
||||
description:
|
||||
- 'Application ID for authenticating to the Oauth2 provider specified in I(oauth2_url).'
|
||||
- 'If not found in the playbook or command line arguments, the value will be taken from DECORT_APP_ID
|
||||
environment variable.'
|
||||
required: no
|
||||
app_secret:
|
||||
description:
|
||||
- 'Application API secret used for authenticating to the Oauth2 provider specified in I(oauth2_url).'
|
||||
- 'If not found in the playbook or command line arguments, the value will be taken from DECORT_APP_SECRET
|
||||
environment variable.'
|
||||
required: no
|
||||
oauth2_url:
|
||||
description:
|
||||
- 'URL of the oauth2 authentication provider to obtain JWT from.'
|
||||
- If not specified in the playbook, the value will be taken from DECORT_OAUTH2_URL environment variable.
|
||||
validity:
|
||||
description:
|
||||
- Validity of the JWT in seconds. Default value is 3600 (one hour).
|
||||
required: no
|
||||
verify_ssl:
|
||||
description:
|
||||
- 'Controls SSL verification mode when making API calls to DECS controller. Set it to False if you
|
||||
want to disable SSL certificate verification.'
|
||||
- `Intended use case is when you run module in a trusted environment that uses self-signed certificates.
|
||||
Note that disabling SSL verification in any other scenario can lead to security issues, so please use
|
||||
with caution.'
|
||||
default: True
|
||||
required: no
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- name: Obtain JWT and store it as my_jwt for authenticating subsequent task to DECORT cloud controller
|
||||
decort_jwt:
|
||||
app_id: "{{ my_app_id }}"
|
||||
app_secret: "{{ my_app_secret }}"
|
||||
oauth2_url: https://sso.decs.online
|
||||
delegate_to: localhost
|
||||
register: my_jwt
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
jwt:
|
||||
description: JSON Web Token that can be used to access DECS cloud controller
|
||||
returned: always
|
||||
type: string
|
||||
sample: None
|
||||
description: See L(Module Documentation,https://repository.basistech.ru/BASIS/decort-ansible/wiki/Home).
|
||||
'''
|
||||
|
||||
import requests
|
||||
@@ -88,6 +12,7 @@ import requests
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.basic import env_fallback
|
||||
|
||||
|
||||
def decort_jwt_parameters():
|
||||
"""Build and return a dictionary of parameters expected by decort_jwt module in a form accepted
|
||||
by AnsibleModule utility class"""
|
||||
|
||||
@@ -1,83 +1,39 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Digital Enegry Cloud Orchestration Technology (DECORT) modules for Ansible
|
||||
# Copyright: (c) 2018-2023 Digital Energy Cloud Solutions LLC
|
||||
#
|
||||
# Apache License 2.0 (see http://www.apache.org/licenses/LICENSE-2.0.txt)
|
||||
#
|
||||
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'}
|
||||
DOCUMENTATION = '''
|
||||
DOCUMENTATION = r'''
|
||||
---
|
||||
---
|
||||
'''
|
||||
module: decort_k8s
|
||||
|
||||
EXAMPLES = '''
|
||||
- name: Create k8s cluster
|
||||
decort_k8s:
|
||||
verify_ssl: false
|
||||
authenticator: jwt
|
||||
jwt: "{{ run_jwt.jwt }}"
|
||||
controller_url: "{{CONTROLLER_URL}}"
|
||||
name: SOME_NAME
|
||||
rg_id: {{RG_ID}}
|
||||
k8ci_id: 10
|
||||
master_count: 3
|
||||
master_cpu: 2
|
||||
master_ram: 2048
|
||||
master_disk: 10
|
||||
state: present
|
||||
permanent: True
|
||||
started: True
|
||||
getConfig: True
|
||||
network_plugin: flannel
|
||||
workers:
|
||||
- name: wg1
|
||||
ram: 1024
|
||||
cpu: 2
|
||||
disk: 10
|
||||
num: 1
|
||||
labels:
|
||||
- disktype1=ssd1
|
||||
- disktype2=ssd2
|
||||
- disktype3=ssd3
|
||||
taints:
|
||||
- key1=value1:NoSchedule
|
||||
- key2=value2:NoSchedule
|
||||
- key3=value3:NoSchedule
|
||||
annotations:
|
||||
- node.deckhouse.io/group1=g1
|
||||
- node.deckhouse.io/group2=g2
|
||||
- node.deckhouse.io/group3=g3
|
||||
- name: wg2
|
||||
ram: 1024
|
||||
cpu: 2
|
||||
disk: 10
|
||||
num: 1
|
||||
labels:
|
||||
- apptype=main
|
||||
annotations:
|
||||
- node.mainapp.domen.local/group1=g1
|
||||
register: some_cluster
|
||||
description: See L(Module Documentation,https://repository.basistech.ru/BASIS/decort-ansible/wiki/Home).
|
||||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.basic import env_fallback
|
||||
from ansible.module_utils.decort_utils import *
|
||||
from copy import deepcopy
|
||||
|
||||
|
||||
class decort_k8s(DecortController):
|
||||
def __init__(self,arg_amodule):
|
||||
super(decort_k8s, self).__init__(arg_amodule)
|
||||
|
||||
|
||||
validated_acc_id = 0
|
||||
validated_rg_id = 0
|
||||
validated_rg_facts = None
|
||||
validated_k8ci_id = 0
|
||||
self.k8s_should_exist = False
|
||||
|
||||
self.wg_default_params = {
|
||||
'num': 1,
|
||||
'cpu': 1,
|
||||
'ram': 1024,
|
||||
'labels': [],
|
||||
'taints': [],
|
||||
'annotations': [],
|
||||
'ci_user_data': {},
|
||||
'chipset': 'i440fx',
|
||||
}
|
||||
|
||||
if arg_amodule.params['name'] == "" and arg_amodule.params['id'] is None:
|
||||
self.result['failed'] = True
|
||||
self.result['changed'] = False
|
||||
@@ -208,6 +164,16 @@ class decort_k8s(DecortController):
|
||||
return
|
||||
|
||||
def create(self):
|
||||
master_chipset = self.amodule.params['master_chipset']
|
||||
if master_chipset is None:
|
||||
master_chipset = 'i440fx'
|
||||
|
||||
target_wgs = deepcopy(self.amodule.params['workers'])
|
||||
for wg in target_wgs:
|
||||
for param, default_value in self.wg_default_params.items():
|
||||
if wg[param] is None:
|
||||
wg[param] = default_value
|
||||
|
||||
k8s_id = self.k8s_provision(self.amodule.params['name'],
|
||||
self.amodule.params['k8ci_id'],
|
||||
self.amodule.params['rg_id'],
|
||||
@@ -219,7 +185,7 @@ class decort_k8s(DecortController):
|
||||
self.amodule.params['master_disk'],
|
||||
self.amodule.params['master_sepid'],
|
||||
self.amodule.params['master_pool'],
|
||||
self.amodule.params['workers'][0],
|
||||
target_wgs[0],
|
||||
self.amodule.params['extnet_id'],
|
||||
self.amodule.params['with_lb'],
|
||||
self.amodule.params['ha_lb'],
|
||||
@@ -232,6 +198,7 @@ class decort_k8s(DecortController):
|
||||
self.amodule.params['oidc_cert'],
|
||||
self.amodule.params['description'],
|
||||
self.amodule.params['extnet_only'],
|
||||
master_chipset,
|
||||
)
|
||||
|
||||
if not k8s_id:
|
||||
@@ -245,11 +212,13 @@ class decort_k8s(DecortController):
|
||||
k8s_name=self.amodule.params['name'],
|
||||
rg_id=self.rg_id,
|
||||
check_state=False)
|
||||
|
||||
|
||||
if self.k8s_id:
|
||||
self.k8s_should_exist = True
|
||||
if self.k8s_id and len(self.amodule.params['workers'])>1 :
|
||||
self.k8s_workers_modify(self.k8s_info,self.amodule.params['workers'])
|
||||
self.k8s_should_exist = True
|
||||
self.k8s_workers_modify(
|
||||
arg_k8swg=self.k8s_info,
|
||||
arg_modwg=target_wgs,
|
||||
)
|
||||
return
|
||||
|
||||
def destroy(self):
|
||||
@@ -259,6 +228,13 @@ class decort_k8s(DecortController):
|
||||
return
|
||||
|
||||
def action(self, disared_state, started=True, preupdate: bool = False):
|
||||
if self.amodule.params['master_chipset'] is not None:
|
||||
self.result['msg'] = (
|
||||
'"master_chipset" parameter must not be specified '
|
||||
'when modifying an existing K8s cluster.'
|
||||
)
|
||||
self.exit(fail=True)
|
||||
|
||||
if preupdate:
|
||||
# K8s info updating
|
||||
self.k8s_info = self.k8s_get_by_id(k8s_id=self.k8s_id)
|
||||
@@ -270,18 +246,18 @@ class decort_k8s(DecortController):
|
||||
self.k8s_info['techStatus'] == "STARTED"
|
||||
#check groups and modify if needed
|
||||
if self.aparams['workers'] is not None:
|
||||
self.k8s_workers_modify(self.k8s_info, self.aparams['workers'])
|
||||
self.k8s_workers_modify(self.k8s_info, self.amodule.params['workers'])
|
||||
if self.result['changed'] == True:
|
||||
self.k8s_info = self.k8s_get_by_id(k8s_id=self.k8s_id)
|
||||
#TODO check workers metadata and modify if needed
|
||||
|
||||
return
|
||||
|
||||
@staticmethod
|
||||
def build_parameters():
|
||||
return dict(
|
||||
account_id=dict(type='int', required=False),
|
||||
account_name=dict(type='str', required=False, default=''),
|
||||
annotation=dict(type='str', required=False, default=''),
|
||||
app_id=dict(type='str',
|
||||
required=False,
|
||||
fallback=(env_fallback, ['DECORT_APP_ID'])),
|
||||
@@ -369,6 +345,10 @@ class decort_k8s(DecortController):
|
||||
type='list',
|
||||
elements='str',
|
||||
),
|
||||
chipset=dict(
|
||||
type='str',
|
||||
choices=['Q35', 'i440fx'],
|
||||
),
|
||||
),
|
||||
),
|
||||
workers_metadata=dict(type='bool',required=False,default=False),
|
||||
@@ -386,7 +366,12 @@ class decort_k8s(DecortController):
|
||||
oidc_cert=dict(type='raw',required=False,default=None),
|
||||
verify_ssl=dict(type='bool', required=False, default=True),
|
||||
workflow_callback=dict(type='str', required=False),
|
||||
workflow_context=dict(type='str', required=False),)
|
||||
workflow_context=dict(type='str', required=False),
|
||||
master_chipset=dict(
|
||||
type='str',
|
||||
choices=['Q35', 'i440fx'],
|
||||
),
|
||||
)
|
||||
|
||||
def main():
|
||||
module_parameters = decort_k8s.build_parameters()
|
||||
|
||||
@@ -1,355 +1,17 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Digital Enegry Cloud Orchestration Technology (DECORT) modules for Ansible
|
||||
# Copyright: (c) 2018-2023 Digital Energy Cloud Solutions LLC
|
||||
#
|
||||
# Apache License 2.0 (see http://www.apache.org/licenses/LICENSE-2.0.txt)
|
||||
#
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'}
|
||||
|
||||
DOCUMENTATION = '''
|
||||
DOCUMENTATION = r'''
|
||||
---
|
||||
module: decort_kvmvm
|
||||
short_description: Manage KVM virtual machine in DECORT cloud
|
||||
description: >
|
||||
This module can be used to create a KVM based virtual machine in Digital Energy cloud platform from a
|
||||
specified OS image, modify virtual machine's CPU and RAM allocation, change its power state, configure
|
||||
network port forwarding rules, restart guest OS and delete a virtual machine thus releasing
|
||||
corresponding cloud resources.
|
||||
version_added: "2.2"
|
||||
|
||||
requirements:
|
||||
- python >= 3.8
|
||||
- PyJWT Python module
|
||||
- requests Python module
|
||||
- netaddr Python module
|
||||
- decort_utils utility library (module)
|
||||
- DECORT cloud platform version 3.8.6 or higher
|
||||
notes:
|
||||
- Environment variables can be used to pass selected parameters to the module, see details below.
|
||||
- Specified Oauth2 provider must be trusted by the DECORT cloud controller on which JWT will be used.
|
||||
- 'Similarly, JWT supplied in I(authenticator=jwt) mode should be received from Oauth2 provider trusted by
|
||||
the DECORT cloud controller on which this JWT will be used.'
|
||||
options:
|
||||
account_id:
|
||||
description:
|
||||
- 'ID of the account in which this VM will be created (for new VMs) or is located (for already
|
||||
existing VMs). This is the alternative to I(account_name) option.'
|
||||
- If both I(account_id) and I(account_name) specified, then I(account_name) is ignored.
|
||||
- If any one of I(vm_id) or I(rg_id) specified, I(account_id) is ignored.
|
||||
required: no
|
||||
account_name:
|
||||
description:
|
||||
- 'Name of the account in which this VM will be created (for new VMs) or is located (for already
|
||||
existing VMs).'
|
||||
- This parameter is ignored if I(account_id) is specified.
|
||||
- If any one of I(vm_id) or I(rg_id) specified, I(account_name) is ignored.
|
||||
required: no
|
||||
annotation:
|
||||
description:
|
||||
- Optional text description of this VM.
|
||||
default: empty string
|
||||
required: no
|
||||
app_id:
|
||||
description:
|
||||
- 'Application ID for authenticating to the DECORT controller when I(authenticator=oauth2).'
|
||||
- 'Required if I(authenticator=oauth2).'
|
||||
- 'If not found in the playbook or command line arguments, the value will be taken from DECORT_APP_ID
|
||||
environment variable.'
|
||||
required: no
|
||||
app_secret:
|
||||
description:
|
||||
- 'Application API secret used for authenticating to the DECORT controller when I(authenticator=oauth2).'
|
||||
- This parameter is required when I(authenticator=oauth2) and ignored in other modes.
|
||||
- 'If not found in the playbook or command line arguments, the value will be taken from DECORT_APP_SECRET
|
||||
environment variable.'
|
||||
required: no
|
||||
arch:
|
||||
description:
|
||||
- Architecture of the KVM VM. DECORT supports KVM hosts based on Intel x86.
|
||||
- This parameter is used when new KVM VM is created and ignored for all other operations.
|
||||
- Module may fail if your DECORT installation does not have physical nodes of specified architecture.
|
||||
default: X86_64
|
||||
choices: [ X86_64 ]
|
||||
required: yes
|
||||
authenticator:
|
||||
description:
|
||||
- Authentication mechanism to be used when accessing DECORT controller and authorizing API call.
|
||||
default: jwt
|
||||
choices: [ jwt, oauth2, legacy ]
|
||||
required: yes
|
||||
boot_disk:
|
||||
description:
|
||||
- 'Boot disk size in GB. If this parameter is not specified for a new VM, the size of the boot disk
|
||||
will be set to the size of the OS image, which this VM is based on.'
|
||||
- Boot disk is always created in the same storage and pool, as the OS image, which this VM is based on.
|
||||
- Boot disk cannot be detached from VM.
|
||||
required: no
|
||||
controller_url:
|
||||
description:
|
||||
- URL of the DECORT controller that will be contacted to manage the VM according to the specification.
|
||||
- 'This parameter is always required regardless of the specified I(authenticator) type.'
|
||||
required: yes
|
||||
cpu:
|
||||
description:
|
||||
- Number of virtual CPUs to allocate for the VM.
|
||||
- This parameter is required for creating new VM and optional for other operations.
|
||||
- 'If you set this parameter for an existing VM, then the module will check if VM resize is necessary and do
|
||||
it accordingly. Note that resize operation on a running VM may generate errors as not all OS images support
|
||||
hot resize feature.'
|
||||
required: no
|
||||
data_disks:
|
||||
description:
|
||||
- Optional list of integer IDs of the pre-existing disks that will be attached to this VM.
|
||||
- These are additional disks (aka data disks) besides boot disk, which is created and attached automatically.
|
||||
required: no
|
||||
id:
|
||||
description:
|
||||
- ID of the KVM VM to manage.
|
||||
- 'Either I(id) or a combination of VM name I(name) and RG related parameters (either I(rg_id) or a pair of
|
||||
I(account_name) and I(rg_name) is required to manage an existing VM.'
|
||||
- 'This parameter is not required (and ignored) when creating new VM as VM ID is assigned by cloud platform
|
||||
automatically and cannot be changed afterwards. If existing VM is identified by I(id), then I(account_id),
|
||||
I(account_name), I(rg_name) or I(rg_id) parameters will be ignored.'
|
||||
required: no
|
||||
image_id:
|
||||
description:
|
||||
- ID of the OS image to use for VM provisioning.
|
||||
- 'This parameter is valid at VM creation time only and is ignored for operations on existing VMs.'
|
||||
- 'You need to know image ID, e.g. by extracting it with decort_osimage module and storing
|
||||
in a variable prior to calling decort_kvmvm.'
|
||||
- 'If both I(image_id) and I(image_name) are specified, I(image_name) will be ignored.'
|
||||
required: no
|
||||
image_name:
|
||||
description:
|
||||
- Name of the OS image to use for a new VM provisioning.
|
||||
- 'This parameter is valid at VM creation time only and is ignored for operations on existing VMs.'
|
||||
- 'The specified image name will be looked up in the target DECORT controller and error will be generated if
|
||||
no matching image is found.'
|
||||
- 'If both I(image_id) and I(image_name) are specified, I(image_name) will be ignored.'
|
||||
required: no
|
||||
jwt:
|
||||
description:
|
||||
- 'JWT (access token) for authenticating to the DECORT controller when I(authenticator=jwt).'
|
||||
- 'This parameter is required if I(authenticator=jwt) and ignored for other authentication modes.'
|
||||
- If not specified in the playbook, the value will be taken from DECORT_JWT environment variable.
|
||||
required: no
|
||||
name:
|
||||
description:
|
||||
- Name of the VM.
|
||||
- 'To manage VM by I(name) you also need to specify either I(rg_id) or a pair of I(rg_name) and I(account_name).'
|
||||
- 'If both I(name) and I(id) are specified, I(name) will be ignored and I(id) used to locate the VM.'
|
||||
required: no
|
||||
networks:
|
||||
description:
|
||||
- List of dictionaries that specifies network connections for this VM.
|
||||
- Structure of each element is as follows:
|
||||
- ' - (string) type - type of the network connection. Supported types are VINS and EXTNET.'
|
||||
- ' - (int) id - ID of the target network segment. It is ViNS ID for I(net_type=VINS) and
|
||||
external network segment ID for I(net_type=EXTNET)'
|
||||
- ' - (string) ip_addr - optional IP address to request for this connection. If not specified, the
|
||||
platform will assign valid IP address automatically.'
|
||||
- 'If you call decort_kvmvm module for an existing VM, the module will try to reconfigure existing network
|
||||
connections according to the new specification.'
|
||||
- If this parameter is not specified, the VM will have no connections to the network(s).
|
||||
required: no
|
||||
oauth2_url:
|
||||
description:
|
||||
- 'URL of the oauth2 authentication provider to use when I(authenticator=oauth2).'
|
||||
- 'This parameter is required when when I(authenticator=oauth2).'
|
||||
- If not specified in the playbook, the value will be taken from DECORT_OAUTH2_URL environment variable.
|
||||
password:
|
||||
description:
|
||||
- 'Password for authenticating to the DECORT controller when I(authenticator=legacy).'
|
||||
- 'This parameter is required if I(authenticator=legacy) and ignored in other authentication modes.'
|
||||
- If not specified in the playbook, the value will be taken from DECORT_PASSWORD environment variable.
|
||||
required: no
|
||||
ram:
|
||||
description:
|
||||
- Size of RAM in MB to allocate to the VM.
|
||||
- This parameter is required for creating new VM and optional for other operations.
|
||||
- 'If you set this parameter for an existing VM, then the module will check if VM resize is necessary and do
|
||||
it accordingly. Note that resize operation on a running VM may generate errors as not all OS images support
|
||||
hot resize feature.'
|
||||
required: no
|
||||
ssh_key:
|
||||
description:
|
||||
- 'SSH public key to be deployed on to the new VM for I(ssh_key_user). If I(ssh_key_user) is not specified,
|
||||
the key will not be deployed, and a warning is generated.'
|
||||
- This parameter is valid at VM creation time only and ignored for any operation on existing VMs.
|
||||
required: no
|
||||
ssh_key_user:
|
||||
description:
|
||||
- User for which I(ssh_key) should be deployed.
|
||||
- If I(ssh_key) is not specified, this parameter is ignored and a warning is generated.
|
||||
- This parameter is valid at VM creation time only and ignored for any operation on existing VMs.
|
||||
required: no
|
||||
user_data:
|
||||
description:
|
||||
- Cloud-init User-Data, exept ssh module
|
||||
state:
|
||||
description:
|
||||
- Specify the desired state of the virtual machine at the exit of the module.
|
||||
- 'Regardless of I(state), if VM exists and is in one of [MIGRATING, DESTROYING, ERROR] states, do nothing.'
|
||||
- 'If desired I(state=check):'
|
||||
- ' - Just check if VM exists in any state and return its current specifications.'
|
||||
- ' - If VM does not exist, fail the task.'
|
||||
- 'If desired I(state=present):'
|
||||
- ' - VM does not exist, create the VM according to the specifications and start it.'
|
||||
- ' - VM in one of [RUNNING, PAUSED, HALTED] states, attempt resize if necessary, change network if necessary.'
|
||||
- ' - VM in DELETED state, restore and start it.'
|
||||
- ' - VM in DESTROYED state, recreate the VM according to the specifications and start it.'
|
||||
- 'If desired I(state=poweredon):'
|
||||
- ' - VM does not exist, create it according to the specifications.'
|
||||
- ' - VM in RUNNING state, attempt resize if necessary, change network if necessary.'
|
||||
- ' - VM in one of [PAUSED, HALTED] states, attempt resize if necessary, change network if necessary, next
|
||||
start the VM.'
|
||||
- ' - VM in DELETED state, restore it.'
|
||||
- ' - VM in DESTROYED state, create it according to the specifications.'
|
||||
- 'If desired I(state=absent):'
|
||||
- ' - VM in one of [RUNNING, PAUSED, HALTED] states, destroy it.'
|
||||
- ' - VM in one of [DELETED, DESTROYED] states, do nothing.'
|
||||
- 'If desired I(state=paused):'
|
||||
- ' - VM in RUNNING state, pause the VM, resize if necessary, change network if necessary.'
|
||||
- ' - VM in one of [PAUSED, HALTED] states, resize if necessary, change network if necessary.'
|
||||
- ' - VM in one of [DELETED, DESTROYED] states, abort with an error.'
|
||||
- 'If desired I(state=poweredoff) or I(state=halted):'
|
||||
- ' - VM does not exist, create the VM according to the specifications and leave it in HALTED state.'
|
||||
- ' - VM in RUNNING state, stop the VM, resize if necessary, change network if necessary.'
|
||||
- ' - VM in one of [PAUSED, HALTED] states, resize if necessary, change network if necessary.'
|
||||
- ' - VM in DELETED state, abort with an error.'
|
||||
- ' - VM in DESTROYED state, recreate the VM according to the specifications and leave it in HALTED state.'
|
||||
default: present
|
||||
choices: [ present, absent, poweredon, poweredoff, halted, paused, check ]
|
||||
tags:
|
||||
description:
|
||||
- Dict of custom tags to be assigned to the VM.
|
||||
- These tags are arbitrary text that can be used for grouping or indexing the VMs by other applications.
|
||||
required: no
|
||||
user:
|
||||
description:
|
||||
- 'Name of the legacy user for authenticating to the DECORT controller when I(authenticator=legacy).'
|
||||
- 'This parameter is required when I(authenticator=legacy) and ignored for other authentication modes.'
|
||||
- If not specified in the playbook, the value will be taken from DECORT_USER environment variable.
|
||||
required: no
|
||||
rg_id:
|
||||
description:
|
||||
- ID of the Resource Group where a new VM will be deployed or an existing VM can be found.
|
||||
- 'This parameter may be required when managing VM by its I(name). If you specify I(rg_id), then
|
||||
I(account_name), I(account_id) and I(rg_name) will be ignored.'
|
||||
required: no
|
||||
rg_name:
|
||||
description:
|
||||
- Name of the RG where the VM will be deployed (for new VMs) or can be found (for existing VMs).
|
||||
- This parameter is required when managing VM by its I(name).
|
||||
- If both I(rg_id) and I(rg_name) are specified, I(rg_name) will be ignored.
|
||||
- If I(rg_name) is specified, then either I(account_name) or I(account_id) must also be set.
|
||||
required: no
|
||||
verify_ssl:
|
||||
description:
|
||||
- 'Controls SSL verification mode when making API calls to DECORT controller. Set it to False if you
|
||||
want to disable SSL certificate verification. Intended use case is when you run module in a trusted
|
||||
environment that uses self-signed certificates. Note that disabling SSL verification in any other
|
||||
scenario can lead to security issues, so please know what you are doing.'
|
||||
default: True
|
||||
required: no
|
||||
workflow_callback:
|
||||
description:
|
||||
- 'Callback URL that represents an application, which invokes this module (e.g. up-level orchestrator or
|
||||
end-user portal) and may except out-of-band updates on progress / exit status of the module run.'
|
||||
- API call at this URL will be used to relay such information to the application.
|
||||
- 'API call payload will include module-specific details about this module run and I(workflow_context).'
|
||||
required: no
|
||||
workflow_context:
|
||||
description:
|
||||
- 'Context data that will be included into the payload of the API call directed at I(workflow_callback) URL.'
|
||||
- 'This context data is expected to uniquely identify the task carried out by this module invocation so
|
||||
that up-level orchestrator could match returned information to the its internal entities.'
|
||||
required: no
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- name: create a VM named "SimpleVM" in the DECORT cloud along with VDC named "ANewVDC" if it does not exist yet.
|
||||
decort_kvmvm:
|
||||
annotation: "VM managed by decort_kvmvm module"
|
||||
authenticator: oauth2
|
||||
app_id: "{{ MY_APP_ID }}"
|
||||
app_secret: "{{ MY_APP_SECRET }}"
|
||||
controller_url: "https://ds1.digitalenergy.online"
|
||||
name: SimpleVM
|
||||
cpu: 2
|
||||
ram: 4096
|
||||
boot_disk: 10
|
||||
image_name: "Ubuntu 16.04 v1.1"
|
||||
data_disks:
|
||||
- {{DISK_ID}}
|
||||
state: present
|
||||
tags:
|
||||
PROJECT:Ansible
|
||||
STATUS:Test
|
||||
account_name: "Development"
|
||||
rg_name: "ANewVDC"
|
||||
delegate_to: localhost
|
||||
register: simple_vm
|
||||
- name: resize the above VM to CPU 4 and remove port forward rule for port number 80.
|
||||
decort_kvmvm:
|
||||
authenticator: jwt
|
||||
jwt: "{{ MY_JWT }}"
|
||||
controller_url: "https://ds1.digitalenergy.online"
|
||||
name: SimpleVM
|
||||
cpu: 4
|
||||
ram: 4096
|
||||
port_forwards:
|
||||
- ext_port: 21022
|
||||
int_port: 22
|
||||
proto: tcp
|
||||
state: present
|
||||
account_name: "Development"
|
||||
rg_name: "ANewVDC"
|
||||
delegate_to: localhost
|
||||
register: simple_vm
|
||||
- name: stop existing VM identified by the VM ID and down size it to CPU:RAM 1:2048 along the way.
|
||||
decort_kvmvm:
|
||||
authenticator: jwt
|
||||
jwt: "{{ MY_JWT }}"
|
||||
controller_url: "https://ds1.digitalenergy.online"
|
||||
id: "{{ TARGET_VM_ID }}"
|
||||
cpu: 1
|
||||
ram: 2048
|
||||
state: poweredoff
|
||||
delegate_to: localhost
|
||||
register: simple_vm
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
facts:
|
||||
description: facts about the virtual machine that may be useful in the playbook
|
||||
returned: always
|
||||
type: dict
|
||||
sample:
|
||||
facts:
|
||||
id: 9454
|
||||
name: TestVM
|
||||
state: RUNNING
|
||||
username: testuser
|
||||
password: Yab!tWbyPF
|
||||
int_ip: 192.168.103.253
|
||||
rg_name: SandboxVDC
|
||||
rg_id: 2883
|
||||
vdc_ext_ip: 185.193.143.151
|
||||
ext_ip: 185.193.143.106
|
||||
ext_netmask: 24
|
||||
ext_gateway: 185.193.143.1
|
||||
ext_mac: 52:54:00:00:1a:24
|
||||
description: See L(Module Documentation,https://repository.basistech.ru/BASIS/decort-ansible/wiki/Home).
|
||||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.basic import env_fallback
|
||||
from ansible.module_utils.decort_utils import *
|
||||
|
||||
|
||||
class decort_kvmvm(DecortController):
|
||||
def __init__(self, arg_amodule):
|
||||
# call superclass constructor first
|
||||
@@ -420,6 +82,37 @@ class decort_kvmvm(DecortController):
|
||||
self.comp_should_exist = True
|
||||
self.acc_id = self.comp_info['accountId']
|
||||
|
||||
check_error = False
|
||||
params_to_check = {
|
||||
'chipset': 'chipset',
|
||||
'cpu_pin': 'cpupin',
|
||||
'hp_backed': 'hpBacked',
|
||||
'numa_affinity': 'numaAffinity',
|
||||
}
|
||||
for param_name, comp_field_name in params_to_check.items():
|
||||
if (
|
||||
self.aparams[param_name] is not None
|
||||
and self.comp_info[comp_field_name] != self.aparams[param_name]
|
||||
and self.aparams['state'] not in ('halted', 'poweredoff')
|
||||
):
|
||||
self.message(
|
||||
f'Cannot change "{param_name}" for compute '
|
||||
f'{self.comp_id} if parameter "state" is not '
|
||||
f'halted or poweredoff.'
|
||||
)
|
||||
check_error = True
|
||||
|
||||
if check_error:
|
||||
self.exit(fail=True)
|
||||
|
||||
else:
|
||||
if self.aparams['chipset'] is None:
|
||||
self.message(
|
||||
'Check for parameter "chipset" failed: '
|
||||
'chipset must be specified for a new compute.'
|
||||
)
|
||||
self.exit(fail=True)
|
||||
|
||||
return
|
||||
|
||||
def check_amodule_args(self):
|
||||
@@ -441,32 +134,15 @@ class decort_kvmvm(DecortController):
|
||||
)
|
||||
self.exit(fail=True)
|
||||
|
||||
# Check for unacceptable parameters for a blank Compute
|
||||
if (
|
||||
self.aparams['image_id'] is None
|
||||
and self.aparams['image_name'] is None
|
||||
):
|
||||
for parameter in (
|
||||
'ssh_key',
|
||||
'ssh_key_user',
|
||||
'ci_user_data',
|
||||
):
|
||||
if self.aparams[parameter] is not None:
|
||||
self.message(
|
||||
f'Check for parameter "{parameter}" failed: '
|
||||
f'"image_id" or "image_name" must be specified '
|
||||
f'to set {parameter}.'
|
||||
)
|
||||
self.exit(fail=True)
|
||||
|
||||
aparam_custom_fields = self.aparams['custom_fields']
|
||||
if aparam_custom_fields is not None:
|
||||
if (
|
||||
self.aparams['sep_id'] is not None
|
||||
and self.aparams['boot_disk'] is None
|
||||
aparam_custom_fields['disable']
|
||||
and aparam_custom_fields['fields'] is not None
|
||||
):
|
||||
self.message(
|
||||
'Check for parameter "sep_id" failed: '
|
||||
'"image_id" or "image_name" or "boot_disk" '
|
||||
'must be specified to set sep_id.'
|
||||
'Check for parameter "custom_fields" failed: '
|
||||
'"fields" cannot be set if "disable" is True.'
|
||||
)
|
||||
self.exit(fail=True)
|
||||
|
||||
@@ -579,13 +255,27 @@ class decort_kvmvm(DecortController):
|
||||
cloud_init_params = self.amodule.params['ci_user_data']
|
||||
else:
|
||||
cloud_init_params = None
|
||||
# if we get through here, all parameters required to create new Compute instance should be at hand
|
||||
|
||||
match self.amodule.params['chipset'].lower():
|
||||
case 'q35':
|
||||
chipset = 'Q35'
|
||||
case 'i440fx':
|
||||
chipset = 'i440fx'
|
||||
cpu_pin = self.aparams['cpu_pin']
|
||||
if cpu_pin is None:
|
||||
cpu_pin = False
|
||||
|
||||
hp_backed = self.aparams['hp_backed']
|
||||
if hp_backed is None:
|
||||
hp_backed = False
|
||||
|
||||
numa_affinity = self.aparams['numa_affinity']
|
||||
if numa_affinity is None:
|
||||
numa_affinity = 'none'
|
||||
|
||||
if self.aparams['custom_fields'] is None:
|
||||
custom_fields_disable = True
|
||||
custom_fields_fields = None
|
||||
else:
|
||||
custom_fields_disable = self.aparams['custom_fields']['disable']
|
||||
custom_fields_fields = self.aparams['custom_fields']['fields']
|
||||
|
||||
# if we get through here, all parameters required to create new Compute instance should be at hand
|
||||
|
||||
# NOTE: KVM VM is created in HALTED state and must be explicitly started
|
||||
self.comp_id = self.kvmvm_provision(rg_id=self.rg_id,
|
||||
@@ -593,12 +283,16 @@ class decort_kvmvm(DecortController):
|
||||
cpu=self.amodule.params['cpu'], ram=self.amodule.params['ram'],
|
||||
boot_disk=validated_bdisk_size,
|
||||
image_id=image_id,
|
||||
annotation=self.amodule.params['annotation'],
|
||||
description=self.amodule.params['description'],
|
||||
userdata=cloud_init_params,
|
||||
sep_id=self.amodule.params['sep_id' ] if "sep_id" in self.amodule.params else None,
|
||||
pool_name=self.amodule.params['pool'] if "pool" in self.amodule.params else None,
|
||||
start_on_create=start_compute,
|
||||
chipset=chipset)
|
||||
chipset=self.amodule.params['chipset'],
|
||||
cpu_pin=cpu_pin,
|
||||
hp_backed=hp_backed,
|
||||
numa_affinity=numa_affinity,
|
||||
custom_fields=custom_fields_fields)
|
||||
self.comp_should_exist = True
|
||||
|
||||
# Originally we would have had to re-read comp_info after VM was provisioned
|
||||
@@ -713,15 +407,44 @@ class decort_kvmvm(DecortController):
|
||||
**self.compute_update_args,
|
||||
)
|
||||
|
||||
aparam_custom_fields = self.amodule.params['custom_fields']
|
||||
if aparam_custom_fields is not None:
|
||||
compute_custom_fields = self.compute_get_custom_fields(
|
||||
compute_id=self.comp_info['id'],
|
||||
)
|
||||
if aparam_custom_fields['disable']:
|
||||
if compute_custom_fields is not None:
|
||||
self.compute_disable_custom_fields(
|
||||
compute_id=self.comp_info['id'],
|
||||
)
|
||||
else:
|
||||
if compute_custom_fields != aparam_custom_fields['fields']:
|
||||
self.compute_set_custom_fields(
|
||||
compute_id=self.comp_info['id'],
|
||||
custom_fields=aparam_custom_fields['fields'],
|
||||
)
|
||||
|
||||
return
|
||||
|
||||
@property
|
||||
def compute_update_args(self) -> dict:
|
||||
result_args = {}
|
||||
|
||||
aparam_name = self.amodule.params['name']
|
||||
if aparam_name is not None and aparam_name != self.comp_info['name']:
|
||||
result_args['name'] = aparam_name
|
||||
params_to_check = {
|
||||
'name': 'name',
|
||||
'chipset': 'chipset',
|
||||
'cpu_pin': 'cpupin',
|
||||
'hp_backed': 'hpBacked',
|
||||
'numa_affinity': 'numaAffinity',
|
||||
'description': 'desc',
|
||||
}
|
||||
for param_name, comp_field_name in params_to_check.items():
|
||||
aparam_value = self.amodule.params[param_name]
|
||||
if (
|
||||
aparam_value is not None
|
||||
and aparam_value != self.comp_info[comp_field_name]
|
||||
):
|
||||
result_args[param_name] = aparam_value
|
||||
|
||||
return result_args
|
||||
|
||||
@@ -756,6 +479,10 @@ class decort_kvmvm(DecortController):
|
||||
tags={},
|
||||
chipset="",
|
||||
interfaces=[],
|
||||
cpu_pin="",
|
||||
hp_backed="",
|
||||
numa_affinity="",
|
||||
custom_fields={},
|
||||
)
|
||||
|
||||
if check_mode or self.comp_info is None:
|
||||
@@ -812,8 +539,46 @@ class decort_kvmvm(DecortController):
|
||||
|
||||
ret_dict['interfaces'] = self.comp_info['interfaces']
|
||||
|
||||
ret_dict['cpu_pin'] = self.comp_info['cpupin']
|
||||
ret_dict['hp_backed'] = self.comp_info['hpBacked']
|
||||
ret_dict['numa_affinity'] = self.comp_info['numaAffinity']
|
||||
|
||||
ret_dict['custom_fields'] = self.compute_get_custom_fields(
|
||||
compute_id=self.comp_info['id'],
|
||||
)
|
||||
|
||||
return ret_dict
|
||||
|
||||
def check_amodule_args_for_create(self):
|
||||
# Check for unacceptable parameters for a blank Compute
|
||||
if (
|
||||
self.aparams['image_id'] is None
|
||||
and self.aparams['image_name'] is None
|
||||
):
|
||||
for parameter in (
|
||||
'ssh_key',
|
||||
'ssh_key_user',
|
||||
'ci_user_data',
|
||||
):
|
||||
if self.aparams[parameter] is not None:
|
||||
self.message(
|
||||
f'Check for parameter "{parameter}" failed: '
|
||||
f'"image_id" or "image_name" must be specified '
|
||||
f'to set {parameter}.'
|
||||
)
|
||||
self.exit(fail=True)
|
||||
|
||||
if (
|
||||
self.aparams['sep_id'] is not None
|
||||
and self.aparams['boot_disk'] is None
|
||||
):
|
||||
self.message(
|
||||
'Check for parameter "sep_id" failed: '
|
||||
'"image_id" or "image_name" or "boot_disk" '
|
||||
'must be specified to set sep_id.'
|
||||
)
|
||||
self.exit(fail=True)
|
||||
|
||||
@staticmethod
|
||||
def build_parameters():
|
||||
"""Build and return a dictionary of parameters expected by decort_kvmvm module in a form
|
||||
@@ -825,9 +590,7 @@ class decort_kvmvm(DecortController):
|
||||
return dict(
|
||||
account_id=dict(type='int', required=False, default=0),
|
||||
account_name=dict(type='str', required=False, default=''),
|
||||
annotation=dict(type='str',
|
||||
default='',
|
||||
required=False),
|
||||
description=dict(type='str', required=False),
|
||||
app_id=dict(type='str',
|
||||
required=False,
|
||||
fallback=(env_fallback, ['DECORT_APP_ID'])),
|
||||
@@ -917,10 +680,52 @@ class decort_kvmvm(DecortController):
|
||||
workflow_context=dict(type='str', required=False),
|
||||
chipset=dict(
|
||||
type='str',
|
||||
default='i440fx',
|
||||
choices=['Q35', 'q35', 'I440FX', 'i440fx']
|
||||
choices=['Q35', 'i440fx']
|
||||
),
|
||||
cpu_pin=dict(
|
||||
type='bool',
|
||||
),
|
||||
hp_backed=dict(
|
||||
type='bool',
|
||||
),
|
||||
numa_affinity=dict(
|
||||
type='str',
|
||||
choices=['strict', 'loose', 'none'],
|
||||
),
|
||||
custom_fields=dict(
|
||||
type='dict',
|
||||
options=dict(
|
||||
fields=dict(
|
||||
type='dict',
|
||||
),
|
||||
disable=dict(
|
||||
type='bool',
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
def check_amodule_args_for_change(self):
|
||||
new_boot_disk_size = self.amodule.params['boot_disk']
|
||||
if new_boot_disk_size is not None:
|
||||
for disk in self.comp_info['disks']:
|
||||
if disk['type'] == 'B':
|
||||
boot_disk_size = disk['sizeMax']
|
||||
break
|
||||
else:
|
||||
self.message(
|
||||
f'Can\'t set boot disk size for Compute '
|
||||
f'{self.comp_info["id"]}, because it doesn\'t have a '
|
||||
f'boot disk.'
|
||||
)
|
||||
self.exit(fail=True)
|
||||
if new_boot_disk_size < boot_disk_size:
|
||||
self.message(
|
||||
f'New boot disk size {new_boot_disk_size} is less than '
|
||||
f'current {boot_disk_size} for Compute ID '
|
||||
f'{self.comp_info["id"]}'
|
||||
)
|
||||
self.exit(fail=True)
|
||||
|
||||
# Workflow digest:
|
||||
# 1) authenticate to DECORT controller & validate authentication by issuing API call - done when creating DECSController
|
||||
@@ -980,6 +785,8 @@ def main():
|
||||
pass
|
||||
|
||||
if subj.comp_id:
|
||||
subj.check_amodule_args_for_change()
|
||||
|
||||
if subj.comp_info['status'] in ("DISABLED", "MIGRATING", "DELETING", "DESTROYING", "ERROR", "REDEPLOYING"):
|
||||
# cannot do anything on the existing Compute in the listed states
|
||||
subj.error() # was subj.nop()
|
||||
@@ -1011,6 +818,8 @@ def main():
|
||||
elif amodule.params['state'] == 'paused':
|
||||
subj.error()
|
||||
else:
|
||||
subj.check_amodule_args_for_create()
|
||||
|
||||
# Preexisting Compute of specified identity was not found.
|
||||
# If requested state is 'absent' - nothing to do
|
||||
if amodule.params['state'] == 'absent':
|
||||
|
||||
@@ -1,28 +1,17 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Digital Enegry Cloud Orchestration Technology (DECORT) modules for Ansible
|
||||
# Copyright: (c) 2018-2023 Digital Energy Cloud Solutions LLC
|
||||
#
|
||||
# Apache License 2.0 (see http://www.apache.org/licenses/LICENSE-2.0.txt)
|
||||
#
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'}
|
||||
DOCUMENTATION = r'''
|
||||
---
|
||||
module: decort_lb
|
||||
|
||||
DOCUMENTATION = '''
|
||||
TODO
|
||||
description: See L(Module Documentation,https://repository.basistech.ru/BASIS/decort-ansible/wiki/Home).
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
TODO
|
||||
'''
|
||||
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.basic import env_fallback
|
||||
from ansible.module_utils.decort_utils import *
|
||||
|
||||
|
||||
class decort_lb(DecortController):
|
||||
def __init__(self,arg_amodule) -> None:
|
||||
super(decort_lb,self).__init__(arg_amodule)
|
||||
@@ -113,7 +102,7 @@ class decort_lb(DecortController):
|
||||
self.rg_id,self.vins_id,
|
||||
self.amodule.params['ext_net_id'],
|
||||
self.amodule.params['ha_lb'],
|
||||
self.amodule.params['annotation'])
|
||||
self.amodule.params['description'])
|
||||
if self.lb_id and (self.amodule.params['backends'] or
|
||||
self.amodule.params['frontends']):
|
||||
self.lb_id, self.lb_facts = self.lb_find(0,self.amodule.params['lb_name'],self.rg_id)
|
||||
@@ -235,7 +224,7 @@ class decort_lb(DecortController):
|
||||
return dict(
|
||||
account_id=dict(type='int', required=False),
|
||||
account_name=dict(type='str', required=False, default=''),
|
||||
annotation=dict(type='str', required=False, default='Managed by Ansible module decort_lb'),
|
||||
description=dict(type='str', required=False, default='Managed by Ansible module decort_lb'),
|
||||
app_id=dict(type='str',
|
||||
required=False,
|
||||
fallback=(env_fallback, ['DECORT_APP_ID'])),
|
||||
|
||||
@@ -1,285 +1,10 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Digital Enegry Cloud Orchestration Technology (DECORT) modules for Ansible
|
||||
# Copyright: (c) 2018-2021 Digital Energy Cloud Solutions LLC
|
||||
#
|
||||
# Apache License 2.0 (see http://www.apache.org/licenses/LICENSE-2.0.txt)
|
||||
#
|
||||
|
||||
#
|
||||
# Author: Sergey Shubin (sergey.shubin@digitalenergy.online)
|
||||
#
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'}
|
||||
|
||||
DOCUMENTATION = '''
|
||||
DOCUMENTATION = r'''
|
||||
---
|
||||
module: decort_osimage
|
||||
short_description: Locate OS image in DCORT cloud by its name and return image ID
|
||||
description: >
|
||||
This module can be used to obtain image ID of an OS image in DECORT cloud to use with subsequent calls to
|
||||
decort_vm module for batch VM provisioning. It will speed up VM creation and save a bunch of extra calls to
|
||||
DECORT cloud controller on each VM creation act.
|
||||
|
||||
version_added: "2.2"
|
||||
author:
|
||||
- Sergey Shubin <sergey.shubin@digitalenergy.online>
|
||||
requirements:
|
||||
- python >= 2.6
|
||||
- PyJWT Python module
|
||||
- requests Python module
|
||||
- netaddr Python module
|
||||
- decort_utils utility library (module)
|
||||
- DECORT cloud platform version 3.6.1 or higher.
|
||||
notes:
|
||||
- Environment variables can be used to pass selected parameters to the module, see details below.
|
||||
- Specified Oauth2 provider must be trusted by the DECORT cloud controller on which JWT will be used.
|
||||
- 'Similarly, JWT supplied in I(authenticator=jwt) mode should be received from Oauth2 provider trusted by
|
||||
the DECORT cloud controller on which this JWT will be used.'
|
||||
options:
|
||||
app_id:
|
||||
description:
|
||||
- 'Application ID for authenticating to the DECORT controller when I(authenticator=oauth2).'
|
||||
- 'Required if I(authenticator=oauth2).'
|
||||
- 'If not found in the playbook or command line arguments, the value will be taken from DECORT_APP_ID
|
||||
environment variable.'
|
||||
required: no
|
||||
app_secret:
|
||||
description:
|
||||
- 'Application API secret used for authenticating to the DECORT controller when I(authenticator=oauth2).'
|
||||
- This parameter is required when I(authenticator=oauth2) and ignored in other modes.
|
||||
- 'If not found in the playbook or command line arguments, the value will be taken from DECORT_APP_SECRET
|
||||
environment variable.'
|
||||
required: no
|
||||
authenticator:
|
||||
description:
|
||||
- Authentication mechanism to be used when accessing DECORT controller and authorizing API call.
|
||||
default: jwt
|
||||
choices: [ jwt, oauth2, legacy ]
|
||||
required: yes
|
||||
controller_url:
|
||||
description:
|
||||
- URL of the DECORT controller that will be contacted to obtain OS image details.
|
||||
- 'This parameter is always required regardless of the specified I(authenticator) type.'
|
||||
required: yes
|
||||
image_name:
|
||||
description:
|
||||
- Name of the OS image to use. Module will return the ID of this image.
|
||||
- 'The specified image name will be looked up in the target DECORT controller and error will be generated
|
||||
- if no matching image is found.'
|
||||
required: yes
|
||||
jwt:
|
||||
description:
|
||||
- 'JWT (access token) for authenticating to the DECORT controller when I(authenticator=jwt).'
|
||||
- 'This parameter is required if I(authenticator=jwt) and ignored for other authentication modes.'
|
||||
- If not specified in the playbook, the value will be taken from DECORT_JWT environment variable.
|
||||
required: no
|
||||
oauth2_url:
|
||||
description:
|
||||
- 'URL of the oauth2 authentication provider to use when I(authenticator=oauth2).'
|
||||
- 'This parameter is required when when I(authenticator=oauth2).'
|
||||
- If not specified in the playbook, the value will be taken from DECORT_OAUTH2_URL environment variable.
|
||||
password:
|
||||
description:
|
||||
- 'Password for authenticating to the DECORT controller when I(authenticator=legacy).'
|
||||
- 'This parameter is required if I(authenticator=legacy) and ignored in other authentication modes.'
|
||||
- If not specified in the playbook, the value will be taken from DECORT_PASSWORD environment variable.
|
||||
required: no
|
||||
pool:
|
||||
description:
|
||||
- 'Name of the storage pool, where the image should be found.'
|
||||
- 'Omit this option if no matching by pool name is required. The first matching image will be returned."
|
||||
required: no
|
||||
sep_id:
|
||||
description:
|
||||
- 'ID of the SEP (Storage End-point Provider), where the image should be found.'
|
||||
- 'Omit this option if no matching by SEP ID is required. The first matching image will be returned."
|
||||
required: no
|
||||
account_name:
|
||||
description:
|
||||
- 'Name of the account for which the specified OS image will be looked up.'
|
||||
- 'This parameter is required for listing OS images.'
|
||||
required: yes
|
||||
user:
|
||||
description:
|
||||
- 'Name of the legacy user for authenticating to the DECORT controller when I(authenticator=legacy).'
|
||||
- 'This parameter is required when I(authenticator=legacy) and ignored for other authentication modes.'
|
||||
- If not specified in the playbook, the value will be taken from DECORT_USER environment variable.
|
||||
required: no
|
||||
verify_ssl:
|
||||
description:
|
||||
- 'Controls SSL verification mode when making API calls to DECORT controller. Set it to False if you
|
||||
want to disable SSL certificate verification. Intended use case is when you run module in a trusted
|
||||
environment that uses self-signed certificates. Note that disabling SSL verification in any other
|
||||
scenario can lead to security issues, so please know what you are doing.'
|
||||
default: True
|
||||
required: no
|
||||
workflow_callback:
|
||||
description:
|
||||
- 'Callback URL that represents an application, which invokes this module (e.g. up-level orchestrator or
|
||||
end-user portal) and may except out-of-band updates on progress / exit status of the module run.'
|
||||
- API call at this URL will be used to relay such information to the application.
|
||||
- 'API call payload will include module-specific details about this module run and I(workflow_context).'
|
||||
required: no
|
||||
workflow_context:
|
||||
description:
|
||||
- 'Context data that will be included into the payload of the API call directed at I(workflow_callback) URL.'
|
||||
- 'This context data is expected to uniquely identify the task carried out by this module invocation so
|
||||
that up-level orchestrator could match returned information to the its internal entities.'
|
||||
required: no
|
||||
account_name:
|
||||
description:
|
||||
- 'Account name. Used to get a unique integer account ID.'
|
||||
required: no
|
||||
virt_id:
|
||||
description:
|
||||
- 'A unique integer identifier for the virtual image.'
|
||||
- 'Can be used to obtain information about a virtual image, as well as to create a virtual image and
|
||||
- bind another operating system image to it.'
|
||||
required: no
|
||||
virt_name:
|
||||
description:
|
||||
- 'Name of the virtual image. Used to get the `virt_id`, and later information about the virtual image,
|
||||
- as well as to create a virtual image and bind another operating system image to it.'
|
||||
required: no
|
||||
state:
|
||||
description:
|
||||
- 'The state of the images. If set to present, operating system images will be created to which
|
||||
- the account specified in `account_Id` or `account_name` is bound. If set to absent, they will be removed.
|
||||
required: no
|
||||
drivers:
|
||||
description:
|
||||
- 'A list of compute types (eg virtual servers) that are appropriate for the operating system image.
|
||||
- Note: `KVM_X86`. Used when creating an operating system image.'
|
||||
required: no
|
||||
architecture:
|
||||
description:
|
||||
- 'Binary architecture of the image. Note. `X86_64`. Used when creating
|
||||
-an operating system image.'
|
||||
required: no
|
||||
imagetype:
|
||||
description:
|
||||
- 'Image type. `linux`, `windows` or `other`. The default is `linux`. Used when creating
|
||||
- an operating system image.'
|
||||
required: no
|
||||
boottype:
|
||||
description:
|
||||
- 'Image upload type. `bios` or `uefi`. The default is `uefi`. Used when creating an operating
|
||||
-system image.'
|
||||
required: no
|
||||
url:
|
||||
description:
|
||||
- 'Uniform resource locator (URL) pointing to the iso image of the operating system. Used when
|
||||
-creating an operating system image.'
|
||||
required: no
|
||||
sepId:
|
||||
description:
|
||||
- 'The unique integer ID of the storage provider endpoint. Specified in pair with `poolName`.
|
||||
- Used when creating an operating system image.'
|
||||
required: no
|
||||
poolName:
|
||||
description:
|
||||
- 'The pool in which the image will be created. Specified in pair with `sepId`. Used when creating
|
||||
- an operating system image.'
|
||||
required: no
|
||||
hotresize:
|
||||
description:
|
||||
- 'Whether the image supports "hot" resizing. The default is `false`. Used when creating an operating
|
||||
- system image.'
|
||||
required: no
|
||||
image_username:
|
||||
description:
|
||||
- 'An optional username for the image. Used when creating an operating system image.'
|
||||
required: no
|
||||
image_password:
|
||||
description:
|
||||
- 'An optional password for the image. Used when creating an operating system image. Used when creating
|
||||
- an operating system image.'
|
||||
required: no
|
||||
usernameDL:
|
||||
description:
|
||||
- 'The username for loading the binary media. Used in conjunction with `passwordDL`. Used when creating
|
||||
- an operating system image'
|
||||
required: no
|
||||
passwordDL:
|
||||
description:
|
||||
- 'The password for loading the binary media. Used in conjunction with `usernameDL`. Used when creating
|
||||
- an operating system image.'
|
||||
required: no
|
||||
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- name: create_osimage
|
||||
decort_osimage:
|
||||
authenticator: oauth2
|
||||
verify_ssl: False
|
||||
controller_url: "https://ds1.digitalenergy.online"
|
||||
state: present
|
||||
image_name: "alpine_linux3.14.0"
|
||||
account_Id: 12345
|
||||
url: "https://dl-cdn.alpinelinux.org/alpine/v3.14/releases/x86_64/alpine-virt-3.14.0-x86_64.iso"
|
||||
boottype: "uefi"
|
||||
imagetype: "linux"
|
||||
hotresize: False
|
||||
image_username: "test"
|
||||
image_password: "p@ssw0rd"
|
||||
usernameDL: "testDL"
|
||||
passwordDL: "p@ssw0rdDL"
|
||||
architecture: "X86_64"
|
||||
drivers: "KVM_X86"
|
||||
delegate_to: localhost
|
||||
register: osimage
|
||||
|
||||
- name: get_osimage
|
||||
decort_osimage:
|
||||
authenticator: oauth2
|
||||
controller_url: "https://ds1.digitalenergy.online"
|
||||
image_name: "alpine_linux_3.14.0"
|
||||
account_Id: 12345
|
||||
delegate_to: localhost
|
||||
register: osimage
|
||||
|
||||
- name: create_virtual_osimage
|
||||
decort_osimage:
|
||||
authenticator: oauth2
|
||||
controller_url: "https://ds1.digitalenergy.online"
|
||||
image_name: "alpine_linux_3.14.0"
|
||||
virt_name: "alpine_last"
|
||||
delegate_to: localhost
|
||||
register: osimage
|
||||
|
||||
- name: rename_osimage
|
||||
decort_osimage:
|
||||
authenticator: oauth2
|
||||
controller_url: "https://ds1.digitalenergy.online"
|
||||
image_name: "alpine_linux_3.14.0v2.0"
|
||||
image_id: 54321
|
||||
delegate_to: localhost
|
||||
register: osimage
|
||||
|
||||
|
||||
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
facts:
|
||||
description: facts about the specified OS image
|
||||
returned: always
|
||||
type: dict
|
||||
sample:
|
||||
facts:
|
||||
id: 100
|
||||
linkto: 80
|
||||
name: "Ubuntu 16.04 v1.0"
|
||||
size: 3
|
||||
sep_id: 1
|
||||
pool: "vmstore"
|
||||
type: Linux
|
||||
arch: x86_64
|
||||
state: CREATED
|
||||
description: See L(Module Documentation,https://repository.basistech.ru/BASIS/decort-ansible/wiki/Home).
|
||||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
@@ -287,6 +12,7 @@ from ansible.module_utils.basic import env_fallback
|
||||
|
||||
from ansible.module_utils.decort_utils import *
|
||||
|
||||
|
||||
class decort_osimage(DecortController):
|
||||
def __init__(self,amodule):
|
||||
super(decort_osimage, self).__init__(amodule)
|
||||
|
||||
@@ -1,180 +1,10 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Digital Enegry Cloud Orchestration Technology (DECORT) modules for Ansible
|
||||
# Copyright: (c) 2018-2021 Digital Energy Cloud Solutions LLC
|
||||
#
|
||||
# Apache License 2.0 (see http://www.apache.org/licenses/LICENSE-2.0.txt)
|
||||
#
|
||||
|
||||
#
|
||||
# Author: Sergey Shubin (sergey.shubin@digitalenergy.online)
|
||||
#
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'}
|
||||
|
||||
DOCUMENTATION = '''
|
||||
DOCUMENTATION = r'''
|
||||
---
|
||||
module: decort_pfw
|
||||
short_description: Manage network Port Forward rules for Compute instances in DECORT cloud
|
||||
description: >
|
||||
This module can be used to create new port forwarding rules in DECORT cloud platform,
|
||||
modify and delete them.
|
||||
version_added: "2.2"
|
||||
author:
|
||||
- Sergey Shubin <sergey.shubin@digitalenergy.online>
|
||||
requirements:
|
||||
- python >= 2.6
|
||||
- PyJWT Python module
|
||||
- requests Python module
|
||||
- netaddr Python module
|
||||
- decort_utils utility library (module)
|
||||
- DECORT cloud platform version 3.6.1 or higher
|
||||
notes:
|
||||
- Environment variables can be used to pass selected parameters to the module, see details below.
|
||||
- Specified Oauth2 provider must be trusted by the DECORT cloud controller on which JWT will be used.
|
||||
- 'Similarly, JWT supplied in I(authenticator=jwt) mode should be received from Oauth2 provider trusted by
|
||||
the DECORT cloud controller on which this JWT will be used.'
|
||||
options:
|
||||
account_id:
|
||||
description:
|
||||
- ID of the account, which owns this disk. This is the alternative to I(account_name) option.
|
||||
- If both I(account_id) and I(account_name) specified, then I(account_name) is ignored.
|
||||
default: 0
|
||||
required: no
|
||||
account_name:
|
||||
description:
|
||||
- 'Name of the account, which will own this disk.'
|
||||
- 'This parameter is ignored if I(account_id) is specified.'
|
||||
default: empty string
|
||||
required: no
|
||||
app_id:
|
||||
description:
|
||||
- 'Application ID for authenticating to the DECORT controller when I(authenticator=oauth2).'
|
||||
- 'Required if I(authenticator=oauth2).'
|
||||
- 'If not found in the playbook or command line arguments, the value will be taken from DECORT_APP_ID
|
||||
environment variable.'
|
||||
required: no
|
||||
app_secret:
|
||||
description:
|
||||
- 'Application API secret used for authenticating to the DECORT controller when I(authenticator=oauth2).'
|
||||
- This parameter is required when I(authenticator=oauth2) and ignored in other modes.
|
||||
- 'If not found in the playbook or command line arguments, the value will be taken from DECORT_APP_SECRET
|
||||
environment variable.'
|
||||
required: no
|
||||
authenticator:
|
||||
description:
|
||||
- Authentication mechanism to be used when accessing DECORT controller and authorizing API call.
|
||||
default: jwt
|
||||
choices: [ jwt, oauth2, legacy ]
|
||||
required: yes
|
||||
controller_url:
|
||||
description:
|
||||
- URL of the DECORT controller that will be contacted to manage the RG according to the specification.
|
||||
- 'This parameter is always required regardless of the specified I(authenticator) type.'
|
||||
required: yes
|
||||
compute_id:
|
||||
description:
|
||||
- ID of the Compute instance to manage network port forwarding rules for.
|
||||
required: yes
|
||||
jwt:
|
||||
description:
|
||||
- 'JWT (access token) for authenticating to the DECORT controller when I(authenticator=jwt).'
|
||||
- 'This parameter is required if I(authenticator=jwt) and ignored for other authentication modes.'
|
||||
- If not specified in the playbook, the value will be taken from DECORT_JWT environment variable.
|
||||
required: no
|
||||
oauth2_url:
|
||||
description:
|
||||
- 'URL of the oauth2 authentication provider to use when I(authenticator=oauth2).'
|
||||
- 'This parameter is required when when I(authenticator=oauth2).'
|
||||
- 'If not specified in the playbook, the value will be taken from DECORT_OAUTH2_URL environment variable.'
|
||||
password:
|
||||
description:
|
||||
- 'Password for authenticating to the DECORT controller when I(authenticator=legacy).'
|
||||
- 'This parameter is required if I(authenticator=legacy) and ignored in other authentication modes.'
|
||||
- If not specified in the playbook, the value will be taken from DECORT_PASSWORD environment variable.
|
||||
required: no
|
||||
rules:
|
||||
description:
|
||||
- 'Set of rules to configure for the Compute instance identidied by I(compute_id) in the virtual
|
||||
network segment identidied by I(vins_id).'
|
||||
- The set is specified as a list of dictionaries with the following structure:
|
||||
- ' - (int) public_port_start - starting port number on the ViNS external interface.'
|
||||
- ' - (int) public_port_end - optional end port number of the ViNS external interface. If not specified
|
||||
or set equal to I(public_port_start), a one-to-one rule is created. Otherwise a ranged rule will
|
||||
be created, which maps specified external port range to local ports starting from I(local_port).'
|
||||
- ' - (int) local_port - port number on the local interface of the Compute. For ranged rule it is
|
||||
interpreted as a base port to translate public port range to internal port range.'
|
||||
- ' - (string) proto - protocol, specify either I(tcp) or I(udp).'
|
||||
- 'Note that rules are meaningful only if I(state=present). If I(state=absent) is specified, rules set
|
||||
will be ignored, and all rules for the specified Compute will be deleted.'
|
||||
state:
|
||||
description:
|
||||
- 'Specify the desired state of the port forwarding rules set for the Compute instance identified by
|
||||
I(compute_id).'
|
||||
- 'If I(state=present), the rules will be applied according to the I(rules) parameter.'
|
||||
- 'If I(state=absent), all rules for the specified Compute instance will be deleted regardless of
|
||||
I(rules) parameter.'
|
||||
default: present
|
||||
choices: [ absent, present ]
|
||||
verify_ssl:
|
||||
description:
|
||||
- 'Controls SSL verification mode when making API calls to DECORT controller. Set it to False if you
|
||||
want to disable SSL certificate verification. Intended use case is when you run module in a trusted
|
||||
environment that uses self-signed certificates. Note that disabling SSL verification in any other
|
||||
scenario can lead to security issues, so please know what you are doing.'
|
||||
default: True
|
||||
required: no
|
||||
vins_id:
|
||||
description:
|
||||
- ID of the virtual network segment (ViNS), where port forwarding rules will be set up.
|
||||
- This ViNS must have connection to external network.
|
||||
- Compute instance specified by I(compute_id) must be connected to this ViNS.
|
||||
workflow_callback:
|
||||
description:
|
||||
- 'Callback URL that represents an application, which invokes this module (e.g. up-level orchestrator or
|
||||
end-user portal) and may except out-of-band updates on progress / exit status of the module run.'
|
||||
- API call at this URL will be used to relay such information to the application.
|
||||
- 'API call payload will include module-specific details about this module run and I(workflow_context).'
|
||||
required: no
|
||||
workflow_context:
|
||||
description:
|
||||
- 'Context data that will be included into the payload of the API call directed at I(workflow_callback) URL.'
|
||||
- 'This context data is expected to uniquely identify the task carried out by this module invocation so
|
||||
that up-level orchestrator could match returned information to the its internal entities.'
|
||||
required: no
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- name: configure one-toone rule for SSH protocol on Compute ID 100 connected to ViNS ID 5.
|
||||
decort_pfw:
|
||||
authenticator: oauth2
|
||||
app_id: "{{ MY_APP_ID }}"
|
||||
app_secret: "{{ MY_APP_SECRET }}"
|
||||
controller_url: "https://cloud.digitalenergy.online"
|
||||
compute_id: 100
|
||||
vins_id: 5
|
||||
rules:
|
||||
- public_port_start: 10022
|
||||
local_port: 22
|
||||
proto: tcp
|
||||
state: present
|
||||
delegate_to: localhost
|
||||
register: my_pfw
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
facts:
|
||||
description: facts about created PFW rules
|
||||
returned: always
|
||||
type: dict
|
||||
sample:
|
||||
facts:
|
||||
compute_id: 100
|
||||
vins_id: 5
|
||||
rules:
|
||||
-
|
||||
description: See L(Module Documentation,https://repository.basistech.ru/BASIS/decort-ansible/wiki/Home).
|
||||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
@@ -1,207 +1,10 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Digital Enegry Cloud Orchestration Technology (DECORT) modules for Ansible
|
||||
# Copyright: (c) 2018-2021 Digital Energy Cloud Solutions LLC
|
||||
#
|
||||
# Apache License 2.0 (see http://www.apache.org/licenses/LICENSE-2.0.txt)
|
||||
#
|
||||
|
||||
#
|
||||
# Author: Sergey Shubin (sergey.shubin@digitalenergy.online)
|
||||
#
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'}
|
||||
|
||||
DOCUMENTATION = '''
|
||||
DOCUMENTATION = r'''
|
||||
---
|
||||
module: decort_rg
|
||||
short_description: Manage resource groups (RGs) in DECORT cloud
|
||||
description: >
|
||||
This module can be used to create a new resource group in DECORT cloud platform, modify its
|
||||
characteristics, and delete it.
|
||||
version_added: "2.2"
|
||||
author:
|
||||
- Sergey Shubin <sergey.shubin@digitalenergy.online>
|
||||
requirements:
|
||||
- python >= 2.6
|
||||
- PyJWT Python module
|
||||
- requests Python module
|
||||
- netaddr Python module
|
||||
- decort_utils utility library (module)
|
||||
- DECORT cloud platform version 3.6.1 or higher
|
||||
notes:
|
||||
- Environment variables can be used to pass selected parameters to the module, see details below.
|
||||
- Specified Oauth2 provider must be trusted by the DECORT cloud controller on which JWT will be used.
|
||||
- 'Similarly, JWT supplied in I(authenticator=jwt) mode should be received from Oauth2 provider trusted by
|
||||
the DECORT cloud controller on which this JWT will be used.'
|
||||
- New RGs provisioned with this module will be deployed to the first location under specified DECORT
|
||||
controller (if there is more than one location).
|
||||
options:
|
||||
account_id:
|
||||
description:
|
||||
- ID of the account under which this RG will be created. This is the alternative to I(account_name)
|
||||
option. If both I(account_id) and I(account_name) specified, the latter is ignored.
|
||||
account_name:
|
||||
description:
|
||||
- 'Name of the account under which this RG will be created (for new RGs) or is located.'
|
||||
- 'This parameter is ignored if I(account_id) is specified.'
|
||||
required: no
|
||||
annotation:
|
||||
description:
|
||||
- Optional text description of this resource group.
|
||||
default: empty string
|
||||
required: no
|
||||
app_id:
|
||||
description:
|
||||
- 'Application ID for authenticating to the DECORT controller when I(authenticator=oauth2).'
|
||||
- 'Required if I(authenticator=oauth2).'
|
||||
- 'If not found in the playbook or command line arguments, the value will be taken from DECORT_APP_ID
|
||||
environment variable.'
|
||||
required: no
|
||||
app_secret:
|
||||
description:
|
||||
- 'Application API secret used for authenticating to the DECORT controller when I(authenticator=oauth2).'
|
||||
- This parameter is required when I(authenticator=oauth2) and ignored in other modes.
|
||||
- 'If not found in the playbook or command line arguments, the value will be taken from DECORT_APP_SECRET
|
||||
environment variable.'
|
||||
required: no
|
||||
authenticator:
|
||||
description:
|
||||
- Authentication mechanism to be used when accessing DECORT controller and authorizing API call.
|
||||
default: jwt
|
||||
choices: [ jwt, oauth2, legacy ]
|
||||
required: yes
|
||||
controller_url:
|
||||
description:
|
||||
- URL of the DECORT controller that will be contacted to manage the RG according to the specification.
|
||||
- 'This parameter is always required regardless of the specified I(authenticator) type.'
|
||||
required: yes
|
||||
jwt:
|
||||
description:
|
||||
- 'JWT (access token) for authenticating to the DECORT controller when I(authenticator=jwt).'
|
||||
- 'This parameter is required if I(authenticator=jwt) and ignored for other authentication modes.'
|
||||
- If not specified in the playbook, the value will be taken from DECORT_JWT environment variable.
|
||||
required: no
|
||||
oauth2_url:
|
||||
description:
|
||||
- 'URL of the oauth2 authentication provider to use when I(authenticator=oauth2).'
|
||||
- 'This parameter is required when when I(authenticator=oauth2).'
|
||||
- If not specified in the playbook, the value will be taken from DECORT_OAUTH2_URL environment variable.
|
||||
password:
|
||||
description:
|
||||
- 'Password for authenticating to the DECORT controller when I(authenticator=legacy).'
|
||||
- 'This parameter is required if I(authenticator=legacy) and ignored in other authentication modes.'
|
||||
- If not specified in the playbook, the value will be taken from DECORT_PASSWORD environment variable.
|
||||
required: no
|
||||
quotas:
|
||||
description:
|
||||
- Dictionary that defines resource quotas to be set on a newly created RG.
|
||||
- 'This parameter is optional and only used when creating new RG. It is ignored for any operations on an
|
||||
existing RG.'
|
||||
- 'The following keys are valid to set the resource quotas:'
|
||||
- ' - I(cpu) (integer) - limit on the total number of CPUs that can be consumed by all compute instances
|
||||
in this RG.'
|
||||
- ' - I(ram) (integer) - limit on the total amount of RAM in GB that can be consumed by compute instances
|
||||
in this RG.'
|
||||
- ' - I(disk) (integer) - limit on the total volume of disk space in GB that can be consumed by all
|
||||
compute instances in this RG.'
|
||||
- ' - I(ext_ips) (integer) - maximum number of external IP addresses that can be allocated to the compute
|
||||
instances and virtual network segments (ViNS) in this RG.'
|
||||
- 'Each of the above keys is optional. For example, you may specify I(cpu) and I(ram) while omitting the
|
||||
other two keys. Then the quotas will be set on RAM and CPU leaving disk volume and the number of external
|
||||
IP addresses unlimited.'
|
||||
required: no
|
||||
rg_name:
|
||||
description:
|
||||
- Name of the RG to manage.
|
||||
required: yes
|
||||
state:
|
||||
description:
|
||||
- Specify the desired state of the resource group at the exit of the module.
|
||||
- 'Regardless of I(state), if RG exists and is in one of [DEPLOYING, DESTROYING, MIGRATING, ] states,
|
||||
do nothing.'
|
||||
- 'If desired I(state=present):'
|
||||
- ' - RG does not exist or is in DESTROYED state, create new RG according to the specifications.'
|
||||
- ' - RG is in one of [CREATED, DISABLED] states, change quotas if necessary.'
|
||||
- ' - RG is in DELETED state, restore it and change quotas if necessary. RG will be left in DISABLED state.'
|
||||
- ' - RG in any other state, abort with an error.'
|
||||
- 'If desired I(state=enabled):'
|
||||
- ' - RG does not exist or is in DESTROYED state, create new RG according to the specifications.'
|
||||
- ' - RG is in CREATED state, change quotas if necessary.'
|
||||
- ' - RG is in DELETED state, restore it, change quotas if necessary and enable.'
|
||||
- ' - RG is in any other state, abort with an error.'
|
||||
- 'If desired I(state=absent):'
|
||||
- ' - RG is in one of [CREATED, DISABLED, DELETED] states, destroy it.'
|
||||
- ' - RG in DESTROYED state, do nothing.'
|
||||
- ' - RG in any other state, abort with an error.'
|
||||
- 'If desired I(state=disabled):'
|
||||
- ' - RG does not exist or is in one of [ENABLING, DISABLING, DELETING, DELETED, DESTROYING, DESTROYED]
|
||||
states, abort with an error.'
|
||||
- ' - RG is DISABLED state, change quotas if necessary.'
|
||||
- ' - RG is in CREATED state, change quotas if necessary and disable the RG.'
|
||||
default: present
|
||||
choices: [ absent, disabled, enabled, present ]
|
||||
user:
|
||||
description:
|
||||
- 'Name of the legacy user for authenticating to the DECORT controller when I(authenticator=legacy).'
|
||||
- 'This parameter is required when I(authenticator=legacy) and ignored for other authentication modes.'
|
||||
- If not specified in the playbook, the value will be taken from DECORT_USER environment variable.
|
||||
required: no
|
||||
verify_ssl:
|
||||
description:
|
||||
- 'Controls SSL verification mode when making API calls to DECORT controller. Set it to False if you
|
||||
want to disable SSL certificate verification. Intended use case is when you run module in a trusted
|
||||
environment that uses self-signed certificates. Note that disabling SSL verification in any other
|
||||
scenario can lead to security issues, so please know what you are doing.'
|
||||
default: True
|
||||
required: no
|
||||
workflow_callback:
|
||||
description:
|
||||
- 'Callback URL that represents an application, which invokes this module (e.g. up-level orchestrator or
|
||||
end-user portal) and may except out-of-band updates on progress / exit status of the module run.'
|
||||
- API call at this URL will be used to relay such information to the application.
|
||||
- 'API call payload will include module-specific details about this module run and I(workflow_context).'
|
||||
required: no
|
||||
workflow_context:
|
||||
description:
|
||||
- 'Context data that will be included into the payload of the API call directed at I(workflow_callback) URL.'
|
||||
- 'This context data is expected to uniquely identify the task carried out by this module invocation so
|
||||
that up-level orchestrator could match returned information to the its internal entities.'
|
||||
required: no
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- name: create a new RG named "MyFirstRG" if it does not exist yet, set quotas on CPU and the number of exteranl IPs.
|
||||
decort_rg:
|
||||
authenticator: oauth2
|
||||
app_id: "{{ MY_APP_ID }}"
|
||||
app_secret: "{{ MY_APP_SECRET }}"
|
||||
controller_url: "https://cloud.digitalenergy.online"
|
||||
rg_name: "MyFirstRG"
|
||||
account_name: "MyMainAccount"
|
||||
quotas:
|
||||
cpu: 16
|
||||
ext_ips: 4
|
||||
annotation: "My first RG created with Ansible module"
|
||||
state: present
|
||||
delegate_to: localhost
|
||||
register: my_rg
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
facts:
|
||||
description: facts about the resource group
|
||||
returned: always
|
||||
type: dict
|
||||
sample:
|
||||
facts:
|
||||
id: 100
|
||||
name: MyFirstRG
|
||||
state: CREATED
|
||||
account_id: 10
|
||||
gid: 1001
|
||||
description: See L(Module Documentation,https://repository.basistech.ru/BASIS/decort-ansible/wiki/Home).
|
||||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
@@ -209,6 +12,7 @@ from ansible.module_utils.basic import env_fallback
|
||||
|
||||
from ansible.module_utils.decort_utils import *
|
||||
|
||||
|
||||
class decort_rg(DecortController):
|
||||
def __init__(self,amodule):
|
||||
super(decort_rg, self).__init__(amodule)
|
||||
@@ -347,7 +151,7 @@ class decort_rg(DecortController):
|
||||
self.validated_rg_id = self.rg_provision(self.validated_acc_id,
|
||||
self.amodule.params['rg_name'],
|
||||
self.amodule.params['owner'],
|
||||
self.amodule.params['annotation'],
|
||||
self.amodule.params['description'],
|
||||
self.amodule.params['resType'],
|
||||
self.amodule.params['def_netType'],
|
||||
self.amodule.params['ipcidr'],
|
||||
@@ -441,7 +245,7 @@ class decort_rg(DecortController):
|
||||
account_id=dict(type='int', required=False),
|
||||
account_name=dict(type='str', required=False, default=''),
|
||||
access=dict(type='dict'),
|
||||
annotation=dict(type='str', required=False, default=''),
|
||||
description=dict(type='str', required=False, default=''),
|
||||
app_id=dict(type='str',
|
||||
required=False,
|
||||
fallback=(env_fallback, ['DECORT_APP_ID'])),
|
||||
|
||||
@@ -1,23 +1,12 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
# Copyright: ...
|
||||
# ...
|
||||
|
||||
DOCUMENTATION = r'''
|
||||
---
|
||||
module: decort_user_info
|
||||
|
||||
version_added: "2.16"
|
||||
|
||||
description: See L(Module Documentation,https://repository.basistech.ru/BASIS/decort-ansible/wiki/Home).
|
||||
'''
|
||||
|
||||
# EXAMPLES = r'''
|
||||
# '''
|
||||
|
||||
# RETURN = r'''
|
||||
# '''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.decort_utils import DecortController
|
||||
|
||||
|
||||
@@ -1,239 +1,10 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Digital Enegry Cloud Orchestration Technology (DECORT) modules for Ansible
|
||||
# Copyright: (c) 2018-2021 Digital Energy Cloud Solutions LLC
|
||||
#
|
||||
# Apache License 2.0 (see http://www.apache.org/licenses/LICENSE-2.0.txt)
|
||||
#
|
||||
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'}
|
||||
|
||||
DOCUMENTATION = '''
|
||||
DOCUMENTATION = r'''
|
||||
---
|
||||
module: decort_vins
|
||||
short_description: Manage Virtual Network Segments (ViNS) in DECORT cloud
|
||||
description: >
|
||||
This module can be used to create new ViNS in DECORT cloud platform, obtain or
|
||||
modify its characteristics, and delete it.
|
||||
version_added: "2.2"
|
||||
author:
|
||||
requirements:
|
||||
- python >= 3.8
|
||||
- PyJWT Python module
|
||||
- requests Python module
|
||||
- netaddr Python module
|
||||
- decort_utils utility library (module)
|
||||
- DECORT cloud platform version 3.8.6 or higher
|
||||
notes:
|
||||
- Environment variables can be used to pass selected parameters to the module, see details below.
|
||||
- Specified Oauth2 provider must be trusted by the DECORT cloud controller on which JWT will be used.
|
||||
- 'Similarly, JWT supplied in I(authenticator=jwt) mode should be received from Oauth2 provider trusted by
|
||||
the DECORT cloud controller on which this JWT will be used.'
|
||||
options:
|
||||
account_id:
|
||||
description:
|
||||
- 'ID of the account under which this ViNS will be created (for new ViNS) or is located (for already
|
||||
existing ViNS). This is the alternative to I(account_name) option.'
|
||||
- If both I(account_id) and I(account_name) specified, then I(account_name) is ignored.
|
||||
required: no
|
||||
account_name:
|
||||
description:
|
||||
- 'Name of the account under which this ViNS will be created (for new RGs) or is located (for already
|
||||
existing ViNS).'
|
||||
- 'This parameter is ignored if I(account_id) is specified.'
|
||||
required: no
|
||||
annotation:
|
||||
description:
|
||||
- Optional text description of this virtual network segment.
|
||||
default: empty string
|
||||
required: no
|
||||
app_id:
|
||||
description:
|
||||
- 'Application ID for authenticating to the DECORT controller when I(authenticator=oauth2).'
|
||||
- 'Required if I(authenticator=oauth2).'
|
||||
- 'If not found in the playbook or command line arguments, the value will be taken from DECORT_APP_ID
|
||||
environment variable.'
|
||||
required: no
|
||||
app_secret:
|
||||
description:
|
||||
- 'Application API secret used for authenticating to the DECORT controller when I(authenticator=oauth2).'
|
||||
- This parameter is required when I(authenticator=oauth2) and ignored in other modes.
|
||||
- 'If not found in the playbook or command line arguments, the value will be taken from DECORT_APP_SECRET
|
||||
environment variable.'
|
||||
required: no
|
||||
authenticator:
|
||||
description:
|
||||
- Authentication mechanism to be used when accessing DECORT controller and authorizing API call.
|
||||
default: jwt
|
||||
choices: [ jwt, oauth2, legacy ]
|
||||
required: yes
|
||||
controller_url:
|
||||
description:
|
||||
- URL of the DECORT controller that will be contacted to manage the RG according to the specification.
|
||||
- 'This parameter is always required regardless of the specified I(authenticator) type.'
|
||||
required: yes
|
||||
ext_net_id:
|
||||
description:
|
||||
- 'Controls ViNS connection to an external network. This argument is optional with default value of -1,
|
||||
which means no external connection.'
|
||||
- Specify 0 to connect ViNS to external network and let platform select external network Id automatically.
|
||||
- Specify positive value to request ViNS connection to the external network with corresponding ID.
|
||||
- You may also control external IP address selection with I(ext_ip_addr) argument.
|
||||
default: -1
|
||||
required: no
|
||||
ext_ip_addr:
|
||||
description:
|
||||
- IP address to assign to the external interface of this ViNS when connecting to the external net.
|
||||
- If empty string is passed, the platform will assign free IP address automatically.
|
||||
- 'Note that if invalid IP address or an address already occupied by another client is specified,
|
||||
the module will abort with an error.'
|
||||
- 'This argument is used only for new connection to the specified network. You cannot select another
|
||||
external IP address without changing external network ID.'
|
||||
- ViNS connection to the external network is controlled by I(ext_net_id) argument.
|
||||
default: empty string
|
||||
required: no
|
||||
ipcidr:
|
||||
description:
|
||||
- Internal ViNS network address in a format XXX.XXX.XXX.XXX/XX (includes address and netmask).
|
||||
- If empty string is passed, the platform will assign network address automatically.
|
||||
- 'When selecting this address manually, note that this address must be unique amomng all ViNSes in
|
||||
the target account.'
|
||||
default: empty string
|
||||
required: no
|
||||
jwt:
|
||||
description:
|
||||
- 'JWT (access token) for authenticating to the DECORT controller when I(authenticator=jwt).'
|
||||
- 'This parameter is required if I(authenticator=jwt) and ignored for other authentication modes.'
|
||||
- If not specified in the playbook, the value will be taken from DECORT_JWT environment variable.
|
||||
required: no
|
||||
oauth2_url:
|
||||
description:
|
||||
- 'URL of the oauth2 authentication provider to use when I(authenticator=oauth2).'
|
||||
- 'This parameter is required when when I(authenticator=oauth2).'
|
||||
- 'If not specified in the playbook, the value will be taken from DECORT_OAUTH2_URL environment variable.'
|
||||
password:
|
||||
description:
|
||||
- 'Password for authenticating to the DECORT controller when I(authenticator=legacy).'
|
||||
- 'This parameter is required if I(authenticator=legacy) and ignored in other authentication modes.'
|
||||
- If not specified in the playbook, the value will be taken from DECORT_PASSWORD environment variable.
|
||||
required: no
|
||||
rg_id:
|
||||
description:
|
||||
- 'ID of the resource group (RG), where this ViNS will be created (for a new ViNS) or located
|
||||
(for already existing ViNS).'
|
||||
- If ViNS is created at the account level, I(rg_id) should be omitted or set to 0.
|
||||
- If both I(rg_id) and I(rg_name) are specified, then I(rg_name) is ignored.
|
||||
default: 0
|
||||
required: no
|
||||
rg_name:
|
||||
description:
|
||||
- 'Name of the resource group (RG), where this ViNS will be created (for new ViNS) or
|
||||
located (for already existing ViNS).'
|
||||
- If ViNS is created at the account level, I(rg_name) should be omitted or set to emtpy string.
|
||||
- If both I(rg_name) and I(rg_id) are specified, then I(rg_name) is ignored.
|
||||
default: empty string
|
||||
required: no
|
||||
state:
|
||||
description:
|
||||
- Specify the desired state of the ViNS at the exit of the module.
|
||||
- 'Regardless of I(state), if ViNS exists and is in one of [DEPLOYING, DESTROYING, MIGRATING] states,
|
||||
do nothing.'
|
||||
- 'If desired I(state=present):'
|
||||
- ' - ViNS does not exist or is in DESTROYED state, create new ViNS according to the specifications.'
|
||||
- ' - ViNS is in DELETED state, restore it and change quotas if necessary. Note that on successful
|
||||
restore ViNS will be left in DISABLED state.'
|
||||
- ' - ViNS is in one of [CREATED, ENABLED, DISABLED] states, do nothing.'
|
||||
- ' - ViNS in any other state, abort with an error.'
|
||||
- 'If desired I(state=enabled):'
|
||||
- ' - ViNS does not exist or is in DESTROYED state, create new ViNS according to the specifications.'
|
||||
- ' - ViNS is in DELETED state, restore and enable it.'
|
||||
- ' - ViNS is in one of [CREATED, ENABLED] states, do nothing.'
|
||||
- ' - viNS is in any other state, abort with an error.'
|
||||
- 'If desired I(state=absent):'
|
||||
- ' - ViNS is in one of [CREATED, ENABLED, DISABLED, DELETED] states, destroy it.'
|
||||
- ' - ViNS in DESTROYED state, do nothing.'
|
||||
- ' - ViNS in any other state, abort with an error.'
|
||||
- 'If desired I(state=disabled):'
|
||||
- ' - ViNS is in one of [CREATED, ENABLED] states, disable it.'
|
||||
- ' - ViNS is DISABLED state, do nothing.'
|
||||
- ' - ViNS does not exist or is in one of [ENABLING, DISABLING, DELETING, DELETED, DESTROYING, DESTROYED]
|
||||
states, abort with an error.'
|
||||
default: present
|
||||
choices: [ absent, disabled, enabled, present ]
|
||||
user:
|
||||
description:
|
||||
- 'Name of the legacy user for authenticating to the DECORT controller when I(authenticator=legacy).'
|
||||
- 'This parameter is required when I(authenticator=legacy) and ignored for other authentication modes.'
|
||||
- If not specified in the playbook, the value will be taken from DECORT_USER environment variable.
|
||||
required: no
|
||||
verify_ssl:
|
||||
description:
|
||||
- 'Controls SSL verification mode when making API calls to DECORT controller. Set it to False if you
|
||||
want to disable SSL certificate verification. Intended use case is when you run module in a trusted
|
||||
environment that uses self-signed certificates. Note that disabling SSL verification in any other
|
||||
scenario can lead to security issues, so please know what you are doing.'
|
||||
default: True
|
||||
required: no
|
||||
vins_id:
|
||||
description:
|
||||
- ID of the ViNs to manage. If ViNS is identified by ID it must be present.
|
||||
- If ViNS ID is specified, I(account_id), I(account_name), I(rg_id) and I(rg_name) are ignored.
|
||||
vins_name:
|
||||
description:
|
||||
- Name of the ViNS.
|
||||
- ViNS can exist at either account or resource group level.
|
||||
- ViNS name is unique only within its parent (i.e. account or resource group).
|
||||
- 'To create ViNS at account level omit both I(rg_id) and I(rg_name), or set them to 0 and empty
|
||||
string respectively.'
|
||||
required: yes
|
||||
workflow_callback:
|
||||
description:
|
||||
- 'Callback URL that represents an application, which invokes this module (e.g. up-level orchestrator or
|
||||
end-user portal) and may except out-of-band updates on progress / exit status of the module run.'
|
||||
- API call at this URL will be used to relay such information to the application.
|
||||
- 'API call payload will include module-specific details about this module run and I(workflow_context).'
|
||||
required: no
|
||||
workflow_context:
|
||||
description:
|
||||
- 'Context data that will be included into the payload of the API call directed at I(workflow_callback) URL.'
|
||||
- 'This context data is expected to uniquely identify the task carried out by this module invocation so
|
||||
that up-level orchestrator could match returned information to the its internal entities.'
|
||||
required: no
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- name: create a new ViNS named "MyViNS" if it does not exist yet under RG "MyRG" in the account "MyAccount".
|
||||
decort_vins:
|
||||
authenticator: oauth2
|
||||
app_id: "{{ MY_APP_ID }}"
|
||||
app_secret: "{{ MY_APP_SECRET }}"
|
||||
controller_url: "https://cloud.digitalenergy.online"
|
||||
vins_name: "MyViNS"
|
||||
rg_name: "MyRG"
|
||||
account_name: "MyAccount"
|
||||
state: present
|
||||
delegate_to: localhost
|
||||
register: my_vins
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
facts:
|
||||
description: facts about the virtual network segment
|
||||
returned: always
|
||||
type: dict
|
||||
sample:
|
||||
facts:
|
||||
id: 5
|
||||
name: MyViNS
|
||||
int_net_addr: 192.168.1.0
|
||||
ext_net_addr: 10.50.11.118
|
||||
state: CREATED
|
||||
account_id: 7
|
||||
rg_id: 19
|
||||
gid: 1001
|
||||
description: See L(Module Documentation,https://repository.basistech.ru/BASIS/decort-ansible/wiki/Home).
|
||||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
@@ -241,6 +12,7 @@ from ansible.module_utils.basic import env_fallback
|
||||
|
||||
from ansible.module_utils.decort_utils import *
|
||||
|
||||
|
||||
class decort_vins(DecortController):
|
||||
def __init__(self,arg_amodule):
|
||||
super(decort_vins, self).__init__(arg_amodule)
|
||||
@@ -337,7 +109,7 @@ class decort_vins(DecortController):
|
||||
self.acc_id, self.rg_id,
|
||||
self.amodule.params['ipcidr'],
|
||||
self.amodule.params['ext_net_id'], self.amodule.params['ext_ip_addr'],
|
||||
self.amodule.params['annotation'])
|
||||
self.amodule.params['description'])
|
||||
|
||||
if self.amodule.params['mgmtaddr'] or self.amodule.params['connect_to']:
|
||||
_, self.vins_facts = self.vins_find(self.vins_id)
|
||||
@@ -473,7 +245,7 @@ class decort_vins(DecortController):
|
||||
return dict(
|
||||
account_id=dict(type='int', required=False,default=0),
|
||||
account_name=dict(type='str', required=False, default=''),
|
||||
annotation=dict(type='str', required=False, default=''),
|
||||
description=dict(type='str', required=False, default=''),
|
||||
app_id=dict(type='str',
|
||||
required=False,
|
||||
fallback=(env_fallback, ['DECORT_APP_ID'])),
|
||||
|
||||
Reference in New Issue
Block a user