From e4206d8ef58e3e68e50a52a654a51925efc20748 Mon Sep 17 00:00:00 2001 From: AlexanderStock Date: Fri, 31 Mar 2017 18:39:30 +0200 Subject: [PATCH] Added Tag functionality to Volume,Template,FWRule,PF Rule,ISO,Snapshot (#23141) * Added Tag functionality to Volume,Template,FWRule,PF Rule,ISO,Snapshot * Update cs_firewall.py Fixed whitespace * Added doc for Cloudstack Tags in Volume,Template,FWRule,PF Rule,ISO,Snapshot --- .../modules/cloud/cloudstack/cs_firewall.py | 14 ++++++++++++++ lib/ansible/modules/cloud/cloudstack/cs_iso.py | 14 ++++++++++++++ .../modules/cloud/cloudstack/cs_portforward.py | 14 ++++++++++++++ .../modules/cloud/cloudstack/cs_template.py | 12 ++++++++++++ .../modules/cloud/cloudstack/cs_vmsnapshot.py | 12 ++++++++++++ lib/ansible/modules/cloud/cloudstack/cs_volume.py | 13 +++++++++++++ 6 files changed, 79 insertions(+) diff --git a/lib/ansible/modules/cloud/cloudstack/cs_firewall.py b/lib/ansible/modules/cloud/cloudstack/cs_firewall.py index 61c1acdd00..721ae32793 100644 --- a/lib/ansible/modules/cloud/cloudstack/cs_firewall.py +++ b/lib/ansible/modules/cloud/cloudstack/cs_firewall.py @@ -115,6 +115,14 @@ options: - Poll async jobs until job has finished. required: false default: true + tags: + description: + - 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: [])." + required: false + default: null + aliases: [ 'tag' ] + version_added: "2.4" extends_documentation_fragment: cloudstack ''' @@ -345,6 +353,11 @@ class AnsibleCloudStackFirewall(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if poll_async: firewall_rule = self.poll_job(res, 'firewallrule') + + if firewall_rule: + firewall_rule = self.ensure_tags(resource=firewall_rule, resource_type='Firewallrule') + self.firewall_rule = firewall_rule + return firewall_rule def remove_firewall_rule(self): @@ -398,6 +411,7 @@ def main(): account=dict(), project=dict(), poll_async=dict(type='bool', default=True), + tags=dict(type='list', aliases=['tag'], default=None), )) required_together = cs_required_together() diff --git a/lib/ansible/modules/cloud/cloudstack/cs_iso.py b/lib/ansible/modules/cloud/cloudstack/cs_iso.py index 1b88491e20..3f730fe0e5 100644 --- a/lib/ansible/modules/cloud/cloudstack/cs_iso.py +++ b/lib/ansible/modules/cloud/cloudstack/cs_iso.py @@ -117,6 +117,14 @@ options: required: false default: true version_added: "2.3" + tags: + description: + - 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: [])." + required: false + default: null + aliases: [ 'tag' ] + version_added: "2.4" extends_documentation_fragment: cloudstack ''' @@ -255,6 +263,11 @@ class AnsibleCloudStackIso(AnsibleCloudStack): if 'errortext' in res: self.module.fail_json(msg="Failed: '%s'" % res['errortext']) iso = res['iso'][0] + + if iso: + iso = self.ensure_tags(resource=iso, resource_type='ISO') + self.iso=iso + return iso @@ -325,6 +338,7 @@ def main(): is_dynamically_scalable = dict(type='bool', default=False), state = dict(choices=['present', 'absent'], default='present'), poll_async = dict(type='bool', default=True), + tags=dict(type='list', aliases=['tag'], default=None), )) module = AnsibleModule( diff --git a/lib/ansible/modules/cloud/cloudstack/cs_portforward.py b/lib/ansible/modules/cloud/cloudstack/cs_portforward.py index 5354194bcc..8685498ebb 100644 --- a/lib/ansible/modules/cloud/cloudstack/cs_portforward.py +++ b/lib/ansible/modules/cloud/cloudstack/cs_portforward.py @@ -123,6 +123,14 @@ options: - Poll async jobs until job has finished. required: false default: true + tags: + description: + - 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: [])." + required: false + default: null + aliases: [ 'tag' ] + version_added: "2.4" extends_documentation_fragment: cloudstack ''' @@ -288,6 +296,11 @@ class AnsibleCloudStackPortforwarding(AnsibleCloudStack): portforwarding_rule = self.update_portforwarding_rule(portforwarding_rule) else: portforwarding_rule = self.create_portforwarding_rule() + + if portforwarding_rule: + portforwarding_rule = self.ensure_tags(resource=portforwarding_rule, resource_type='PortForwardingRule') + self.portforwarding_rule=portforwarding_rule + return portforwarding_rule @@ -395,6 +408,7 @@ def main(): account = dict(default=None), project = dict(default=None), poll_async = dict(type='bool', default=True), + tags=dict(type='list', aliases=['tag'], default=None), )) module = AnsibleModule( diff --git a/lib/ansible/modules/cloud/cloudstack/cs_template.py b/lib/ansible/modules/cloud/cloudstack/cs_template.py index 98fc0abc97..cfe7c61b27 100644 --- a/lib/ansible/modules/cloud/cloudstack/cs_template.py +++ b/lib/ansible/modules/cloud/cloudstack/cs_template.py @@ -203,6 +203,14 @@ options: - Poll async jobs until job has finished. required: false default: true + tags: + description: + - 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: [])." + required: false + default: null + aliases: [ 'tag' ] + version_added: "2.4" extends_documentation_fragment: cloudstack ''' @@ -482,6 +490,9 @@ class AnsibleCloudStackTemplate(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if poll_async: template = self.poll_job(template, 'template') + if template: + template = self.ensure_tags(resource=template, resource_type='Template') + return template @@ -630,6 +641,7 @@ def main(): account = dict(default=None), project = dict(default=None), poll_async = dict(type='bool', default=True), + tags=dict(type='list', aliases=['tag'], default=None), )) module = AnsibleModule( diff --git a/lib/ansible/modules/cloud/cloudstack/cs_vmsnapshot.py b/lib/ansible/modules/cloud/cloudstack/cs_vmsnapshot.py index 2bcc5f6940..d2893d70d5 100644 --- a/lib/ansible/modules/cloud/cloudstack/cs_vmsnapshot.py +++ b/lib/ansible/modules/cloud/cloudstack/cs_vmsnapshot.py @@ -82,6 +82,14 @@ options: - Poll async jobs until job has finished. required: false default: true + tags: + description: + - 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: [])." + required: false + default: null + aliases: [ 'tag' ] + version_added: "2.4" extends_documentation_fragment: cloudstack ''' @@ -216,6 +224,9 @@ class AnsibleCloudStackVmSnapshot(AnsibleCloudStack): if res and poll_async: snapshot = self.poll_job(res, 'vmsnapshot') + if snapshot: + snapshot = self.ensure_tags(resource=snapshot, resource_type='Snapshot') + return snapshot @@ -268,6 +279,7 @@ def main(): account = dict(default=None), project = dict(default=None), poll_async = dict(type='bool', default=True), + tags=dict(type='list', aliases=['tag'], default=None), )) required_together = cs_required_together() diff --git a/lib/ansible/modules/cloud/cloudstack/cs_volume.py b/lib/ansible/modules/cloud/cloudstack/cs_volume.py index fa781c299c..15de0e7b70 100644 --- a/lib/ansible/modules/cloud/cloudstack/cs_volume.py +++ b/lib/ansible/modules/cloud/cloudstack/cs_volume.py @@ -127,6 +127,14 @@ options: - Poll async jobs until job has finished. required: false default: true + tags: + description: + - 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: [])." + required: false + default: null + aliases: [ 'tag' ] + version_added: "2.4" extends_documentation_fragment: cloudstack ''' @@ -338,6 +346,10 @@ class AnsibleCloudStackVolume(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if poll_async: volume = self.poll_job(res, 'volume') + if volume: + volume = self.ensure_tags(resource=volume, resource_type='Volume') + self.volume=volume + return volume @@ -458,6 +470,7 @@ def main(): account = dict(default=None), project = dict(default=None), poll_async = dict(type='bool', default=True), + tags=dict(type='list', aliases=['tag'], default=None), )) module = AnsibleModule(