mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
cloudstack: cs_iso: add update support, fixes pep8
This commit is contained in:
parent
0391ac6ece
commit
3dc379c89d
3 changed files with 143 additions and 77 deletions
|
@ -52,33 +52,31 @@ options:
|
||||||
successfully downloaded and installed. Recommended to set it to C(false).
|
successfully downloaded and installed. Recommended to set it to C(false).
|
||||||
required: false
|
required: false
|
||||||
default: false
|
default: false
|
||||||
aliases: []
|
|
||||||
is_public:
|
is_public:
|
||||||
description:
|
description:
|
||||||
- Register the ISO to be publicly available to all users. Only used if C(state) is present.
|
- Register the ISO to be publicly available to all users. Only used if C(state) is present.
|
||||||
required: false
|
required: false
|
||||||
default: false
|
default: null
|
||||||
is_featured:
|
is_featured:
|
||||||
description:
|
description:
|
||||||
- Register the ISO to be featured. Only used if C(state) is present.
|
- Register the ISO to be featured. Only used if C(state) is present.
|
||||||
required: false
|
required: false
|
||||||
default: false
|
default: null
|
||||||
is_dynamically_scalable:
|
is_dynamically_scalable:
|
||||||
description:
|
description:
|
||||||
- Register the ISO having XS/VMWare tools installed inorder to support dynamic scaling of VM cpu/memory. Only used if C(state) is present.
|
- Register the ISO having XS/VMWare tools installed inorder to support dynamic scaling of VM cpu/memory. Only used if C(state) is present.
|
||||||
required: false
|
required: false
|
||||||
default: false
|
default: null
|
||||||
aliases: []
|
|
||||||
checksum:
|
checksum:
|
||||||
description:
|
description:
|
||||||
- The MD5 checksum value of this ISO. If set, we search by checksum instead of name.
|
- The MD5 checksum value of this ISO. If set, we search by checksum instead of name.
|
||||||
required: false
|
required: false
|
||||||
default: false
|
default: null
|
||||||
bootable:
|
bootable:
|
||||||
description:
|
description:
|
||||||
- Register the ISO to be bootable. Only used if C(state) is present.
|
- Register the ISO to be bootable. Only used if C(state) is present.
|
||||||
required: false
|
required: false
|
||||||
default: true
|
default: null
|
||||||
domain:
|
domain:
|
||||||
description:
|
description:
|
||||||
- Domain the ISO is related to.
|
- Domain the ISO is related to.
|
||||||
|
@ -217,8 +215,13 @@ project:
|
||||||
sample: example project
|
sample: example project
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# import cloudstack common
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.cloudstack import *
|
from ansible.module_utils.cloudstack import (
|
||||||
|
AnsibleCloudStack,
|
||||||
|
CloudStackException,
|
||||||
|
cs_argument_spec,
|
||||||
|
cs_required_together
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class AnsibleCloudStackIso(AnsibleCloudStack):
|
class AnsibleCloudStackIso(AnsibleCloudStack):
|
||||||
|
@ -227,60 +230,82 @@ class AnsibleCloudStackIso(AnsibleCloudStack):
|
||||||
super(AnsibleCloudStackIso, self).__init__(module)
|
super(AnsibleCloudStackIso, self).__init__(module)
|
||||||
self.returns = {
|
self.returns = {
|
||||||
'checksum': 'checksum',
|
'checksum': 'checksum',
|
||||||
'status': 'status',
|
'status': 'status',
|
||||||
'isready': 'is_ready',
|
'isready': 'is_ready',
|
||||||
}
|
}
|
||||||
self.iso = None
|
self.iso = None
|
||||||
|
|
||||||
|
def _get_common_args(self):
|
||||||
|
return {
|
||||||
|
'name': self.module.params.get('name'),
|
||||||
|
'displaytext': self.module.params.get('name'),
|
||||||
|
'isdynamicallyscalable': self.module.params.get('is_dynamically_scalable'),
|
||||||
|
'ostypeid': self.get_os_type('id'),
|
||||||
|
'bootable': self.module.params.get('bootable'),
|
||||||
|
}
|
||||||
|
|
||||||
def register_iso(self):
|
def register_iso(self):
|
||||||
|
args = self._get_common_args()
|
||||||
|
args.update({
|
||||||
|
'zoneid': self.get_zone('id'),
|
||||||
|
'domainid': self.get_domain('id'),
|
||||||
|
'account': self.get_account('name'),
|
||||||
|
'projectid': self.get_project('id'),
|
||||||
|
'checksum': self.module.params.get('checksum'),
|
||||||
|
'isfeatured': self.module.params.get('is_featured'),
|
||||||
|
'ispublic': self.module.params.get('is_public'),
|
||||||
|
})
|
||||||
|
if args['bootable'] and not args['ostypeid']:
|
||||||
|
self.module.fail_json(msg="OS type 'os_type' is requried if 'bootable=true'.")
|
||||||
|
|
||||||
|
args['url'] = self.module.params.get('url')
|
||||||
|
if not args['url']:
|
||||||
|
self.module.fail_json(msg="URL is requried.")
|
||||||
|
|
||||||
|
self.result['changed'] = True
|
||||||
|
if not self.module.check_mode:
|
||||||
|
res = self.cs.registerIso(**args)
|
||||||
|
if 'errortext' in res:
|
||||||
|
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||||
|
self.iso = res['iso'][0]
|
||||||
|
return self.iso
|
||||||
|
|
||||||
|
def present_iso(self):
|
||||||
iso = self.get_iso()
|
iso = self.get_iso()
|
||||||
if not iso:
|
if not iso:
|
||||||
|
iso = self.register_iso()
|
||||||
args = {}
|
else:
|
||||||
args['zoneid'] = self.get_zone('id')
|
iso = self.update_iso(iso)
|
||||||
args['domainid'] = self.get_domain('id')
|
|
||||||
args['account'] = self.get_account('name')
|
|
||||||
args['projectid'] = self.get_project('id')
|
|
||||||
args['bootable'] = self.module.params.get('bootable')
|
|
||||||
args['ostypeid'] = self.get_os_type('id')
|
|
||||||
args['name'] = self.module.params.get('name')
|
|
||||||
args['displaytext'] = self.module.params.get('name')
|
|
||||||
args['checksum'] = self.module.params.get('checksum')
|
|
||||||
args['isdynamicallyscalable'] = self.module.params.get('is_dynamically_scalable')
|
|
||||||
args['isfeatured'] = self.module.params.get('is_featured')
|
|
||||||
args['ispublic'] = self.module.params.get('is_public')
|
|
||||||
|
|
||||||
if args['bootable'] and not args['ostypeid']:
|
|
||||||
self.module.fail_json(msg="OS type 'os_type' is required if 'bootable=true'.")
|
|
||||||
|
|
||||||
args['url'] = self.module.params.get('url')
|
|
||||||
if not args['url']:
|
|
||||||
self.module.fail_json(msg="URL is required.")
|
|
||||||
|
|
||||||
self.result['changed'] = True
|
|
||||||
if not self.module.check_mode:
|
|
||||||
res = self.cs.registerIso(**args)
|
|
||||||
if 'errortext' in res:
|
|
||||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
|
||||||
iso = res['iso'][0]
|
|
||||||
|
|
||||||
if iso:
|
if iso:
|
||||||
iso = self.ensure_tags(resource=iso, resource_type='ISO')
|
iso = self.ensure_tags(resource=iso, resource_type='ISO')
|
||||||
self.iso=iso
|
self.iso = iso
|
||||||
|
|
||||||
return iso
|
return iso
|
||||||
|
|
||||||
|
def update_iso(self, iso):
|
||||||
|
args = self._get_common_args()
|
||||||
|
args.update({
|
||||||
|
'id': iso['id'],
|
||||||
|
})
|
||||||
|
if self.has_changed(args, iso):
|
||||||
|
self.result['changed'] = True
|
||||||
|
if not self.module.check_mode:
|
||||||
|
res = self.cs.updateIso(**args)
|
||||||
|
if 'errortext' in res:
|
||||||
|
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||||
|
self.iso = res['iso']
|
||||||
|
return self.iso
|
||||||
|
|
||||||
def get_iso(self):
|
def get_iso(self):
|
||||||
if not self.iso:
|
if not self.iso:
|
||||||
|
args = {
|
||||||
args = {}
|
'isready': self.module.params.get('is_ready'),
|
||||||
args['isready'] = self.module.params.get('is_ready')
|
'isofilter': self.module.params.get('iso_filter'),
|
||||||
args['isofilter'] = self.module.params.get('iso_filter')
|
'domainid': self.get_domain('id'),
|
||||||
args['domainid'] = self.get_domain('id')
|
'account': self.get_account('name'),
|
||||||
args['account'] = self.get_account('name')
|
'projectid': self.get_project('id'),
|
||||||
args['projectid'] = self.get_project('id')
|
'zoneid': self.get_zone('id'),
|
||||||
args['zoneid'] = self.get_zone('id')
|
}
|
||||||
|
|
||||||
# if checksum is set, we only look on that.
|
# if checksum is set, we only look on that.
|
||||||
checksum = self.module.params.get('checksum')
|
checksum = self.module.params.get('checksum')
|
||||||
|
@ -298,16 +323,16 @@ class AnsibleCloudStackIso(AnsibleCloudStack):
|
||||||
break
|
break
|
||||||
return self.iso
|
return self.iso
|
||||||
|
|
||||||
|
def absent_iso(self):
|
||||||
def remove_iso(self):
|
|
||||||
iso = self.get_iso()
|
iso = self.get_iso()
|
||||||
if iso:
|
if iso:
|
||||||
self.result['changed'] = True
|
self.result['changed'] = True
|
||||||
|
|
||||||
args = {}
|
args = {
|
||||||
args['id'] = iso['id']
|
'id': iso['id'],
|
||||||
args['projectid'] = self.get_project('id')
|
'projectid': self.get_project('id'),
|
||||||
args['zoneid'] = self.get_zone('id')
|
'zoneid': self.get_zone('id'),
|
||||||
|
}
|
||||||
|
|
||||||
if not self.module.check_mode:
|
if not self.module.check_mode:
|
||||||
res = self.cs.deleteIso(**args)
|
res = self.cs.deleteIso(**args)
|
||||||
|
@ -319,26 +344,25 @@ class AnsibleCloudStackIso(AnsibleCloudStack):
|
||||||
return iso
|
return iso
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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),
|
||||||
url = dict(default=None),
|
url=dict(),
|
||||||
os_type = dict(default=None),
|
os_type=dict(),
|
||||||
zone = dict(default=None),
|
zone=dict(),
|
||||||
iso_filter = dict(default='self', choices=[ 'featured', 'self', 'selfexecutable','sharedexecutable','executable', 'community' ]),
|
iso_filter=dict(default='self', choices=['featured', 'self', 'selfexecutable', 'sharedexecutable', 'executable', 'community']),
|
||||||
domain = dict(default=None),
|
domain=dict(),
|
||||||
account = dict(default=None),
|
account=dict(),
|
||||||
project = dict(default=None),
|
project=dict(),
|
||||||
checksum = dict(default=None),
|
checksum=dict(),
|
||||||
is_ready = dict(type='bool', default=False),
|
is_ready=dict(type='bool', default=False),
|
||||||
bootable = dict(type='bool', default=True),
|
bootable=dict(type='bool'),
|
||||||
is_featured = dict(type='bool', default=False),
|
is_featured=dict(type='bool'),
|
||||||
is_dynamically_scalable = dict(type='bool', default=False),
|
is_dynamically_scalable=dict(type='bool'),
|
||||||
state = dict(choices=['present', 'absent'], default='present'),
|
state=dict(choices=['present', 'absent'], default='present'),
|
||||||
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(
|
||||||
|
@ -352,9 +376,9 @@ def main():
|
||||||
|
|
||||||
state = module.params.get('state')
|
state = module.params.get('state')
|
||||||
if state in ['absent']:
|
if state in ['absent']:
|
||||||
iso = acs_iso.remove_iso()
|
iso = acs_iso.absent_iso()
|
||||||
else:
|
else:
|
||||||
iso = acs_iso.register_iso()
|
iso = acs_iso.present_iso()
|
||||||
|
|
||||||
result = acs_iso.get_result(iso)
|
result = acs_iso.get_result(iso)
|
||||||
|
|
||||||
|
@ -363,7 +387,6 @@ def main():
|
||||||
|
|
||||||
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()
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
that:
|
that:
|
||||||
- iso|changed
|
- iso|changed
|
||||||
- iso.name == "{{ cs_resource_prefix }}-iso"
|
- iso.name == "{{ cs_resource_prefix }}-iso"
|
||||||
|
- iso.display_text == "{{ cs_resource_prefix }}-iso"
|
||||||
|
|
||||||
- name: test download iso idempotence
|
- name: test download iso idempotence
|
||||||
cs_iso:
|
cs_iso:
|
||||||
|
@ -44,6 +45,47 @@
|
||||||
that:
|
that:
|
||||||
- not iso|changed
|
- not iso|changed
|
||||||
- iso.name == "{{ cs_resource_prefix }}-iso"
|
- iso.name == "{{ cs_resource_prefix }}-iso"
|
||||||
|
- iso.display_text == "{{ cs_resource_prefix }}-iso"
|
||||||
|
|
||||||
|
- name: test update iso in check mdoe
|
||||||
|
cs_iso:
|
||||||
|
name: "{{ cs_resource_prefix }}-iso"
|
||||||
|
url: http://mirror.switch.ch/ftp/mirror/debian-cd/current/amd64/iso-cd/debian-7.7.0-amd64-netinst.iso
|
||||||
|
os_type: CentOS 7
|
||||||
|
register: iso
|
||||||
|
check_mode: true
|
||||||
|
- name: verify test update iso in check mode
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- iso|changed
|
||||||
|
- iso.name == "{{ cs_resource_prefix }}-iso"
|
||||||
|
- iso.display_text == "{{ cs_resource_prefix }}-iso"
|
||||||
|
|
||||||
|
- name: test update iso
|
||||||
|
cs_iso:
|
||||||
|
name: "{{ cs_resource_prefix }}-iso"
|
||||||
|
url: http://mirror.switch.ch/ftp/mirror/debian-cd/current/amd64/iso-cd/debian-7.7.0-amd64-netinst.iso
|
||||||
|
os_type: CentOS 7
|
||||||
|
register: iso
|
||||||
|
- name: verify test update iso
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- iso|changed
|
||||||
|
- iso.name == "{{ cs_resource_prefix }}-iso"
|
||||||
|
- iso.display_text == "{{ cs_resource_prefix }}-iso"
|
||||||
|
|
||||||
|
- name: test update iso idempotence
|
||||||
|
cs_iso:
|
||||||
|
name: "{{ cs_resource_prefix }}-iso"
|
||||||
|
url: http://mirror.switch.ch/ftp/mirror/debian-cd/current/amd64/iso-cd/debian-7.7.0-amd64-netinst.iso
|
||||||
|
os_type: CentOS 7
|
||||||
|
register: iso
|
||||||
|
- name: verify test update iso idempotence
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- not iso|changed
|
||||||
|
- iso.name == "{{ cs_resource_prefix }}-iso"
|
||||||
|
- iso.display_text == "{{ cs_resource_prefix }}-iso"
|
||||||
|
|
||||||
- name: test remove iso in check mode
|
- name: test remove iso in check mode
|
||||||
cs_iso:
|
cs_iso:
|
||||||
|
@ -56,6 +98,7 @@
|
||||||
that:
|
that:
|
||||||
- iso|changed
|
- iso|changed
|
||||||
- iso.name == "{{ cs_resource_prefix }}-iso"
|
- iso.name == "{{ cs_resource_prefix }}-iso"
|
||||||
|
- iso.display_text == "{{ cs_resource_prefix }}-iso"
|
||||||
|
|
||||||
- name: test remove iso
|
- name: test remove iso
|
||||||
cs_iso:
|
cs_iso:
|
||||||
|
@ -67,6 +110,7 @@
|
||||||
that:
|
that:
|
||||||
- iso|changed
|
- iso|changed
|
||||||
- iso.name == "{{ cs_resource_prefix }}-iso"
|
- iso.name == "{{ cs_resource_prefix }}-iso"
|
||||||
|
- iso.display_text == "{{ cs_resource_prefix }}-iso"
|
||||||
|
|
||||||
- name: test remove iso idempotence
|
- name: test remove iso idempotence
|
||||||
cs_iso:
|
cs_iso:
|
||||||
|
|
|
@ -86,7 +86,6 @@ lib/ansible/modules/cloud/cloudscale/cloudscale_server.py
|
||||||
lib/ansible/modules/cloud/cloudstack/cs_configuration.py
|
lib/ansible/modules/cloud/cloudstack/cs_configuration.py
|
||||||
lib/ansible/modules/cloud/cloudstack/cs_instance.py
|
lib/ansible/modules/cloud/cloudstack/cs_instance.py
|
||||||
lib/ansible/modules/cloud/cloudstack/cs_instance_facts.py
|
lib/ansible/modules/cloud/cloudstack/cs_instance_facts.py
|
||||||
lib/ansible/modules/cloud/cloudstack/cs_iso.py
|
|
||||||
lib/ansible/modules/cloud/cloudstack/cs_nic.py
|
lib/ansible/modules/cloud/cloudstack/cs_nic.py
|
||||||
lib/ansible/modules/cloud/cloudstack/cs_portforward.py
|
lib/ansible/modules/cloud/cloudstack/cs_portforward.py
|
||||||
lib/ansible/modules/cloud/cloudstack/cs_router.py
|
lib/ansible/modules/cloud/cloudstack/cs_router.py
|
||||||
|
|
Loading…
Reference in a new issue