From 75456f7b3aff027d2bfe8572f6d5512f2ee4f371 Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Sun, 20 Dec 2015 22:24:58 +0100 Subject: [PATCH] cloudstack: fix name is not case insensitive --- .../cloud/cloudstack/cs_affinitygroup.py | 7 +-- .../cloud/cloudstack/cs_securitygroup.py | 53 ++++++++++++++++--- 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_affinitygroup.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_affinitygroup.py index 7181eae607..a3ac1b0696 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_affinitygroup.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_affinitygroup.py @@ -124,18 +124,15 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack): def get_affinity_group(self): if not self.affinity_group: - affinity_group = self.module.params.get('name') args = {} args['account'] = self.get_account('name') args['domainid'] = self.get_domain('id') + args['name'] = self.module.params.get('name') affinity_groups = self.cs.listAffinityGroups(**args) if affinity_groups: - for a in affinity_groups['affinitygroup']: - if affinity_group in [ a['name'], a['id'] ]: - self.affinity_group = a - break + self.affinity_group = affinity_groups['affinitygroup'][0] return self.affinity_group diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_securitygroup.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_securitygroup.py index 43efa1ae16..ec30c757e7 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_securitygroup.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_securitygroup.py @@ -40,6 +40,16 @@ options: required: false default: 'present' choices: [ 'present', 'absent' ] + domain: + description: + - Domain the security group is related to. + required: false + default: null + account: + description: + - Account the security group is related to. + required: false + default: null project: description: - Name of the project the security group to be created in. @@ -79,6 +89,26 @@ description: returned: success type: string sample: application security group +tags: + description: List of resource tags associated with the security group. + returned: success + type: dict + sample: '[ { "key": "foo", "value": "bar" } ]' +project: + description: Name of project the security group is related to. + returned: success + type: string + sample: Production +domain: + description: Domain the security group is related to. + returned: success + type: string + sample: example domain +account: + description: Account the security group is related to. + returned: success + type: string + sample: example account ''' try: @@ -100,15 +130,16 @@ class AnsibleCloudStackSecurityGroup(AnsibleCloudStack): def get_security_group(self): if not self.security_group: - sg_name = self.module.params.get('name') + args = {} - args['projectid'] = self.get_project('id') + args['projectid'] = self.get_project(key='id') + args['account'] = self.get_account(key='name') + args['domainid'] = self.get_domain(key='id') + args['securitygroupname'] = self.module.params.get('name') + sgs = self.cs.listSecurityGroups(**args) if sgs: - for s in sgs['securitygroup']: - if s['name'] == sg_name: - self.security_group = s - break + self.security_group = sgs['securitygroup'][0] return self.security_group @@ -119,7 +150,9 @@ class AnsibleCloudStackSecurityGroup(AnsibleCloudStack): args = {} args['name'] = self.module.params.get('name') - args['projectid'] = self.get_project('id') + args['projectid'] = self.get_project(key='id') + args['account'] = self.get_account(key='name') + args['domainid'] = self.get_domain(key='id') args['description'] = self.module.params.get('description') if not self.module.check_mode: @@ -138,7 +171,9 @@ class AnsibleCloudStackSecurityGroup(AnsibleCloudStack): args = {} args['name'] = self.module.params.get('name') - args['projectid'] = self.get_project('id') + args['projectid'] = self.get_project(key='id') + args['account'] = self.get_account(key='name') + args['domainid'] = self.get_domain(key='id') if not self.module.check_mode: res = self.cs.deleteSecurityGroup(**args) @@ -156,6 +191,8 @@ def main(): description = dict(default=None), state = dict(choices=['present', 'absent'], default='present'), project = dict(default=None), + account = dict(default=None), + domain = dict(default=None), )) module = AnsibleModule(