cloudstack: cs_affinitygroup: overhaul code style

This commit is contained in:
Rene Moser 2016-06-08 18:01:29 +02:00
parent 122beec048
commit a3f57a8cf4

View file

@ -136,22 +136,20 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack):
} }
self.affinity_group = None self.affinity_group = None
def get_affinity_group(self): def get_affinity_group(self):
if not self.affinity_group: if not self.affinity_group:
args = {} args = {
args['projectid'] = self.get_project(key='id') 'projectid': self.get_project(key='id'),
args['account'] = self.get_account('name') 'account': self.get_account(key='name'),
args['domainid'] = self.get_domain('id') 'domainid': self.get_domain(key='id'),
args['name'] = self.module.params.get('name') 'name': self.module.params.get('name'),
}
affinity_groups = self.cs.listAffinityGroups(**args) affinity_groups = self.cs.listAffinityGroups(**args)
if affinity_groups: if affinity_groups:
self.affinity_group = affinity_groups['affinitygroup'][0] self.affinity_group = affinity_groups['affinitygroup'][0]
return self.affinity_group return self.affinity_group
def get_affinity_type(self): def get_affinity_type(self):
affinity_type = self.module.params.get('affinty_type') affinity_type = self.module.params.get('affinty_type')
@ -165,20 +163,19 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack):
return a['type'] return a['type']
self.module.fail_json(msg="affinity group type '%s' not found" % affinity_type) self.module.fail_json(msg="affinity group type '%s' not found" % affinity_type)
def create_affinity_group(self): def create_affinity_group(self):
affinity_group = self.get_affinity_group() affinity_group = self.get_affinity_group()
if not affinity_group: if not affinity_group:
self.result['changed'] = True self.result['changed'] = True
args = {} args = {
args['name'] = self.module.params.get('name') 'name': self.module.params.get('name'),
args['type'] = self.get_affinity_type() 'type': self.get_affinity_type(),
args['description'] = self.module.params.get('description') 'description': self.module.params.get('description'),
args['projectid'] = self.get_project(key='id') 'projectid': self.get_project(key='id'),
args['account'] = self.get_account('name') 'account': self.get_account(key='name'),
args['domainid'] = self.get_domain('id') 'domainid': self.get_domain(key='id'),
}
if not self.module.check_mode: if not self.module.check_mode:
res = self.cs.createAffinityGroup(**args) res = self.cs.createAffinityGroup(**args)
@ -190,18 +187,17 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack):
affinity_group = self._poll_job(res, 'affinitygroup') affinity_group = self._poll_job(res, 'affinitygroup')
return affinity_group return affinity_group
def remove_affinity_group(self): def remove_affinity_group(self):
affinity_group = self.get_affinity_group() affinity_group = self.get_affinity_group()
if affinity_group: if affinity_group:
self.result['changed'] = True self.result['changed'] = True
args = {} args = {
args['name'] = self.module.params.get('name') 'name': self.module.params.get('name'),
args['projectid'] = self.get_project(key='id') 'projectid': self.get_project(key='id'),
args['account'] = self.get_account('name') 'account': self.get_account(key='name'),
args['domainid'] = self.get_domain('id') 'domainid': self.get_domain(key='id'),
}
if not self.module.check_mode: if not self.module.check_mode:
res = self.cs.deleteAffinityGroup(**args) res = self.cs.deleteAffinityGroup(**args)
@ -210,7 +206,7 @@ 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') self._poll_job(res, 'affinitygroup')
return affinity_group return affinity_group