cloudstack: cs_cluster: overhaul code style

This commit is contained in:
Rene Moser 2016-06-09 21:22:19 +02:00 committed by Matt Clay
parent 4d26762b34
commit 03d3baa164

View file

@ -229,6 +229,7 @@ pod:
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
class AnsibleCloudStackCluster(AnsibleCloudStack): class AnsibleCloudStackCluster(AnsibleCloudStack):
def __init__(self, module): def __init__(self, module):
@ -245,29 +246,27 @@ class AnsibleCloudStackCluster(AnsibleCloudStack):
} }
self.cluster = None self.cluster = None
def _get_common_cluster_args(self): def _get_common_cluster_args(self):
args = {} args = {
args['clustername'] = self.module.params.get('name') 'clustername': self.module.params.get('name'),
args['hypervisor'] = self.module.params.get('hypervisor') 'hypervisor': self.module.params.get('hypervisor'),
args['clustertype'] = self.module.params.get('cluster_type') 'clustertype': self.module.params.get('cluster_type'),
}
state = self.module.params.get('state') state = self.module.params.get('state')
if state in ['enabled', 'disabled']: if state in ['enabled', 'disabled']:
args['allocationstate'] = state.capitalize() args['allocationstate'] = state.capitalize()
return args return args
def get_pod(self, key=None): def get_pod(self, key=None):
args = {} args = {
args['name'] = self.module.params.get('pod') 'name': self.module.params.get('pod'),
args['zoneid'] = self.get_zone(key='id') 'zoneid': self.get_zone(key='id'),
}
pods = self.cs.listPods(**args) pods = self.cs.listPods(**args)
if pods: if pods:
return self._get_by_key(key, pods['pod'][0]) return self._get_by_key(key, pods['pod'][0])
self.module.fail_json(msg="Pod %s not found in zone %s." % (self.module.params.get('pod'), self.get_zone(key='name'))) self.module.fail_json(msg="Pod %s not found in zone %s." % (self.module.params.get('pod'), self.get_zone(key='name')))
def get_cluster(self): def get_cluster(self):
if not self.cluster: if not self.cluster:
args = {} args = {}
@ -289,7 +288,6 @@ class AnsibleCloudStackCluster(AnsibleCloudStack):
self.cluster['clustername'] = self.cluster['name'] self.cluster['clustername'] = self.cluster['name']
return self.cluster return self.cluster
def present_cluster(self): def present_cluster(self):
cluster = self.get_cluster() cluster = self.get_cluster()
if cluster: if cluster:
@ -298,7 +296,6 @@ class AnsibleCloudStackCluster(AnsibleCloudStack):
cluster = self._create_cluster() cluster = self._create_cluster()
return cluster return cluster
def _create_cluster(self): def _create_cluster(self):
required_params = [ required_params = [
'cluster_type', 'cluster_type',
@ -337,7 +334,6 @@ class AnsibleCloudStackCluster(AnsibleCloudStack):
cluster = res['cluster'] cluster = res['cluster']
return cluster return cluster
def _update_cluster(self): def _update_cluster(self):
cluster = self.get_cluster() cluster = self.get_cluster()
@ -354,15 +350,14 @@ class AnsibleCloudStackCluster(AnsibleCloudStack):
cluster = res['cluster'] cluster = res['cluster']
return cluster return cluster
def absent_cluster(self): def absent_cluster(self):
cluster = self.get_cluster() cluster = self.get_cluster()
if cluster: if cluster:
self.result['changed'] = True self.result['changed'] = True
args = {} args = {
args['id'] = cluster['id'] 'id': cluster['id'],
}
if not self.module.check_mode: if not self.module.check_mode:
res = self.cs.deleteCluster(**args) res = self.cs.deleteCluster(**args)
if 'errortext' in res: if 'errortext' in res: