Merge pull request #961 from resmo/feature/cs_account
cloudstack: cs_account improvements
This commit is contained in:
commit
4c59101825
1 changed files with 16 additions and 20 deletions
|
@ -85,9 +85,10 @@ options:
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- State of the account.
|
- State of the account.
|
||||||
|
- C(unlocked) is an alias for C(enabled).
|
||||||
required: false
|
required: false
|
||||||
default: 'present'
|
default: 'present'
|
||||||
choices: [ 'present', 'absent', 'enabled', 'disabled', 'locked' ]
|
choices: [ 'present', 'absent', 'enabled', 'disabled', 'locked', 'unlocked' ]
|
||||||
poll_async:
|
poll_async:
|
||||||
description:
|
description:
|
||||||
- Poll async jobs until job has finished.
|
- Poll async jobs until job has finished.
|
||||||
|
@ -220,7 +221,7 @@ class AnsibleCloudStackAccount(AnsibleCloudStack):
|
||||||
def enable_account(self):
|
def enable_account(self):
|
||||||
account = self.get_account()
|
account = self.get_account()
|
||||||
if not account:
|
if not account:
|
||||||
self.module.fail_json(msg="Failed: account not present")
|
account = self.present_account()
|
||||||
|
|
||||||
if account['state'].lower() != 'enabled':
|
if account['state'].lower() != 'enabled':
|
||||||
self.result['changed'] = True
|
self.result['changed'] = True
|
||||||
|
@ -247,7 +248,7 @@ class AnsibleCloudStackAccount(AnsibleCloudStack):
|
||||||
def lock_or_disable_account(self, lock=False):
|
def lock_or_disable_account(self, lock=False):
|
||||||
account = self.get_account()
|
account = self.get_account()
|
||||||
if not account:
|
if not account:
|
||||||
self.module.fail_json(msg="Failed: account not present")
|
account = self.present_account()
|
||||||
|
|
||||||
# we need to enable the account to lock it.
|
# we need to enable the account to lock it.
|
||||||
if lock and account['state'].lower() == 'disabled':
|
if lock and account['state'].lower() == 'disabled':
|
||||||
|
@ -276,21 +277,16 @@ class AnsibleCloudStackAccount(AnsibleCloudStack):
|
||||||
def present_account(self):
|
def present_account(self):
|
||||||
missing_params = []
|
missing_params = []
|
||||||
|
|
||||||
if not self.module.params.get('email'):
|
missing_params = []
|
||||||
missing_params.append('email')
|
for required_params in [
|
||||||
|
'email',
|
||||||
if not self.module.params.get('username'):
|
'username',
|
||||||
missing_params.append('username')
|
'password',
|
||||||
|
'first_name',
|
||||||
if not self.module.params.get('password'):
|
'last_name',
|
||||||
missing_params.append('password')
|
]:
|
||||||
|
if not self.module.params.get(required_params):
|
||||||
if not self.module.params.get('first_name'):
|
missing_params.append(required_params)
|
||||||
missing_params.append('first_name')
|
|
||||||
|
|
||||||
if not self.module.params.get('last_name'):
|
|
||||||
missing_params.append('last_name')
|
|
||||||
|
|
||||||
if missing_params:
|
if missing_params:
|
||||||
self.module.fail_json(msg="missing required arguments: %s" % ','.join(missing_params))
|
self.module.fail_json(msg="missing required arguments: %s" % ','.join(missing_params))
|
||||||
|
|
||||||
|
@ -350,7 +346,7 @@ def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
name = dict(required=True),
|
name = dict(required=True),
|
||||||
state = dict(choices=['present', 'absent', 'enabled', 'disabled', 'locked' ], default='present'),
|
state = dict(choices=['present', 'absent', 'enabled', 'disabled', 'locked', 'unlocked'], default='present'),
|
||||||
account_type = dict(choices=['user', 'root_admin', 'domain_admin'], default='user'),
|
account_type = dict(choices=['user', 'root_admin', 'domain_admin'], default='user'),
|
||||||
network_domain = dict(default=None),
|
network_domain = dict(default=None),
|
||||||
domain = dict(default='ROOT'),
|
domain = dict(default='ROOT'),
|
||||||
|
@ -385,7 +381,7 @@ def main():
|
||||||
if state in ['absent']:
|
if state in ['absent']:
|
||||||
account = acs_acc.absent_account()
|
account = acs_acc.absent_account()
|
||||||
|
|
||||||
elif state in ['enabled']:
|
elif state in ['enabled', 'unlocked']:
|
||||||
account = acs_acc.enable_account()
|
account = acs_acc.enable_account()
|
||||||
|
|
||||||
elif state in ['disabled']:
|
elif state in ['disabled']:
|
||||||
|
|
Loading…
Reference in a new issue