mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 21:30:22 -07:00
cloudstack: remove CloudStackException dep for several modules (#26874)
* cloudstack: cs_affinitygroup: remove CloudStackException dependency * cloudstack: cs_domain: remove CloudStackException dependency * cloudstack: cs_firewall: remove CloudStackException dependency * cloudstack: cs_host: remove CloudStackException dependency * cloudstack: cs_instancegroup: remove CloudStackException dependency * cloudstack: cs_pod: remove CloudStackException dependency * cloudstack: cs_configuration: remove CloudStackException dependency, fix pep8 * cloudstack: cs_cluster: remove CloudStackException dependency * cloudstack: cs_network_acl: remove CloudStackException dependency * cloudstack: cs_network_acl_rule: remove CloudStackException dependency * cloudstack: cs_zone_facts: remove CloudStackException dependency * cloudstack: cs_zone: remove CloudStackException dependency * cloudstack: cs_vpn_gateway: remove CloudStackException dependency * cloudstack: cs_vpc: remove CloudStackException dependency * cloudstack: cs_sshkeypair: remove CloudStackException dependency * cloudstack: cs_role: remove CloudStackException dependency * cloudstack: cs_ip_address: remove CloudStackException dependency * cloudstack: cs_ip_staticnat: remove CloudStackException dependency * cloudstack: cs_resourcelimit: remove CloudStackException dependency * cloudstack: cs_region: remove CloudStackException dependency * cloudstack: cs_project: remove CloudStackException dependency * cloudstack: cs_network: remove CloudStackException dependency * cloudstack: cs_loadbalancer_rule_member: remove CloudStackException dependency * cloudstack: cs_loadbalancer_rule: remove CloudStackException dependency * cloudstack: cs_iso: remove CloudStackException dependency
This commit is contained in:
parent
e228c7d021
commit
30ad30c470
26 changed files with 333 additions and 595 deletions
|
@ -349,7 +349,6 @@ zone:
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
CloudStackException,
|
||||
cs_argument_spec,
|
||||
cs_required_together,
|
||||
CS_HYPERVISORS
|
||||
|
@ -415,7 +414,7 @@ class AnsibleCloudStackHost(AnsibleCloudStack):
|
|||
'name': pod_name,
|
||||
'zoneid': self.get_zone(key='id'),
|
||||
}
|
||||
pods = self.cs.listPods(**args)
|
||||
pods = self.query_api('listPods', **args)
|
||||
if pods:
|
||||
return self._get_by_key(key, pods['pod'][0])
|
||||
self.module.fail_json(msg="Pod %s not found" % pod_name)
|
||||
|
@ -428,7 +427,7 @@ class AnsibleCloudStackHost(AnsibleCloudStack):
|
|||
'name': cluster_name,
|
||||
'zoneid': self.get_zone(key='id'),
|
||||
}
|
||||
clusters = self.cs.listClusters(**args)
|
||||
clusters = self.query_api('listClusters', **args)
|
||||
if clusters:
|
||||
return self._get_by_key(key, clusters['cluster'][0])
|
||||
self.module.fail_json(msg="Cluster %s not found" % cluster_name)
|
||||
|
@ -447,7 +446,7 @@ class AnsibleCloudStackHost(AnsibleCloudStack):
|
|||
args = {
|
||||
'zoneid': self.get_zone(key='id'),
|
||||
}
|
||||
res = self.cs.listHosts(**args)
|
||||
res = self.query_api('listHosts', **args)
|
||||
if res:
|
||||
for h in res['host']:
|
||||
if name in [h['ipaddress'], h['name']]:
|
||||
|
@ -530,9 +529,7 @@ class AnsibleCloudStackHost(AnsibleCloudStack):
|
|||
'hosttags': self.get_host_tags(),
|
||||
}
|
||||
if not self.module.check_mode:
|
||||
host = self.cs.addHost(**args)
|
||||
if 'errortext' in host:
|
||||
self.module.fail_json(msg="Failed: '%s'" % host['errortext'])
|
||||
host = self.query_api('addHost', **args)
|
||||
host = host['host'][0]
|
||||
return host
|
||||
|
||||
|
@ -549,9 +546,7 @@ class AnsibleCloudStackHost(AnsibleCloudStack):
|
|||
if self.has_changed(args, host):
|
||||
self.result['changed'] = True
|
||||
if not self.module.check_mode:
|
||||
host = self.cs.updateHost(**args)
|
||||
if 'errortext' in host:
|
||||
self.module.fail_json(msg="Failed: '%s'" % host['errortext'])
|
||||
host = self.query_api('updateHost', **args)
|
||||
host = host['host']
|
||||
|
||||
return host
|
||||
|
@ -566,9 +561,7 @@ class AnsibleCloudStackHost(AnsibleCloudStack):
|
|||
if not self.module.check_mode:
|
||||
res = self.enable_maintenance(host)
|
||||
if res:
|
||||
res = self.cs.deleteHost(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('deleteHost', **args)
|
||||
return host
|
||||
|
||||
def enable_maintenance(self, host):
|
||||
|
@ -578,9 +571,7 @@ class AnsibleCloudStackHost(AnsibleCloudStack):
|
|||
'id': host['id'],
|
||||
}
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.prepareHostForMaintenance(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('prepareHostForMaintenance', **args)
|
||||
self.poll_job(res, 'host')
|
||||
host = self._poll_for_maintenance()
|
||||
return host
|
||||
|
@ -592,9 +583,7 @@ class AnsibleCloudStackHost(AnsibleCloudStack):
|
|||
'id': host['id'],
|
||||
}
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.cancelHostMaintenance(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('cancelHostMaintenance', **args)
|
||||
host = self.poll_job(res, 'host')
|
||||
return host
|
||||
|
||||
|
@ -638,19 +627,15 @@ def main():
|
|||
supports_check_mode=True
|
||||
)
|
||||
|
||||
try:
|
||||
acs_host = AnsibleCloudStackHost(module)
|
||||
acs_host = AnsibleCloudStackHost(module)
|
||||
|
||||
state = module.params.get('state')
|
||||
if state == 'absent':
|
||||
host = acs_host.absent_host()
|
||||
else:
|
||||
host = acs_host.present_host()
|
||||
state = module.params.get('state')
|
||||
if state == 'absent':
|
||||
host = acs_host.absent_host()
|
||||
else:
|
||||
host = acs_host.present_host()
|
||||
|
||||
result = acs_host.get_result(host)
|
||||
|
||||
except CloudStackException as e:
|
||||
module.fail_json(msg='CloudStackException: %s' % str(e))
|
||||
result = acs_host.get_result(host)
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue