cloudstack: cs_iso: add cross_zone param
This commit is contained in:
parent
31d530d6af
commit
64643c4e7d
2 changed files with 67 additions and 4 deletions
|
@ -101,9 +101,17 @@ options:
|
||||||
default: null
|
default: null
|
||||||
zone:
|
zone:
|
||||||
description:
|
description:
|
||||||
- Name of the zone you wish the ISO to be registered or deleted from. If not specified, first zone found will be used.
|
- Name of the zone you wish the ISO to be registered or deleted from.
|
||||||
|
- If not specified, first zone found will be used.
|
||||||
required: false
|
required: false
|
||||||
default: null
|
default: null
|
||||||
|
cross_zones:
|
||||||
|
description:
|
||||||
|
- Whether the ISO should be synced or removed across zones.
|
||||||
|
- Mutually exclusive with C(zone).
|
||||||
|
required: false
|
||||||
|
default: false
|
||||||
|
version_added: "2.4"
|
||||||
iso_filter:
|
iso_filter:
|
||||||
description:
|
description:
|
||||||
- Name of the filter used to search for the ISO.
|
- Name of the filter used to search for the ISO.
|
||||||
|
@ -205,6 +213,12 @@ created:
|
||||||
returned: success
|
returned: success
|
||||||
type: string
|
type: string
|
||||||
sample: 2015-03-29T14:57:06+0200
|
sample: 2015-03-29T14:57:06+0200
|
||||||
|
cross_zones:
|
||||||
|
description: true if the ISO is managed across all zones, false otherwise.
|
||||||
|
returned: success
|
||||||
|
type: boolean
|
||||||
|
sample: false
|
||||||
|
version_added: "2.4"
|
||||||
domain:
|
domain:
|
||||||
description: Domain the ISO is related to.
|
description: Domain the ISO is related to.
|
||||||
returned: success
|
returned: success
|
||||||
|
@ -239,6 +253,8 @@ class AnsibleCloudStackIso(AnsibleCloudStack):
|
||||||
'checksum': 'checksum',
|
'checksum': 'checksum',
|
||||||
'status': 'status',
|
'status': 'status',
|
||||||
'isready': 'is_ready',
|
'isready': 'is_ready',
|
||||||
|
'crossZones': 'cross_zones',
|
||||||
|
|
||||||
}
|
}
|
||||||
self.iso = None
|
self.iso = None
|
||||||
|
|
||||||
|
@ -254,7 +270,6 @@ class AnsibleCloudStackIso(AnsibleCloudStack):
|
||||||
def register_iso(self):
|
def register_iso(self):
|
||||||
args = self._get_common_args()
|
args = self._get_common_args()
|
||||||
args.update({
|
args.update({
|
||||||
'zoneid': self.get_zone('id'),
|
|
||||||
'domainid': self.get_domain('id'),
|
'domainid': self.get_domain('id'),
|
||||||
'account': self.get_account('name'),
|
'account': self.get_account('name'),
|
||||||
'projectid': self.get_project('id'),
|
'projectid': self.get_project('id'),
|
||||||
|
@ -262,6 +277,12 @@ class AnsibleCloudStackIso(AnsibleCloudStack):
|
||||||
'isfeatured': self.module.params.get('is_featured'),
|
'isfeatured': self.module.params.get('is_featured'),
|
||||||
'ispublic': self.module.params.get('is_public'),
|
'ispublic': self.module.params.get('is_public'),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if not self.module.params.get('cross_zones'):
|
||||||
|
args['zoneid'] = self.get_zone(key='id')
|
||||||
|
else:
|
||||||
|
args['zoneid'] = -1
|
||||||
|
|
||||||
if args['bootable'] and not args['ostypeid']:
|
if args['bootable'] and not args['ostypeid']:
|
||||||
self.module.fail_json(msg="OS type 'os_type' is requried if 'bootable=true'.")
|
self.module.fail_json(msg="OS type 'os_type' is requried if 'bootable=true'.")
|
||||||
|
|
||||||
|
@ -296,6 +317,14 @@ class AnsibleCloudStackIso(AnsibleCloudStack):
|
||||||
})
|
})
|
||||||
if self.has_changed(args, iso):
|
if self.has_changed(args, iso):
|
||||||
self.result['changed'] = True
|
self.result['changed'] = True
|
||||||
|
|
||||||
|
if not self.module.params.get('cross_zones'):
|
||||||
|
args['zoneid'] = self.get_zone(key='id')
|
||||||
|
else:
|
||||||
|
# Workaround API does not return cross_zones=true
|
||||||
|
self.result['cross_zones'] = True
|
||||||
|
args['zoneid'] = -1
|
||||||
|
|
||||||
if not self.module.check_mode:
|
if not self.module.check_mode:
|
||||||
res = self.cs.updateIso(**args)
|
res = self.cs.updateIso(**args)
|
||||||
if 'errortext' in res:
|
if 'errortext' in res:
|
||||||
|
@ -311,9 +340,11 @@ class AnsibleCloudStackIso(AnsibleCloudStack):
|
||||||
'domainid': self.get_domain('id'),
|
'domainid': self.get_domain('id'),
|
||||||
'account': self.get_account('name'),
|
'account': self.get_account('name'),
|
||||||
'projectid': self.get_project('id'),
|
'projectid': self.get_project('id'),
|
||||||
'zoneid': self.get_zone('id'),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if not self.module.params.get('cross_zones'):
|
||||||
|
args['zoneid'] = self.get_zone(key='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')
|
||||||
if not checksum:
|
if not checksum:
|
||||||
|
@ -338,9 +369,11 @@ class AnsibleCloudStackIso(AnsibleCloudStack):
|
||||||
args = {
|
args = {
|
||||||
'id': iso['id'],
|
'id': iso['id'],
|
||||||
'projectid': self.get_project('id'),
|
'projectid': self.get_project('id'),
|
||||||
'zoneid': self.get_zone('id'),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if not self.module.params.get('cross_zones'):
|
||||||
|
args['zoneid'] = self.get_zone(key='id')
|
||||||
|
|
||||||
if not self.module.check_mode:
|
if not self.module.check_mode:
|
||||||
res = self.cs.deleteIso(**args)
|
res = self.cs.deleteIso(**args)
|
||||||
if 'errortext' in res:
|
if 'errortext' in res:
|
||||||
|
@ -350,6 +383,15 @@ class AnsibleCloudStackIso(AnsibleCloudStack):
|
||||||
self.poll_job(res, 'iso')
|
self.poll_job(res, 'iso')
|
||||||
return iso
|
return iso
|
||||||
|
|
||||||
|
def get_result(self, iso):
|
||||||
|
super(AnsibleCloudStackIso, self).get_result(iso)
|
||||||
|
# Workaround API does not return cross_zones=true
|
||||||
|
if self.module.params.get('cross_zones'):
|
||||||
|
self.result['cross_zones'] = True
|
||||||
|
if 'zone' in self.result:
|
||||||
|
del self.result['zone']
|
||||||
|
return self.result
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
argument_spec = cs_argument_spec()
|
argument_spec = cs_argument_spec()
|
||||||
|
@ -359,6 +401,7 @@ def main():
|
||||||
url=dict(),
|
url=dict(),
|
||||||
os_type=dict(),
|
os_type=dict(),
|
||||||
zone=dict(),
|
zone=dict(),
|
||||||
|
cross_zones=dict(type='bool', default=False),
|
||||||
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(),
|
domain=dict(),
|
||||||
account=dict(),
|
account=dict(),
|
||||||
|
@ -376,6 +419,9 @@ def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec=argument_spec,
|
argument_spec=argument_spec,
|
||||||
required_together=cs_required_together(),
|
required_together=cs_required_together(),
|
||||||
|
mutually_exclusive=(
|
||||||
|
['zone', 'cross_zones'],
|
||||||
|
),
|
||||||
supports_check_mode=True
|
supports_check_mode=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
name: "{{ cs_resource_prefix }}-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
|
url: http://mirror.switch.ch/ftp/mirror/debian-cd/current/amd64/iso-cd/debian-7.7.0-amd64-netinst.iso
|
||||||
os_type: Debian GNU/Linux 7(64-bit)
|
os_type: Debian GNU/Linux 7(64-bit)
|
||||||
|
cross_zones: true
|
||||||
register: iso
|
register: iso
|
||||||
check_mode: true
|
check_mode: true
|
||||||
- name: verify test download iso in check mode
|
- name: verify test download iso in check mode
|
||||||
|
@ -26,6 +27,7 @@
|
||||||
name: "{{ cs_resource_prefix }}-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
|
url: http://mirror.switch.ch/ftp/mirror/debian-cd/current/amd64/iso-cd/debian-7.7.0-amd64-netinst.iso
|
||||||
os_type: Debian GNU/Linux 7(64-bit)
|
os_type: Debian GNU/Linux 7(64-bit)
|
||||||
|
cross_zones: true
|
||||||
register: iso
|
register: iso
|
||||||
- name: verify test download iso
|
- name: verify test download iso
|
||||||
assert:
|
assert:
|
||||||
|
@ -33,12 +35,14 @@
|
||||||
- iso|changed
|
- iso|changed
|
||||||
- iso.name == "{{ cs_resource_prefix }}-iso"
|
- iso.name == "{{ cs_resource_prefix }}-iso"
|
||||||
- iso.display_text == "{{ cs_resource_prefix }}-iso"
|
- iso.display_text == "{{ cs_resource_prefix }}-iso"
|
||||||
|
- iso.cross_zones == true
|
||||||
|
|
||||||
- name: test download iso idempotence
|
- name: test download iso idempotence
|
||||||
cs_iso:
|
cs_iso:
|
||||||
name: "{{ cs_resource_prefix }}-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
|
url: http://mirror.switch.ch/ftp/mirror/debian-cd/current/amd64/iso-cd/debian-7.7.0-amd64-netinst.iso
|
||||||
os_type: Debian GNU/Linux 7(64-bit)
|
os_type: Debian GNU/Linux 7(64-bit)
|
||||||
|
cross_zones: true
|
||||||
register: iso
|
register: iso
|
||||||
- name: verify test download iso idempotence
|
- name: verify test download iso idempotence
|
||||||
assert:
|
assert:
|
||||||
|
@ -46,6 +50,7 @@
|
||||||
- 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"
|
- iso.display_text == "{{ cs_resource_prefix }}-iso"
|
||||||
|
- iso.cross_zones == true
|
||||||
|
|
||||||
- name: test update iso in check mdoe
|
- name: test update iso in check mdoe
|
||||||
cs_iso:
|
cs_iso:
|
||||||
|
@ -53,6 +58,7 @@
|
||||||
display_text: "{{ cs_resource_prefix }}-iso display_text"
|
display_text: "{{ cs_resource_prefix }}-iso display_text"
|
||||||
url: http://mirror.switch.ch/ftp/mirror/debian-cd/current/amd64/iso-cd/debian-7.7.0-amd64-netinst.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
|
os_type: CentOS 7
|
||||||
|
cross_zones: true
|
||||||
register: iso
|
register: iso
|
||||||
check_mode: true
|
check_mode: true
|
||||||
- name: verify test update iso in check mode
|
- name: verify test update iso in check mode
|
||||||
|
@ -61,6 +67,7 @@
|
||||||
- iso|changed
|
- iso|changed
|
||||||
- iso.name == "{{ cs_resource_prefix }}-iso"
|
- iso.name == "{{ cs_resource_prefix }}-iso"
|
||||||
- iso.display_text == "{{ cs_resource_prefix }}-iso"
|
- iso.display_text == "{{ cs_resource_prefix }}-iso"
|
||||||
|
- iso.cross_zones == true
|
||||||
|
|
||||||
- name: test update iso
|
- name: test update iso
|
||||||
cs_iso:
|
cs_iso:
|
||||||
|
@ -68,6 +75,7 @@
|
||||||
display_text: "{{ cs_resource_prefix }}-iso display_text"
|
display_text: "{{ cs_resource_prefix }}-iso display_text"
|
||||||
url: http://mirror.switch.ch/ftp/mirror/debian-cd/current/amd64/iso-cd/debian-7.7.0-amd64-netinst.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
|
os_type: CentOS 7
|
||||||
|
cross_zones: true
|
||||||
register: iso
|
register: iso
|
||||||
- name: verify test update iso
|
- name: verify test update iso
|
||||||
assert:
|
assert:
|
||||||
|
@ -75,12 +83,15 @@
|
||||||
- iso|changed
|
- iso|changed
|
||||||
- iso.name == "{{ cs_resource_prefix }}-iso"
|
- iso.name == "{{ cs_resource_prefix }}-iso"
|
||||||
- iso.display_text == "{{ cs_resource_prefix }}-iso display_text"
|
- iso.display_text == "{{ cs_resource_prefix }}-iso display_text"
|
||||||
|
- iso.cross_zones == true
|
||||||
|
|
||||||
- name: test update iso idempotence
|
- name: test update iso idempotence
|
||||||
cs_iso:
|
cs_iso:
|
||||||
name: "{{ cs_resource_prefix }}-iso"
|
name: "{{ cs_resource_prefix }}-iso"
|
||||||
|
display_text: "{{ cs_resource_prefix }}-iso display_text"
|
||||||
url: http://mirror.switch.ch/ftp/mirror/debian-cd/current/amd64/iso-cd/debian-7.7.0-amd64-netinst.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
|
os_type: CentOS 7
|
||||||
|
cross_zones: true
|
||||||
register: iso
|
register: iso
|
||||||
- name: verify test update iso idempotence
|
- name: verify test update iso idempotence
|
||||||
assert:
|
assert:
|
||||||
|
@ -88,11 +99,13 @@
|
||||||
- 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 display_text"
|
- iso.display_text == "{{ cs_resource_prefix }}-iso display_text"
|
||||||
|
- iso.cross_zones == true
|
||||||
|
|
||||||
- name: test remove iso in check mode
|
- name: test remove iso in check mode
|
||||||
cs_iso:
|
cs_iso:
|
||||||
name: "{{ cs_resource_prefix }}-iso"
|
name: "{{ cs_resource_prefix }}-iso"
|
||||||
state: absent
|
state: absent
|
||||||
|
cross_zones: true
|
||||||
register: iso
|
register: iso
|
||||||
check_mode: true
|
check_mode: true
|
||||||
- name: verify test remove iso in check mode
|
- name: verify test remove iso in check mode
|
||||||
|
@ -101,11 +114,13 @@
|
||||||
- iso|changed
|
- iso|changed
|
||||||
- iso.name == "{{ cs_resource_prefix }}-iso"
|
- iso.name == "{{ cs_resource_prefix }}-iso"
|
||||||
- iso.display_text == "{{ cs_resource_prefix }}-iso display_text"
|
- iso.display_text == "{{ cs_resource_prefix }}-iso display_text"
|
||||||
|
- iso.cross_zones == true
|
||||||
|
|
||||||
- name: test remove iso
|
- name: test remove iso
|
||||||
cs_iso:
|
cs_iso:
|
||||||
name: "{{ cs_resource_prefix }}-iso"
|
name: "{{ cs_resource_prefix }}-iso"
|
||||||
state: absent
|
state: absent
|
||||||
|
cross_zones: true
|
||||||
register: iso
|
register: iso
|
||||||
- name: verify test remove iso
|
- name: verify test remove iso
|
||||||
assert:
|
assert:
|
||||||
|
@ -113,11 +128,13 @@
|
||||||
- iso|changed
|
- iso|changed
|
||||||
- iso.name == "{{ cs_resource_prefix }}-iso"
|
- iso.name == "{{ cs_resource_prefix }}-iso"
|
||||||
- iso.display_text == "{{ cs_resource_prefix }}-iso display_text"
|
- iso.display_text == "{{ cs_resource_prefix }}-iso display_text"
|
||||||
|
- iso.cross_zones == true
|
||||||
|
|
||||||
- name: test remove iso idempotence
|
- name: test remove iso idempotence
|
||||||
cs_iso:
|
cs_iso:
|
||||||
name: "{{ cs_resource_prefix }}-iso"
|
name: "{{ cs_resource_prefix }}-iso"
|
||||||
state: absent
|
state: absent
|
||||||
|
cross_zones: true
|
||||||
register: iso
|
register: iso
|
||||||
- name: verify test remove iso idempotence
|
- name: verify test remove iso idempotence
|
||||||
assert:
|
assert:
|
||||||
|
|
Loading…
Reference in a new issue