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

cloudstack: fix pep8 cs_cluster

This commit is contained in:
Rene Moser 2017-05-28 01:01:38 +02:00 committed by René Moser
parent 06035eca67
commit 9fe3891d65
3 changed files with 49 additions and 30 deletions

View file

@ -231,8 +231,14 @@ pod:
sample: pod01 sample: pod01
''' '''
# import cloudstack common from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import (
AnsibleCloudStack,
CloudStackException,
cs_argument_spec,
cs_required_together,
CS_HYPERVISORS
)
class AnsibleCloudStackCluster(AnsibleCloudStack): class AnsibleCloudStackCluster(AnsibleCloudStack):
@ -240,14 +246,14 @@ class AnsibleCloudStackCluster(AnsibleCloudStack):
def __init__(self, module): def __init__(self, module):
super(AnsibleCloudStackCluster, self).__init__(module) super(AnsibleCloudStackCluster, self).__init__(module)
self.returns = { self.returns = {
'allocationstate': 'allocation_state', 'allocationstate': 'allocation_state',
'hypervisortype': 'hypervisor', 'hypervisortype': 'hypervisor',
'clustertype': 'cluster_type', 'clustertype': 'cluster_type',
'podname': 'pod', 'podname': 'pod',
'managedstate': 'managed_state', 'managedstate': 'managed_state',
'memoryovercommitratio': 'memory_overcommit_ratio', 'memoryovercommitratio': 'memory_overcommit_ratio',
'cpuovercommitratio': 'cpu_overcommit_ratio', 'cpuovercommitratio': 'cpu_overcommit_ratio',
'ovm3vip': 'ovm3_vip', 'ovm3vip': 'ovm3_vip',
} }
self.cluster = None self.cluster = None
@ -270,7 +276,7 @@ class AnsibleCloudStackCluster(AnsibleCloudStack):
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:
@ -374,24 +380,24 @@ 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(),
pod=dict(default=None), pod=dict(),
cluster_type=dict(choices=['CloudManaged', 'ExternalManaged'], default=None), cluster_type=dict(choices=['CloudManaged', 'ExternalManaged']),
hypervisor=dict(choices=CS_HYPERVISORS, default=None), hypervisor=dict(choices=CS_HYPERVISORS),
state=dict(choices=['present', 'enabled', 'disabled', 'absent'], default='present'), state=dict(choices=['present', 'enabled', 'disabled', 'absent'], default='present'),
url=dict(default=None), url=dict(),
username=dict(default=None), username=dict(),
password=dict(default=None, no_log=True), password=dict(no_log=True),
guest_vswitch_name=dict(default=None), guest_vswitch_name=dict(),
guest_vswitch_type=dict(choices=['vmwaresvs', 'vmwaredvs'], default=None), guest_vswitch_type=dict(choices=['vmwaresvs', 'vmwaredvs']),
public_vswitch_name=dict(default=None), public_vswitch_name=dict(),
public_vswitch_type=dict(choices=['vmwaresvs', 'vmwaredvs'], default=None), public_vswitch_type=dict(choices=['vmwaresvs', 'vmwaredvs']),
vms_ip_address=dict(default=None), vms_ip_address=dict(),
vms_username=dict(default=None), vms_username=dict(),
vms_password=dict(default=None, no_log=True), vms_password=dict(no_log=True),
ovm3_cluster=dict(default=None), ovm3_cluster=dict(),
ovm3_pool=dict(default=None), ovm3_pool=dict(),
ovm3_vip=dict(default=None), ovm3_vip=dict(),
)) ))
module = AnsibleModule( module = AnsibleModule(
@ -416,7 +422,6 @@ def main():
module.exit_json(**result) module.exit_json(**result)
# import module snippets
from ansible.module_utils.basic import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -44,6 +44,21 @@
- cluster|failed - cluster|failed
- "cluster.msg == 'missing required arguments: name'" - "cluster.msg == 'missing required arguments: name'"
- name: test fail if pod not found
cs_cluster:
name: "{{ cs_resource_prefix }}-cluster"
zone: "{{ cs_resource_prefix }}-zone"
hypervisor: simulator
cluster_type: CloudManaged
pod: unexistent
register: cluster
ignore_errors: true
- name: verify results of fail if missing name
assert:
that:
- cluster|failed
- "cluster.msg == 'Pod unexistent not found in zone {{ cs_resource_prefix }}-zone'"
- name: test create cluster in check mode - name: test create cluster in check mode
cs_cluster: cs_cluster:
name: "{{ cs_resource_prefix }}-cluster" name: "{{ cs_resource_prefix }}-cluster"

View file

@ -165,7 +165,6 @@ lib/ansible/modules/cloud/azure/azure_rm_virtualnetwork_facts.py
lib/ansible/modules/cloud/centurylink/clc_loadbalancer.py lib/ansible/modules/cloud/centurylink/clc_loadbalancer.py
lib/ansible/modules/cloud/cloudscale/cloudscale_server.py lib/ansible/modules/cloud/cloudscale/cloudscale_server.py
lib/ansible/modules/cloud/cloudstack/cs_account.py lib/ansible/modules/cloud/cloudstack/cs_account.py
lib/ansible/modules/cloud/cloudstack/cs_cluster.py
lib/ansible/modules/cloud/cloudstack/cs_configuration.py lib/ansible/modules/cloud/cloudstack/cs_configuration.py
lib/ansible/modules/cloud/cloudstack/cs_domain.py lib/ansible/modules/cloud/cloudstack/cs_domain.py
lib/ansible/modules/cloud/cloudstack/cs_facts.py lib/ansible/modules/cloud/cloudstack/cs_facts.py