cloudstack: cs_affinitygroup: add domain and account support

reviewable/pr18780/r1
Rene Moser 10 years ago
parent 9f41d78346
commit 63e9014e16

@ -47,6 +47,16 @@ options:
required: false required: false
default: 'present' default: 'present'
choices: [ 'present', 'absent' ] choices: [ 'present', 'absent' ]
domain:
description:
- Domain the affinity group is related to.
required: false
default: null
account:
description:
- Account the affinity group is related to.
required: false
default: null
poll_async: poll_async:
description: description:
- Poll async jobs until job has finished. - Poll async jobs until job has finished.
@ -112,12 +122,16 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack):
def get_affinity_group(self): def get_affinity_group(self):
if not self.affinity_group: if not self.affinity_group:
affinity_group_name = self.module.params.get('name') affinity_group = self.module.params.get('name')
args = {}
args['account'] = self.get_account('name')
args['domainid'] = self.get_domain('id')
affinity_groups = self.cs.listAffinityGroups() affinity_groups = self.cs.listAffinityGroups(**args)
if affinity_groups: if affinity_groups:
for a in affinity_groups['affinitygroup']: for a in affinity_groups['affinitygroup']:
if a['name'] == affinity_group_name: if affinity_group in [ a['name'], a['id'] ]:
self.affinity_group = a self.affinity_group = a
break break
return self.affinity_group return self.affinity_group
@ -146,6 +160,8 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack):
args['name'] = self.module.params.get('name') args['name'] = self.module.params.get('name')
args['type'] = self.get_affinity_type() args['type'] = self.get_affinity_type()
args['description'] = self.module.params.get('description') args['description'] = self.module.params.get('description')
args['account'] = self.get_account('name')
args['domainid'] = self.get_domain('id')
if not self.module.check_mode: if not self.module.check_mode:
res = self.cs.createAffinityGroup(**args) res = self.cs.createAffinityGroup(**args)
@ -156,7 +172,6 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack):
poll_async = self.module.params.get('poll_async') poll_async = self.module.params.get('poll_async')
if res and poll_async: if res and poll_async:
affinity_group = self._poll_job(res, 'affinitygroup') affinity_group = self._poll_job(res, 'affinitygroup')
return affinity_group return affinity_group
@ -167,6 +182,8 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack):
args = {} args = {}
args['name'] = self.module.params.get('name') args['name'] = self.module.params.get('name')
args['account'] = self.get_account('name')
args['domainid'] = self.get_domain('id')
if not self.module.check_mode: if not self.module.check_mode:
res = self.cs.deleteAffinityGroup(**args) res = self.cs.deleteAffinityGroup(**args)
@ -177,7 +194,6 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack):
poll_async = self.module.params.get('poll_async') poll_async = self.module.params.get('poll_async')
if res and poll_async: if res and poll_async:
res = self._poll_job(res, 'affinitygroup') res = self._poll_job(res, 'affinitygroup')
return affinity_group return affinity_group
@ -189,6 +205,10 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack):
self.result['description'] = affinity_group['description'] self.result['description'] = affinity_group['description']
if 'type' in affinity_group: if 'type' in affinity_group:
self.result['affinity_type'] = affinity_group['type'] self.result['affinity_type'] = affinity_group['type']
if 'domain' in affinity_group:
self.result['domain'] = affinity_group['domain']
if 'account' in affinity_group:
self.result['account'] = affinity_group['account']
return self.result return self.result
@ -199,6 +219,8 @@ def main():
affinty_type = dict(default=None), affinty_type = dict(default=None),
description = dict(default=None), description = dict(default=None),
state = dict(choices=['present', 'absent'], default='present'), state = dict(choices=['present', 'absent'], default='present'),
domain = dict(default=None),
account = dict(default=None),
poll_async = dict(choices=BOOLEANS, default=True), poll_async = dict(choices=BOOLEANS, default=True),
api_key = dict(default=None), api_key = dict(default=None),
api_secret = dict(default=None, no_log=True), api_secret = dict(default=None, no_log=True),

Loading…
Cancel
Save