cloudstack: cs_template: remove dependency to CloudStackException
* fixes docs * fixes pep8
This commit is contained in:
parent
fde4244d04
commit
d7fa3ab487
2 changed files with 153 additions and 211 deletions
|
@ -41,182 +41,141 @@ options:
|
||||||
- URL of where the template is hosted on C(state=present).
|
- URL of where the template is hosted on C(state=present).
|
||||||
- URL to which the template would be extracted on C(state=extracted).
|
- URL to which the template would be extracted on C(state=extracted).
|
||||||
- Mutually exclusive with C(vm).
|
- Mutually exclusive with C(vm).
|
||||||
required: false
|
|
||||||
default: null
|
|
||||||
vm:
|
vm:
|
||||||
description:
|
description:
|
||||||
- VM name the template will be created from its volume or alternatively from a snapshot.
|
- VM name the template will be created from its volume or alternatively from a snapshot.
|
||||||
- VM must be in stopped state if created from its volume.
|
- VM must be in stopped state if created from its volume.
|
||||||
- Mutually exclusive with C(url).
|
- Mutually exclusive with C(url).
|
||||||
required: false
|
|
||||||
default: null
|
|
||||||
snapshot:
|
snapshot:
|
||||||
description:
|
description:
|
||||||
- Name of the snapshot, created from the VM ROOT volume, the template will be created from.
|
- Name of the snapshot, created from the VM ROOT volume, the template will be created from.
|
||||||
- C(vm) is required together with this argument.
|
- C(vm) is required together with this argument.
|
||||||
required: false
|
|
||||||
default: null
|
|
||||||
os_type:
|
os_type:
|
||||||
description:
|
description:
|
||||||
- OS type that best represents the OS of this template.
|
- OS type that best represents the OS of this template.
|
||||||
required: false
|
|
||||||
default: null
|
|
||||||
checksum:
|
checksum:
|
||||||
description:
|
description:
|
||||||
- The MD5 checksum value of this template.
|
- The MD5 checksum value of this template.
|
||||||
- If set, we search by checksum instead of name.
|
- If set, we search by checksum instead of name.
|
||||||
required: false
|
|
||||||
default: false
|
default: false
|
||||||
is_ready:
|
is_ready:
|
||||||
description:
|
description:
|
||||||
- This flag is used for searching existing templates.
|
- This flag is used for searching existing templates.
|
||||||
- If set to C(true), it will only list template ready for deployment e.g. successfully downloaded and installed.
|
- If set to C(true), it will only list template ready for deployment e.g. successfully downloaded and installed.
|
||||||
- Recommended to set it to C(false).
|
- Recommended to set it to C(false).
|
||||||
required: false
|
|
||||||
default: false
|
default: false
|
||||||
is_public:
|
is_public:
|
||||||
description:
|
description:
|
||||||
- Register the template to be publicly available to all users.
|
- Register the template to be publicly available to all users.
|
||||||
- Only used if C(state) is present.
|
- Only used if C(state) is present.
|
||||||
required: false
|
|
||||||
default: false
|
default: false
|
||||||
is_featured:
|
is_featured:
|
||||||
description:
|
description:
|
||||||
- Register the template to be featured.
|
- Register the template to be featured.
|
||||||
- Only used if C(state) is present.
|
- Only used if C(state) is present.
|
||||||
required: false
|
|
||||||
default: false
|
default: false
|
||||||
is_dynamically_scalable:
|
is_dynamically_scalable:
|
||||||
description:
|
description:
|
||||||
- Register the template having XS/VMWare tools installed in order to support dynamic scaling of VM CPU/memory.
|
- Register the template having XS/VMWare tools installed in order to support dynamic scaling of VM CPU/memory.
|
||||||
- Only used if C(state) is present.
|
- Only used if C(state) is present.
|
||||||
required: false
|
|
||||||
default: false
|
default: false
|
||||||
cross_zones:
|
cross_zones:
|
||||||
description:
|
description:
|
||||||
- Whether the template should be synced or removed across zones.
|
- Whether the template should be synced or removed across zones.
|
||||||
- Only used if C(state) is present or absent.
|
- Only used if C(state) is present or absent.
|
||||||
required: false
|
|
||||||
default: false
|
default: false
|
||||||
mode:
|
mode:
|
||||||
description:
|
description:
|
||||||
- Mode for the template extraction.
|
- Mode for the template extraction.
|
||||||
- Only used if C(state=extracted).
|
- Only used if C(state=extracted).
|
||||||
required: false
|
required: false
|
||||||
default: 'http_download'
|
default: http_download
|
||||||
choices: [ 'http_download', 'ftp_upload' ]
|
choices: [ http_download, ftp_upload ]
|
||||||
domain:
|
domain:
|
||||||
description:
|
description:
|
||||||
- Domain the template, snapshot or VM is related to.
|
- Domain the template, snapshot or VM is related to.
|
||||||
required: false
|
|
||||||
default: null
|
|
||||||
account:
|
account:
|
||||||
description:
|
description:
|
||||||
- Account the template, snapshot or VM is related to.
|
- Account the template, snapshot or VM is related to.
|
||||||
required: false
|
|
||||||
default: null
|
|
||||||
project:
|
project:
|
||||||
description:
|
description:
|
||||||
- Name of the project the template to be registered in.
|
- Name of the project the template to be registered in.
|
||||||
required: false
|
|
||||||
default: null
|
|
||||||
zone:
|
zone:
|
||||||
description:
|
description:
|
||||||
- Name of the zone you wish the template to be registered or deleted from.
|
- Name of the zone you wish the template to be registered or deleted from.
|
||||||
- If not specified, first found zone will be used.
|
- If not specified, first found zone will be used.
|
||||||
required: false
|
|
||||||
default: null
|
|
||||||
template_filter:
|
template_filter:
|
||||||
description:
|
description:
|
||||||
- Name of the filter used to search for the template.
|
- Name of the filter used to search for the template.
|
||||||
required: false
|
required: false
|
||||||
default: 'self'
|
default: self
|
||||||
choices: [ 'featured', 'self', 'selfexecutable', 'sharedexecutable', 'executable', 'community' ]
|
choices: [ featured, self, selfexecutable, sharedexecutable, executable, community ]
|
||||||
hypervisor:
|
hypervisor:
|
||||||
description:
|
description:
|
||||||
- Name the hypervisor to be used for creating the new template.
|
- Name the hypervisor to be used for creating the new template.
|
||||||
- Relevant when using C(state=present).
|
- Relevant when using C(state=present).
|
||||||
required: false
|
choices: [ KVM, VMware, BareMetal, XenServer, LXC, HyperV, UCS, OVM, Simulator ]
|
||||||
default: null
|
|
||||||
choices: [ 'KVM', 'VMware', 'BareMetal', 'XenServer', 'LXC', 'HyperV', 'UCS', 'OVM' ]
|
|
||||||
requires_hvm:
|
requires_hvm:
|
||||||
description:
|
description:
|
||||||
- true if this template requires HVM.
|
- true if this template requires HVM.
|
||||||
required: false
|
|
||||||
default: false
|
default: false
|
||||||
password_enabled:
|
password_enabled:
|
||||||
description:
|
description:
|
||||||
- True if the template supports the password reset feature.
|
- True if the template supports the password reset feature.
|
||||||
required: false
|
|
||||||
default: false
|
default: false
|
||||||
template_tag:
|
template_tag:
|
||||||
description:
|
description:
|
||||||
- the tag for this template.
|
- the tag for this template.
|
||||||
required: false
|
|
||||||
default: null
|
|
||||||
sshkey_enabled:
|
sshkey_enabled:
|
||||||
description:
|
description:
|
||||||
- True if the template supports the sshkey upload feature.
|
- True if the template supports the sshkey upload feature.
|
||||||
required: false
|
|
||||||
default: false
|
default: false
|
||||||
is_routing:
|
is_routing:
|
||||||
description:
|
description:
|
||||||
- True if the template type is routing i.e., if template is used to deploy router.
|
- True if the template type is routing i.e., if template is used to deploy router.
|
||||||
- Only considered if C(url) is used.
|
- Only considered if C(url) is used.
|
||||||
required: false
|
|
||||||
default: null
|
|
||||||
format:
|
format:
|
||||||
description:
|
description:
|
||||||
- The format for the template.
|
- The format for the template.
|
||||||
- Relevant when using C(state=present).
|
- Relevant when using C(state=present).
|
||||||
required: false
|
choices: [ QCOW2, RAW, VHD, OVA ]
|
||||||
default: null
|
|
||||||
choices: [ 'QCOW2', 'RAW', 'VHD', 'OVA' ]
|
|
||||||
is_extractable:
|
is_extractable:
|
||||||
description:
|
description:
|
||||||
- True if the template or its derivatives are extractable.
|
- True if the template or its derivatives are extractable.
|
||||||
required: false
|
|
||||||
default: false
|
default: false
|
||||||
details:
|
details:
|
||||||
description:
|
description:
|
||||||
- Template details in key/value pairs.
|
- Template details in key/value pairs.
|
||||||
required: false
|
|
||||||
default: null
|
|
||||||
bits:
|
bits:
|
||||||
description:
|
description:
|
||||||
- 32 or 64 bits support.
|
- 32 or 64 bits support.
|
||||||
required: false
|
required: false
|
||||||
default: '64'
|
default: 64
|
||||||
display_text:
|
display_text:
|
||||||
description:
|
description:
|
||||||
- Display text of the template.
|
- Display text of the template.
|
||||||
required: false
|
|
||||||
default: null
|
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- State of the template.
|
- State of the template.
|
||||||
required: false
|
required: false
|
||||||
default: 'present'
|
default: present
|
||||||
choices: [ 'present', 'absent', 'extacted' ]
|
choices: [ present, absent, extracted ]
|
||||||
poll_async:
|
poll_async:
|
||||||
description:
|
description:
|
||||||
- Poll async jobs until job has finished.
|
- Poll async jobs until job has finished.
|
||||||
required: false
|
|
||||||
default: true
|
default: true
|
||||||
tags:
|
tags:
|
||||||
description:
|
description:
|
||||||
- List of tags. Tags are a list of dictionaries having keys C(key) and C(value).
|
- List of tags. Tags are a list of dictionaries having keys C(key) and C(value).
|
||||||
- "To delete all tags, set a empty list e.g. C(tags: [])."
|
- "To delete all tags, set a empty list e.g. C(tags: [])."
|
||||||
required: false
|
aliases: [ tag ]
|
||||||
default: null
|
|
||||||
aliases: [ 'tag' ]
|
|
||||||
version_added: "2.4"
|
version_added: "2.4"
|
||||||
extends_documentation_fragment: cloudstack
|
extends_documentation_fragment: cloudstack
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
# Register a systemvm template
|
- name: register a systemvm template
|
||||||
- local_action:
|
local_action:
|
||||||
module: cs_template
|
module: cs_template
|
||||||
name: systemvm-vmware-4.5
|
name: systemvm-vmware-4.5
|
||||||
url: "http://packages.shapeblue.com/systemvmtemplate/4.5/systemvm64template-4.5-vmware.ova"
|
url: "http://packages.shapeblue.com/systemvmtemplate/4.5/systemvm64template-4.5-vmware.ova"
|
||||||
|
@ -225,8 +184,8 @@ EXAMPLES = '''
|
||||||
cross_zones: yes
|
cross_zones: yes
|
||||||
os_type: Debian GNU/Linux 7(64-bit)
|
os_type: Debian GNU/Linux 7(64-bit)
|
||||||
|
|
||||||
# Create a template from a stopped virtual machine's volume
|
- name: create a template from a stopped virtual machine's volume
|
||||||
- local_action:
|
local_action:
|
||||||
module: cs_template
|
module: cs_template
|
||||||
name: debian-base-template
|
name: debian-base-template
|
||||||
vm: debian-base-vm
|
vm: debian-base-vm
|
||||||
|
@ -235,8 +194,8 @@ EXAMPLES = '''
|
||||||
password_enabled: yes
|
password_enabled: yes
|
||||||
is_public: yes
|
is_public: yes
|
||||||
|
|
||||||
# Create a template from a virtual machine's root volume snapshot
|
- name: create a template from a virtual machine's root volume snapshot
|
||||||
- local_action:
|
local_action:
|
||||||
module: cs_template
|
module: cs_template
|
||||||
name: debian-base-template
|
name: debian-base-template
|
||||||
vm: debian-base-vm
|
vm: debian-base-vm
|
||||||
|
@ -246,8 +205,8 @@ EXAMPLES = '''
|
||||||
password_enabled: yes
|
password_enabled: yes
|
||||||
is_public: yes
|
is_public: yes
|
||||||
|
|
||||||
# Remove a template
|
- name: Remove a template
|
||||||
- local_action:
|
local_action:
|
||||||
module: cs_template
|
module: cs_template
|
||||||
name: systemvm-4.2
|
name: systemvm-4.2
|
||||||
cross_zones: yes
|
cross_zones: yes
|
||||||
|
@ -388,8 +347,13 @@ project:
|
||||||
sample: Production
|
sample: Production
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# import cloudstack common
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.cloudstack import *
|
from ansible.module_utils.cloudstack import (
|
||||||
|
AnsibleCloudStack,
|
||||||
|
cs_argument_spec,
|
||||||
|
cs_required_together,
|
||||||
|
CS_HYPERVISORS
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class AnsibleCloudStackTemplate(AnsibleCloudStack):
|
class AnsibleCloudStackTemplate(AnsibleCloudStack):
|
||||||
|
@ -397,78 +361,76 @@ class AnsibleCloudStackTemplate(AnsibleCloudStack):
|
||||||
def __init__(self, module):
|
def __init__(self, module):
|
||||||
super(AnsibleCloudStackTemplate, self).__init__(module)
|
super(AnsibleCloudStackTemplate, self).__init__(module)
|
||||||
self.returns = {
|
self.returns = {
|
||||||
'checksum': 'checksum',
|
'checksum': 'checksum',
|
||||||
'status': 'status',
|
'status': 'status',
|
||||||
'isready': 'is_ready',
|
'isready': 'is_ready',
|
||||||
'templatetag': 'template_tag',
|
'templatetag': 'template_tag',
|
||||||
'sshkeyenabled': 'sshkey_enabled',
|
'sshkeyenabled': 'sshkey_enabled',
|
||||||
'passwordenabled': 'password_enabled',
|
'passwordenabled': 'password_enabled',
|
||||||
'tempaltetype': 'template_type',
|
'tempaltetype': 'template_type',
|
||||||
'ostypename': 'os_type',
|
'ostypename': 'os_type',
|
||||||
'crossZones': 'cross_zones',
|
'crossZones': 'cross_zones',
|
||||||
'isextractable': 'is_extractable',
|
'isextractable': 'is_extractable',
|
||||||
'isfeatured': 'is_featured',
|
'isfeatured': 'is_featured',
|
||||||
'ispublic': 'is_public',
|
'ispublic': 'is_public',
|
||||||
'format': 'format',
|
'format': 'format',
|
||||||
'hypervisor': 'hypervisor',
|
'hypervisor': 'hypervisor',
|
||||||
'url': 'url',
|
'url': 'url',
|
||||||
'extractMode': 'mode',
|
'extractMode': 'mode',
|
||||||
'state': 'state',
|
'state': 'state',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _get_args(self):
|
def _get_args(self):
|
||||||
args = {}
|
args = {
|
||||||
args['name'] = self.module.params.get('name')
|
'name': self.module.params.get('name'),
|
||||||
args['displaytext'] = self.get_or_fallback('display_text', 'name')
|
'displaytext': self.get_or_fallback('display_text', 'name'),
|
||||||
args['bits'] = self.module.params.get('bits')
|
'bits': self.module.params.get('bits'),
|
||||||
args['isdynamicallyscalable'] = self.module.params.get('is_dynamically_scalable')
|
'isdynamicallyscalable': self.module.params.get('is_dynamically_scalable'),
|
||||||
args['isextractable'] = self.module.params.get('is_extractable')
|
'isextractable': self.module.params.get('is_extractable'),
|
||||||
args['isfeatured'] = self.module.params.get('is_featured')
|
'isfeatured': self.module.params.get('is_featured'),
|
||||||
args['ispublic'] = self.module.params.get('is_public')
|
'ispublic': self.module.params.get('is_public'),
|
||||||
args['passwordenabled'] = self.module.params.get('password_enabled')
|
'passwordenabled': self.module.params.get('password_enabled'),
|
||||||
args['requireshvm'] = self.module.params.get('requires_hvm')
|
'requireshvm': self.module.params.get('requires_hvm'),
|
||||||
args['templatetag'] = self.module.params.get('template_tag')
|
'templatetag': self.module.params.get('template_tag'),
|
||||||
args['ostypeid'] = self.get_os_type(key='id')
|
'ostypeid': self.get_os_type(key='id'),
|
||||||
|
}
|
||||||
|
|
||||||
if not args['ostypeid']:
|
if not args['ostypeid']:
|
||||||
self.module.fail_json(msg="Missing required arguments: os_type")
|
self.module.fail_json(msg="Missing required arguments: os_type")
|
||||||
|
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
def get_root_volume(self, key=None):
|
def get_root_volume(self, key=None):
|
||||||
args = {}
|
args = {
|
||||||
args['account'] = self.get_account(key='name')
|
'account': self.get_account(key='name'),
|
||||||
args['domainid'] = self.get_domain(key='id')
|
'domainid': self.get_domain(key='id'),
|
||||||
args['projectid'] = self.get_project(key='id')
|
'projectid': self.get_project(key='id'),
|
||||||
args['virtualmachineid'] = self.get_vm(key='id')
|
'virtualmachineid': self.get_vm(key='id'),
|
||||||
args['type'] = "ROOT"
|
'type': "ROOT"
|
||||||
|
}
|
||||||
volumes = self.cs.listVolumes(**args)
|
volumes = self.query_api('listVolumes', **args)
|
||||||
if volumes:
|
if volumes:
|
||||||
return self._get_by_key(key, volumes['volume'][0])
|
return self._get_by_key(key, volumes['volume'][0])
|
||||||
self.module.fail_json(msg="Root volume for '%s' not found" % self.get_vm('name'))
|
self.module.fail_json(msg="Root volume for '%s' not found" % self.get_vm('name'))
|
||||||
|
|
||||||
|
|
||||||
def get_snapshot(self, key=None):
|
def get_snapshot(self, key=None):
|
||||||
snapshot = self.module.params.get('snapshot')
|
snapshot = self.module.params.get('snapshot')
|
||||||
if not snapshot:
|
if not snapshot:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
args = {}
|
args = {
|
||||||
args['account'] = self.get_account(key='name')
|
'account': self.get_account(key='name'),
|
||||||
args['domainid'] = self.get_domain(key='id')
|
'domainid': self.get_domain(key='id'),
|
||||||
args['projectid'] = self.get_project(key='id')
|
'projectid': self.get_project(key='id'),
|
||||||
args['volumeid'] = self.get_root_volume('id')
|
'volumeid': self.get_root_volume('id')
|
||||||
snapshots = self.cs.listSnapshots(**args)
|
}
|
||||||
|
snapshots = self.query_api('listSnapshots', **args)
|
||||||
if snapshots:
|
if snapshots:
|
||||||
for s in snapshots['snapshot']:
|
for s in snapshots['snapshot']:
|
||||||
if snapshot in [ s['name'], s['id'] ]:
|
if snapshot in [s['name'], s['id']]:
|
||||||
return self._get_by_key(key, s)
|
return self._get_by_key(key, s)
|
||||||
self.module.fail_json(msg="Snapshot '%s' not found" % snapshot)
|
self.module.fail_json(msg="Snapshot '%s' not found" % snapshot)
|
||||||
|
|
||||||
|
|
||||||
def create_template(self):
|
def create_template(self):
|
||||||
template = self.get_template()
|
template = self.get_template()
|
||||||
if not template:
|
if not template:
|
||||||
|
@ -479,13 +441,10 @@ class AnsibleCloudStackTemplate(AnsibleCloudStack):
|
||||||
if snapshot_id:
|
if snapshot_id:
|
||||||
args['snapshotid'] = snapshot_id
|
args['snapshotid'] = snapshot_id
|
||||||
else:
|
else:
|
||||||
args['volumeid'] = self.get_root_volume('id')
|
args['volumeid'] = self.get_root_volume('id')
|
||||||
|
|
||||||
if not self.module.check_mode:
|
if not self.module.check_mode:
|
||||||
template = self.cs.createTemplate(**args)
|
template = self.query_api('createTemplate', **args)
|
||||||
|
|
||||||
if 'errortext' in template:
|
|
||||||
self.module.fail_json(msg="Failed: '%s'" % template['errortext'])
|
|
||||||
|
|
||||||
poll_async = self.module.params.get('poll_async')
|
poll_async = self.module.params.get('poll_async')
|
||||||
if poll_async:
|
if poll_async:
|
||||||
|
@ -495,7 +454,6 @@ class AnsibleCloudStackTemplate(AnsibleCloudStack):
|
||||||
|
|
||||||
return template
|
return template
|
||||||
|
|
||||||
|
|
||||||
def register_template(self):
|
def register_template(self):
|
||||||
required_params = [
|
required_params = [
|
||||||
'format',
|
'format',
|
||||||
|
@ -506,17 +464,19 @@ class AnsibleCloudStackTemplate(AnsibleCloudStack):
|
||||||
template = self.get_template()
|
template = self.get_template()
|
||||||
if not template:
|
if not template:
|
||||||
self.result['changed'] = True
|
self.result['changed'] = True
|
||||||
args = self._get_args()
|
args = self._get_args()
|
||||||
args['url'] = self.module.params.get('url')
|
args.update({
|
||||||
args['format'] = self.module.params.get('format')
|
'url': self.module.params.get('url'),
|
||||||
args['checksum'] = self.module.params.get('checksum')
|
'format': self.module.params.get('format'),
|
||||||
args['isextractable'] = self.module.params.get('is_extractable')
|
'checksum': self.module.params.get('checksum'),
|
||||||
args['isrouting'] = self.module.params.get('is_routing')
|
'isextractable': self.module.params.get('is_extractable'),
|
||||||
args['sshkeyenabled'] = self.module.params.get('sshkey_enabled')
|
'isrouting': self.module.params.get('is_routing'),
|
||||||
args['hypervisor'] = self.get_hypervisor()
|
'sshkeyenabled': self.module.params.get('sshkey_enabled'),
|
||||||
args['domainid'] = self.get_domain(key='id')
|
'hypervisor': self.get_hypervisor(),
|
||||||
args['account'] = self.get_account(key='name')
|
'domainid': self.get_domain(key='id'),
|
||||||
args['projectid'] = self.get_project(key='id')
|
'account': self.get_account(key='name'),
|
||||||
|
'projectid': self.get_project(key='id'),
|
||||||
|
})
|
||||||
|
|
||||||
if not self.module.params.get('cross_zones'):
|
if not self.module.params.get('cross_zones'):
|
||||||
args['zoneid'] = self.get_zone(key='id')
|
args['zoneid'] = self.get_zone(key='id')
|
||||||
|
@ -524,21 +484,18 @@ class AnsibleCloudStackTemplate(AnsibleCloudStack):
|
||||||
args['zoneid'] = -1
|
args['zoneid'] = -1
|
||||||
|
|
||||||
if not self.module.check_mode:
|
if not self.module.check_mode:
|
||||||
res = self.cs.registerTemplate(**args)
|
res = self.query_api('registerTemplate', **args)
|
||||||
if 'errortext' in res:
|
|
||||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
|
||||||
template = res['template']
|
template = res['template']
|
||||||
return template
|
return template
|
||||||
|
|
||||||
|
|
||||||
def get_template(self):
|
def get_template(self):
|
||||||
args = {}
|
args = {
|
||||||
args['isready'] = self.module.params.get('is_ready')
|
'isready': self.module.params.get('is_ready'),
|
||||||
args['templatefilter'] = self.module.params.get('template_filter')
|
'templatefilter': self.module.params.get('template_filter'),
|
||||||
args['domainid'] = self.get_domain(key='id')
|
'domainid': self.get_domain(key='id'),
|
||||||
args['account'] = self.get_account(key='name')
|
'account': self.get_account(key='name'),
|
||||||
args['projectid'] = self.get_project(key='id')
|
'projectid': self.get_project(key='id')
|
||||||
|
}
|
||||||
if not self.module.params.get('cross_zones'):
|
if not self.module.params.get('cross_zones'):
|
||||||
args['zoneid'] = self.get_zone(key='id')
|
args['zoneid'] = self.get_zone(key='id')
|
||||||
|
|
||||||
|
@ -547,7 +504,7 @@ class AnsibleCloudStackTemplate(AnsibleCloudStack):
|
||||||
if not checksum:
|
if not checksum:
|
||||||
args['name'] = self.module.params.get('name')
|
args['name'] = self.module.params.get('name')
|
||||||
|
|
||||||
templates = self.cs.listTemplates(**args)
|
templates = self.query_api('listTemplates', **args)
|
||||||
if templates:
|
if templates:
|
||||||
# if checksum is set, we only look on that.
|
# if checksum is set, we only look on that.
|
||||||
if not checksum:
|
if not checksum:
|
||||||
|
@ -558,48 +515,40 @@ class AnsibleCloudStackTemplate(AnsibleCloudStack):
|
||||||
return i
|
return i
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def extract_template(self):
|
def extract_template(self):
|
||||||
template = self.get_template()
|
template = self.get_template()
|
||||||
if not template:
|
if not template:
|
||||||
self.module.fail_json(msg="Failed: template not found")
|
self.module.fail_json(msg="Failed: template not found")
|
||||||
|
|
||||||
args = {}
|
args = {
|
||||||
args['id'] = template['id']
|
'id': template['id'],
|
||||||
args['url'] = self.module.params.get('url')
|
'url': self.module.params.get('url'),
|
||||||
args['mode'] = self.module.params.get('mode')
|
'mode': self.module.params.get('mode'),
|
||||||
args['zoneid'] = self.get_zone(key='id')
|
'zoneid': self.get_zone(key='id')
|
||||||
|
}
|
||||||
self.result['changed'] = True
|
self.result['changed'] = True
|
||||||
|
|
||||||
if not self.module.check_mode:
|
if not self.module.check_mode:
|
||||||
template = self.cs.extractTemplate(**args)
|
template = self.query_api('extractTemplate', **args)
|
||||||
|
|
||||||
if 'errortext' in template:
|
|
||||||
self.module.fail_json(msg="Failed: '%s'" % template['errortext'])
|
|
||||||
|
|
||||||
poll_async = self.module.params.get('poll_async')
|
poll_async = self.module.params.get('poll_async')
|
||||||
if poll_async:
|
if poll_async:
|
||||||
template = self.poll_job(template, 'template')
|
template = self.poll_job(template, 'template')
|
||||||
return template
|
return template
|
||||||
|
|
||||||
|
|
||||||
def remove_template(self):
|
def remove_template(self):
|
||||||
template = self.get_template()
|
template = self.get_template()
|
||||||
if template:
|
if template:
|
||||||
self.result['changed'] = True
|
self.result['changed'] = True
|
||||||
|
|
||||||
args = {}
|
args = {
|
||||||
args['id'] = template['id']
|
'id': template['id']
|
||||||
|
}
|
||||||
if not self.module.params.get('cross_zones'):
|
if not self.module.params.get('cross_zones'):
|
||||||
args['zoneid'] = self.get_zone(key='id')
|
args['zoneid'] = self.get_zone(key='id')
|
||||||
|
|
||||||
if not self.module.check_mode:
|
if not self.module.check_mode:
|
||||||
res = self.cs.deleteTemplate(**args)
|
res = self.query_api('deleteTemplate', **args)
|
||||||
|
|
||||||
if 'errortext' in res:
|
|
||||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
|
||||||
|
|
||||||
poll_async = self.module.params.get('poll_async')
|
poll_async = self.module.params.get('poll_async')
|
||||||
if poll_async:
|
if poll_async:
|
||||||
|
@ -607,79 +556,73 @@ class AnsibleCloudStackTemplate(AnsibleCloudStack):
|
||||||
return template
|
return template
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
argument_spec = cs_argument_spec()
|
argument_spec = cs_argument_spec()
|
||||||
argument_spec.update(dict(
|
argument_spec.update(dict(
|
||||||
name = dict(required=True),
|
name=dict(required=True),
|
||||||
display_text = dict(default=None),
|
display_text=dict(),
|
||||||
url = dict(default=None),
|
url=dict(),
|
||||||
vm = dict(default=None),
|
vm=dict(),
|
||||||
snapshot = dict(default=None),
|
snapshot=dict(),
|
||||||
os_type = dict(default=None),
|
os_type=dict(),
|
||||||
is_ready = dict(type='bool', default=False),
|
is_ready=dict(type='bool', default=False),
|
||||||
is_public = dict(type='bool', default=True),
|
is_public=dict(type='bool', default=True),
|
||||||
is_featured = dict(type='bool', default=False),
|
is_featured=dict(type='bool', default=False),
|
||||||
is_dynamically_scalable = dict(type='bool', default=False),
|
is_dynamically_scalable=dict(type='bool', default=False),
|
||||||
is_extractable = dict(type='bool', default=False),
|
is_extractable=dict(type='bool', default=False),
|
||||||
is_routing = dict(type='bool', default=None),
|
is_routing=dict(type='bool'),
|
||||||
checksum = dict(default=None),
|
checksum=dict(),
|
||||||
template_filter = dict(default='self', choices=['featured', 'self', 'selfexecutable', 'sharedexecutable', 'executable', 'community']),
|
template_filter=dict(default='self', choices=['featured', 'self', 'selfexecutable', 'sharedexecutable', 'executable', 'community']),
|
||||||
hypervisor = dict(choices=CS_HYPERVISORS, default=None),
|
hypervisor=dict(choices=CS_HYPERVISORS),
|
||||||
requires_hvm = dict(type='bool', default=False),
|
requires_hvm=dict(type='bool', default=False),
|
||||||
password_enabled = dict(type='bool', default=False),
|
password_enabled=dict(type='bool', default=False),
|
||||||
template_tag = dict(default=None),
|
template_tag=dict(),
|
||||||
sshkey_enabled = dict(type='bool', default=False),
|
sshkey_enabled=dict(type='bool', default=False),
|
||||||
format = dict(choices=['QCOW2', 'RAW', 'VHD', 'OVA'], default=None),
|
format=dict(choices=['QCOW2', 'RAW', 'VHD', 'OVA'], ),
|
||||||
details = dict(default=None),
|
details=dict(),
|
||||||
bits = dict(type='int', choices=[ 32, 64 ], default=64),
|
bits=dict(type='int', choices=[32, 64], default=64),
|
||||||
state = dict(choices=['present', 'absent', 'extracted'], default='present'),
|
state=dict(choices=['present', 'absent', 'extracted'], default='present'),
|
||||||
cross_zones = dict(type='bool', default=False),
|
cross_zones=dict(type='bool', default=False),
|
||||||
mode = dict(choices=['http_download', 'ftp_upload'], default='http_download'),
|
mode=dict(choices=['http_download', 'ftp_upload'], default='http_download'),
|
||||||
zone = dict(default=None),
|
zone=dict(),
|
||||||
domain = dict(default=None),
|
domain=dict(),
|
||||||
account = dict(default=None),
|
account=dict(),
|
||||||
project = dict(default=None),
|
project=dict(),
|
||||||
poll_async = dict(type='bool', default=True),
|
poll_async=dict(type='bool', default=True),
|
||||||
tags=dict(type='list', aliases=['tag'], default=None),
|
tags=dict(type='list', aliases=['tag']),
|
||||||
))
|
))
|
||||||
|
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec=argument_spec,
|
argument_spec=argument_spec,
|
||||||
required_together=cs_required_together(),
|
required_together=cs_required_together(),
|
||||||
mutually_exclusive = (
|
mutually_exclusive=(
|
||||||
['url', 'vm'],
|
['url', 'vm'],
|
||||||
['zone', 'cross_zones'],
|
['zone', 'cross_zones'],
|
||||||
),
|
),
|
||||||
supports_check_mode=True
|
supports_check_mode=True
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
acs_tpl = AnsibleCloudStackTemplate(module)
|
||||||
acs_tpl = AnsibleCloudStackTemplate(module)
|
|
||||||
|
|
||||||
state = module.params.get('state')
|
state = module.params.get('state')
|
||||||
if state in ['absent']:
|
if state in ['absent']:
|
||||||
tpl = acs_tpl.remove_template()
|
tpl = acs_tpl.remove_template()
|
||||||
|
|
||||||
elif state in ['extracted']:
|
elif state in ['extracted']:
|
||||||
tpl = acs_tpl.extract_template()
|
tpl = acs_tpl.extract_template()
|
||||||
|
|
||||||
|
else:
|
||||||
|
if module.params.get('url'):
|
||||||
|
tpl = acs_tpl.register_template()
|
||||||
|
elif module.params.get('vm'):
|
||||||
|
tpl = acs_tpl.create_template()
|
||||||
else:
|
else:
|
||||||
if module.params.get('url'):
|
module.fail_json(msg="one of the following is required on state=present: url,vm")
|
||||||
tpl = acs_tpl.register_template()
|
|
||||||
elif module.params.get('vm'):
|
|
||||||
tpl = acs_tpl.create_template()
|
|
||||||
else:
|
|
||||||
module.fail_json(msg="one of the following is required on state=present: url,vm")
|
|
||||||
|
|
||||||
result = acs_tpl.get_result(tpl)
|
result = acs_tpl.get_result(tpl)
|
||||||
|
|
||||||
except CloudStackException as e:
|
|
||||||
module.fail_json(msg='CloudStackException: %s' % str(e))
|
|
||||||
|
|
||||||
module.exit_json(**result)
|
module.exit_json(**result)
|
||||||
|
|
||||||
# import module snippets
|
|
||||||
from ansible.module_utils.basic import *
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -77,7 +77,6 @@ lib/ansible/modules/cloud/cloudstack/cs_portforward.py
|
||||||
lib/ansible/modules/cloud/cloudstack/cs_securitygroup.py
|
lib/ansible/modules/cloud/cloudstack/cs_securitygroup.py
|
||||||
lib/ansible/modules/cloud/cloudstack/cs_securitygroup_rule.py
|
lib/ansible/modules/cloud/cloudstack/cs_securitygroup_rule.py
|
||||||
lib/ansible/modules/cloud/cloudstack/cs_snapshot_policy.py
|
lib/ansible/modules/cloud/cloudstack/cs_snapshot_policy.py
|
||||||
lib/ansible/modules/cloud/cloudstack/cs_template.py
|
|
||||||
lib/ansible/modules/cloud/docker/_docker.py
|
lib/ansible/modules/cloud/docker/_docker.py
|
||||||
lib/ansible/modules/cloud/docker/docker_container.py
|
lib/ansible/modules/cloud/docker/docker_container.py
|
||||||
lib/ansible/modules/cloud/docker/docker_image.py
|
lib/ansible/modules/cloud/docker/docker_image.py
|
||||||
|
|
Loading…
Reference in a new issue