cloudstack: cs_instance_nic: remove CloudStackException dependency (#26860)

pull/26853/merge
René Moser 7 years ago committed by GitHub
parent 8320071e81
commit 2a751e1753

@ -164,7 +164,6 @@ from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.cloudstack import (AnsibleCloudStack, from ansible.module_utils.cloudstack import (AnsibleCloudStack,
cs_argument_spec, cs_argument_spec,
cs_required_together) cs_required_together)
from cs import CloudStackException
class AnsibleCloudStackInstanceNic(AnsibleCloudStack): class AnsibleCloudStackInstanceNic(AnsibleCloudStack):
@ -185,7 +184,7 @@ class AnsibleCloudStackInstanceNic(AnsibleCloudStack):
'virtualmachineid': self.get_vm(key='id'), 'virtualmachineid': self.get_vm(key='id'),
'networkid': self.get_network(key='id'), 'networkid': self.get_network(key='id'),
} }
nics = self.cs.listNics(**args) nics = self.query_api('listNics', **args)
if nics: if nics:
self.nic = nics['nic'][0] self.nic = nics['nic'][0]
return self.nic return self.nic
@ -204,7 +203,7 @@ class AnsibleCloudStackInstanceNic(AnsibleCloudStack):
'ipaddress': self.module.params.get('ip_address'), 'ipaddress': self.module.params.get('ip_address'),
} }
if not self.module.check_mode: if not self.module.check_mode:
res = self.cs.addNicToVirtualMachine(**args) res = self.query_api('addNicToVirtualMachine', **args)
if 'errortext' in res: if 'errortext' in res:
self.module.fail_json(msg="Failed: '%s'" % res['errortext']) self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
@ -226,9 +225,7 @@ class AnsibleCloudStackInstanceNic(AnsibleCloudStack):
if self.has_changed(args, nic, ['ipaddress']): if self.has_changed(args, nic, ['ipaddress']):
self.result['changed'] = True self.result['changed'] = True
if not self.module.check_mode: if not self.module.check_mode:
res = self.cs.updateVmNicIp(**args) res = self.query_api('updateVmNicIp', **args)
if 'errortext' in res:
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
if self.module.params.get('poll_async'): if self.module.params.get('poll_async'):
vm = self.poll_job(res, 'virtualmachine') vm = self.poll_job(res, 'virtualmachine')
@ -242,9 +239,7 @@ class AnsibleCloudStackInstanceNic(AnsibleCloudStack):
'nicid': nic['id'], 'nicid': nic['id'],
} }
if not self.module.check_mode: if not self.module.check_mode:
res = self.cs.removeNicFromVirtualMachine(**args) res = self.query_api('removeNicFromVirtualMachine', **args)
if 'errortext' in res:
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
if self.module.params.get('poll_async'): if self.module.params.get('poll_async'):
self.poll_job(res, 'virtualmachine') self.poll_job(res, 'virtualmachine')
@ -278,13 +273,13 @@ def main():
argument_spec.update(dict( argument_spec.update(dict(
vm=dict(required=True, aliases=['name']), vm=dict(required=True, aliases=['name']),
network=dict(required=True), network=dict(required=True),
vpc=dict(default=None), vpc=dict(),
ip_address=dict(), ip_address=dict(),
state=dict(choices=['present', 'absent'], default='present'), state=dict(choices=['present', 'absent'], default='present'),
domain=dict(default=None), domain=dict(),
account=dict(default=None), account=dict(),
project=dict(default=None), project=dict(),
zone=dict(default=None), zone=dict(),
poll_async=dict(type='bool', default=True), poll_async=dict(type='bool', default=True),
)) ))
@ -294,11 +289,9 @@ def main():
supports_check_mode=True, supports_check_mode=True,
) )
try:
acs_nic = AnsibleCloudStackInstanceNic(module) acs_nic = AnsibleCloudStackInstanceNic(module)
state = module.params.get('state') state = module.params.get('state')
if state == 'absent': if state == 'absent':
nic = acs_nic.absent_nic() nic = acs_nic.absent_nic()
else: else:
@ -306,9 +299,6 @@ def main():
result = acs_nic.get_result(nic) result = acs_nic.get_result(nic)
except CloudStackException as e:
module.fail_json(msg='CloudStackException: %s' % str(e))
module.exit_json(**result) module.exit_json(**result)

Loading…
Cancel
Save