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_account: remove CloudStackException dependency (#26870)

This commit is contained in:
René Moser 2017-07-16 12:02:28 +02:00 committed by GitHub
parent 1a27546039
commit 8477525d2b

View file

@ -181,7 +181,6 @@ domain:
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.cloudstack import ( from ansible.module_utils.cloudstack import (
AnsibleCloudStack, AnsibleCloudStack,
CloudStackException,
cs_argument_spec, cs_argument_spec,
cs_required_together cs_required_together
) )
@ -211,7 +210,7 @@ class AnsibleCloudStackAccount(AnsibleCloudStack):
'listall': True, 'listall': True,
'domainid': self.get_domain(key='id'), 'domainid': self.get_domain(key='id'),
} }
accounts = self.cs.listAccounts(**args) accounts = self.query_api('listAccounts', **args)
if accounts: if accounts:
account_name = self.module.params.get('name') account_name = self.module.params.get('name')
for a in accounts['account']: for a in accounts['account']:
@ -234,9 +233,7 @@ class AnsibleCloudStackAccount(AnsibleCloudStack):
'domainid': self.get_domain(key='id') 'domainid': self.get_domain(key='id')
} }
if not self.module.check_mode: if not self.module.check_mode:
res = self.cs.enableAccount(**args) res = self.query_api('enableAccount', **args)
if 'errortext' in res:
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
account = res['account'] account = res['account']
return account return account
@ -265,10 +262,7 @@ class AnsibleCloudStackAccount(AnsibleCloudStack):
'lock': lock, 'lock': lock,
} }
if not self.module.check_mode: if not self.module.check_mode:
account = self.cs.disableAccount(**args) account = self.query_api('disableAccount', **args)
if 'errortext' in account:
self.module.fail_json(msg="Failed: '%s'" % account['errortext'])
poll_async = self.module.params.get('poll_async') poll_async = self.module.params.get('poll_async')
if poll_async: if poll_async:
@ -303,9 +297,7 @@ class AnsibleCloudStackAccount(AnsibleCloudStack):
'timezone': self.module.params.get('timezone') 'timezone': self.module.params.get('timezone')
} }
if not self.module.check_mode: if not self.module.check_mode:
res = self.cs.createAccount(**args) res = self.query_api('createAccount', **args)
if 'errortext' in res:
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
account = res['account'] account = res['account']
return account return account
@ -315,10 +307,7 @@ class AnsibleCloudStackAccount(AnsibleCloudStack):
self.result['changed'] = True self.result['changed'] = True
if not self.module.check_mode: if not self.module.check_mode:
res = self.cs.deleteAccount(id=account['id']) res = self.query_api('deleteAccount', id=account['id'])
if 'errortext' in res:
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
poll_async = self.module.params.get('poll_async') poll_async = self.module.params.get('poll_async')
if poll_async: if poll_async:
@ -359,7 +348,6 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
try:
acs_acc = AnsibleCloudStackAccount(module) acs_acc = AnsibleCloudStackAccount(module)
state = module.params.get('state') state = module.params.get('state')
@ -381,9 +369,6 @@ def main():
result = acs_acc.get_result(account) result = acs_acc.get_result(account)
except CloudStackException as e:
module.fail_json(msg='CloudStackException: %s' % str(e))
module.exit_json(**result) module.exit_json(**result)