1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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
from ansible.module_utils.cloudstack import *
class AnsibleCloudStackCluster(AnsibleCloudStack):
def __init__(self, module):
@ -245,29 +246,27 @@ class AnsibleCloudStackCluster(AnsibleCloudStack):
}
self.cluster = None
def _get_common_cluster_args(self):
args = {}
args['clustername'] = self.module.params.get('name')
args['hypervisor'] = self.module.params.get('hypervisor')
args['clustertype'] = self.module.params.get('cluster_type')
args = {
'clustername': self.module.params.get('name'),
'hypervisor': self.module.params.get('hypervisor'),
'clustertype': self.module.params.get('cluster_type'),
}
state = self.module.params.get('state')
if state in [ 'enabled', 'disabled']:
if state in ['enabled', 'disabled']:
args['allocationstate'] = state.capitalize()
return args
def get_pod(self, key=None):
args = {}
args['name'] = self.module.params.get('pod')
args['zoneid'] = self.get_zone(key='id')
args = {
'name': self.module.params.get('pod'),
'zoneid': self.get_zone(key='id'),
}
pods = self.cs.listPods(**args)
if pods:
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')))
def get_cluster(self):
if not self.cluster:
args = {}
@ -289,7 +288,6 @@ class AnsibleCloudStackCluster(AnsibleCloudStack):
self.cluster['clustername'] = self.cluster['name']
return self.cluster
def present_cluster(self):
cluster = self.get_cluster()
if cluster:
@ -298,7 +296,6 @@ class AnsibleCloudStackCluster(AnsibleCloudStack):
cluster = self._create_cluster()
return cluster
def _create_cluster(self):
required_params = [
'cluster_type',
@ -337,7 +334,6 @@ class AnsibleCloudStackCluster(AnsibleCloudStack):
cluster = res['cluster']
return cluster
def _update_cluster(self):
cluster = self.get_cluster()
@ -354,15 +350,14 @@ class AnsibleCloudStackCluster(AnsibleCloudStack):
cluster = res['cluster']
return cluster
def absent_cluster(self):
cluster = self.get_cluster()
if cluster:
self.result['changed'] = True
args = {}
args['id'] = cluster['id']
args = {
'id': cluster['id'],
}
if not self.module.check_mode:
res = self.cs.deleteCluster(**args)
if 'errortext' in res:
@ -373,25 +368,25 @@ class AnsibleCloudStackCluster(AnsibleCloudStack):
def main():
argument_spec = cs_argument_spec()
argument_spec.update(dict(
name = dict(required=True),
zone = dict(default=None),
pod = dict(default=None),
cluster_type = dict(choices=['CloudManaged', 'ExternalManaged'], default=None),
hypervisor = dict(choices=CS_HYPERVISORS, default=None),
state = dict(choices=['present', 'enabled', 'disabled', 'absent'], default='present'),
url = dict(default=None),
username = dict(default=None),
password = dict(default=None, no_log=True),
guest_vswitch_name = dict(default=None),
guest_vswitch_type = dict(choices=['vmwaresvs', 'vmwaredvs'], default=None),
public_vswitch_name = dict(default=None),
public_vswitch_type = dict(choices=['vmwaresvs', 'vmwaredvs'], default=None),
vms_ip_address = dict(default=None),
vms_username = dict(default=None),
vms_password = dict(default=None, no_log=True),
ovm3_cluster = dict(default=None),
ovm3_pool = dict(default=None),
ovm3_vip = dict(default=None),
name=dict(required=True),
zone=dict(default=None),
pod=dict(default=None),
cluster_type=dict(choices=['CloudManaged', 'ExternalManaged'], default=None),
hypervisor=dict(choices=CS_HYPERVISORS, default=None),
state=dict(choices=['present', 'enabled', 'disabled', 'absent'], default='present'),
url=dict(default=None),
username=dict(default=None),
password=dict(default=None, no_log=True),
guest_vswitch_name=dict(default=None),
guest_vswitch_type=dict(choices=['vmwaresvs', 'vmwaredvs'], default=None),
public_vswitch_name=dict(default=None),
public_vswitch_type=dict(choices=['vmwaresvs', 'vmwaredvs'], default=None),
vms_ip_address=dict(default=None),
vms_username=dict(default=None),
vms_password=dict(default=None, no_log=True),
ovm3_cluster=dict(default=None),
ovm3_pool=dict(default=None),
ovm3_vip=dict(default=None),
))
module = AnsibleModule(