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:
parent
4d26762b34
commit
03d3baa164
1 changed files with 33 additions and 38 deletions
|
@ -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:
|
||||||
|
@ -373,25 +368,25 @@ class AnsibleCloudStackCluster(AnsibleCloudStack):
|
||||||
def main():
|
def main():
|
||||||
argument_spec = cs_argument_spec()
|
argument_spec = cs_argument_spec()
|
||||||
argument_spec.update(dict(
|
argument_spec.update(dict(
|
||||||
name = dict(required=True),
|
name=dict(required=True),
|
||||||
zone = dict(default=None),
|
zone=dict(default=None),
|
||||||
pod = dict(default=None),
|
pod=dict(default=None),
|
||||||
cluster_type = dict(choices=['CloudManaged', 'ExternalManaged'], default=None),
|
cluster_type=dict(choices=['CloudManaged', 'ExternalManaged'], default=None),
|
||||||
hypervisor = dict(choices=CS_HYPERVISORS, default=None),
|
hypervisor=dict(choices=CS_HYPERVISORS, default=None),
|
||||||
state = dict(choices=['present', 'enabled', 'disabled', 'absent'], default='present'),
|
state=dict(choices=['present', 'enabled', 'disabled', 'absent'], default='present'),
|
||||||
url = dict(default=None),
|
url=dict(default=None),
|
||||||
username = dict(default=None),
|
username=dict(default=None),
|
||||||
password = dict(default=None, no_log=True),
|
password=dict(default=None, no_log=True),
|
||||||
guest_vswitch_name = dict(default=None),
|
guest_vswitch_name=dict(default=None),
|
||||||
guest_vswitch_type = dict(choices=['vmwaresvs', 'vmwaredvs'], default=None),
|
guest_vswitch_type=dict(choices=['vmwaresvs', 'vmwaredvs'], default=None),
|
||||||
public_vswitch_name = dict(default=None),
|
public_vswitch_name=dict(default=None),
|
||||||
public_vswitch_type = dict(choices=['vmwaresvs', 'vmwaredvs'], default=None),
|
public_vswitch_type=dict(choices=['vmwaresvs', 'vmwaredvs'], default=None),
|
||||||
vms_ip_address = dict(default=None),
|
vms_ip_address=dict(default=None),
|
||||||
vms_username = dict(default=None),
|
vms_username=dict(default=None),
|
||||||
vms_password = dict(default=None, no_log=True),
|
vms_password=dict(default=None, no_log=True),
|
||||||
ovm3_cluster = dict(default=None),
|
ovm3_cluster=dict(default=None),
|
||||||
ovm3_pool = dict(default=None),
|
ovm3_pool=dict(default=None),
|
||||||
ovm3_vip = dict(default=None),
|
ovm3_vip=dict(default=None),
|
||||||
))
|
))
|
||||||
|
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
|
|
Loading…
Reference in a new issue