6.1.0
This commit is contained in:
@@ -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'])),
|
||||
|
||||
Reference in New Issue
Block a user