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