From 2d78c23dc0dab96dd6a5edcb7afbe9730e072d89 Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Mon, 11 Apr 2016 20:01:27 +0200 Subject: [PATCH 1/3] cloudstack: cs_template: fix cross_zones template removal --- cloud/cloudstack/cs_template.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cloud/cloudstack/cs_template.py b/cloud/cloudstack/cs_template.py index 8690a6e1756..c61b0a990cc 100644 --- a/cloud/cloudstack/cs_template.py +++ b/cloud/cloudstack/cs_template.py @@ -89,8 +89,8 @@ options: default: false cross_zones: description: - - Whether the template should be syned across zones. - - Only used if C(state) is present. + - Whether the template should be syned or removed across zones. + - Only used if C(state) is present or absent. required: false default: false project: @@ -220,6 +220,7 @@ EXAMPLES = ''' - local_action: module: cs_template name: systemvm-4.2 + cross_zones: yes state: absent ''' @@ -560,7 +561,9 @@ class AnsibleCloudStackTemplate(AnsibleCloudStack): args = {} args['id'] = template['id'] - args['zoneid'] = self.get_zone(key='id') + + if not self.module.params.get('cross_zones'): + args['zoneid'] = self.get_zone(key='id') if not self.module.check_mode: res = self.cs.deleteTemplate(**args) @@ -620,6 +623,7 @@ def main(): required_together=required_together, mutually_exclusive = ( ['url', 'vm'], + ['zone', 'cross_zones'], ), supports_check_mode=True ) From 0b9c8213adc758243f03c6e90c389530d288563b Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Mon, 11 Apr 2016 20:01:36 +0200 Subject: [PATCH 2/3] cloudstack: fix doc, display_text not required --- cloud/cloudstack/cs_template.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud/cloudstack/cs_template.py b/cloud/cloudstack/cs_template.py index c61b0a990cc..537d83e3c2e 100644 --- a/cloud/cloudstack/cs_template.py +++ b/cloud/cloudstack/cs_template.py @@ -168,7 +168,7 @@ options: display_text: description: - Display text of the template. - required: true + required: false default: null state: description: From 1d0df46475e6194eedaa52622e778e0fee5c7378 Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Mon, 11 Apr 2016 20:02:03 +0200 Subject: [PATCH 3/3] cloudstack: cs_template: fix state=extracted * url arg is optional but we enforced it * url is in a required together, but args only relevant while registering --- cloud/cloudstack/cs_template.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/cloud/cloudstack/cs_template.py b/cloud/cloudstack/cs_template.py index 537d83e3c2e..e53c8e286e4 100644 --- a/cloud/cloudstack/cs_template.py +++ b/cloud/cloudstack/cs_template.py @@ -470,6 +470,12 @@ class AnsibleCloudStackTemplate(AnsibleCloudStack): def register_template(self): + required_params = [ + 'format', + 'url', + 'hypervisor', + ] + self.module.fail_on_missing_params(required_params=required_params) template = self.get_template() if not template: self.result['changed'] = True @@ -537,9 +543,6 @@ class AnsibleCloudStackTemplate(AnsibleCloudStack): args['mode'] = self.module.params.get('mode') args['zoneid'] = self.get_zone(key='id') - if not args['url']: - self.module.fail_json(msg="Missing required arguments: url") - self.result['changed'] = True if not self.module.check_mode: @@ -613,14 +616,9 @@ def main(): poll_async = dict(type='bool', default=True), )) - required_together = cs_required_together() - required_together.extend([ - ['format', 'url', 'hypervisor'], - ]) - module = AnsibleModule( argument_spec=argument_spec, - required_together=required_together, + required_together=cs_required_together(), mutually_exclusive = ( ['url', 'vm'], ['zone', 'cross_zones'],