|
|
@ -172,12 +172,6 @@ domain:
|
|
|
|
sample: ROOT
|
|
|
|
sample: ROOT
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
from cs import CloudStack, CloudStackException, read_config
|
|
|
|
|
|
|
|
has_lib_cs = True
|
|
|
|
|
|
|
|
except ImportError:
|
|
|
|
|
|
|
|
has_lib_cs = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# import cloudstack common
|
|
|
|
# import cloudstack common
|
|
|
|
from ansible.module_utils.cloudstack import *
|
|
|
|
from ansible.module_utils.cloudstack import *
|
|
|
|
|
|
|
|
|
|
|
@ -196,28 +190,26 @@ class AnsibleCloudStackAccount(AnsibleCloudStack):
|
|
|
|
'domain_admin': 2,
|
|
|
|
'domain_admin': 2,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_account_type(self):
|
|
|
|
def get_account_type(self):
|
|
|
|
account_type = self.module.params.get('account_type')
|
|
|
|
account_type = self.module.params.get('account_type')
|
|
|
|
return self.account_types[account_type]
|
|
|
|
return self.account_types[account_type]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_account(self):
|
|
|
|
def get_account(self):
|
|
|
|
if not self.account:
|
|
|
|
if not self.account:
|
|
|
|
args = {}
|
|
|
|
args = {
|
|
|
|
args['listall'] = True
|
|
|
|
'listall': True,
|
|
|
|
args['domainid'] = self.get_domain('id')
|
|
|
|
'domainid': self.get_domain(key='id'),
|
|
|
|
|
|
|
|
}
|
|
|
|
accounts = self.cs.listAccounts(**args)
|
|
|
|
accounts = self.cs.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']:
|
|
|
|
if account_name in [ a['name'] ]:
|
|
|
|
if account_name == a['name']:
|
|
|
|
self.account = a
|
|
|
|
self.account = a
|
|
|
|
break
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
return self.account
|
|
|
|
return self.account
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def enable_account(self):
|
|
|
|
def enable_account(self):
|
|
|
|
account = self.get_account()
|
|
|
|
account = self.get_account()
|
|
|
|
if not account:
|
|
|
|
if not account:
|
|
|
@ -225,10 +217,11 @@ class AnsibleCloudStackAccount(AnsibleCloudStack):
|
|
|
|
|
|
|
|
|
|
|
|
if account['state'].lower() != 'enabled':
|
|
|
|
if account['state'].lower() != 'enabled':
|
|
|
|
self.result['changed'] = True
|
|
|
|
self.result['changed'] = True
|
|
|
|
args = {}
|
|
|
|
args = {
|
|
|
|
args['id'] = account['id']
|
|
|
|
'id': account['id'],
|
|
|
|
args['account'] = self.module.params.get('name')
|
|
|
|
'account': self.module.params.get('name'),
|
|
|
|
args['domainid'] = self.get_domain('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.cs.enableAccount(**args)
|
|
|
|
if 'errortext' in res:
|
|
|
|
if 'errortext' in res:
|
|
|
@ -236,15 +229,12 @@ class AnsibleCloudStackAccount(AnsibleCloudStack):
|
|
|
|
account = res['account']
|
|
|
|
account = res['account']
|
|
|
|
return account
|
|
|
|
return account
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def lock_account(self):
|
|
|
|
def lock_account(self):
|
|
|
|
return self.lock_or_disable_account(lock=True)
|
|
|
|
return self.lock_or_disable_account(lock=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def disable_account(self):
|
|
|
|
def disable_account(self):
|
|
|
|
return self.lock_or_disable_account()
|
|
|
|
return self.lock_or_disable_account()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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:
|
|
|
@ -254,14 +244,15 @@ class AnsibleCloudStackAccount(AnsibleCloudStack):
|
|
|
|
if lock and account['state'].lower() == 'disabled':
|
|
|
|
if lock and account['state'].lower() == 'disabled':
|
|
|
|
account = self.enable_account()
|
|
|
|
account = self.enable_account()
|
|
|
|
|
|
|
|
|
|
|
|
if lock and account['state'].lower() != 'locked' \
|
|
|
|
if (lock and account['state'].lower() != 'locked' or
|
|
|
|
or not lock and account['state'].lower() != 'disabled':
|
|
|
|
not lock and account['state'].lower() != 'disabled'):
|
|
|
|
self.result['changed'] = True
|
|
|
|
self.result['changed'] = True
|
|
|
|
args = {}
|
|
|
|
args = {
|
|
|
|
args['id'] = account['id']
|
|
|
|
'id': account['id'],
|
|
|
|
args['account'] = self.module.params.get('name')
|
|
|
|
'account': self.module.params.get('name'),
|
|
|
|
args['domainid'] = self.get_domain('id')
|
|
|
|
'domainid': self.get_domain(key='id'),
|
|
|
|
args['lock'] = lock
|
|
|
|
'lock': lock,
|
|
|
|
|
|
|
|
}
|
|
|
|
if not self.module.check_mode:
|
|
|
|
if not self.module.check_mode:
|
|
|
|
account = self.cs.disableAccount(**args)
|
|
|
|
account = self.cs.disableAccount(**args)
|
|
|
|
|
|
|
|
|
|
|
@ -270,42 +261,36 @@ class AnsibleCloudStackAccount(AnsibleCloudStack):
|
|
|
|
|
|
|
|
|
|
|
|
poll_async = self.module.params.get('poll_async')
|
|
|
|
poll_async = self.module.params.get('poll_async')
|
|
|
|
if poll_async:
|
|
|
|
if poll_async:
|
|
|
|
account = self._poll_job(account, 'account')
|
|
|
|
account = self.poll_job(account, 'account')
|
|
|
|
return account
|
|
|
|
return account
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def present_account(self):
|
|
|
|
def present_account(self):
|
|
|
|
missing_params = []
|
|
|
|
required_params = [
|
|
|
|
|
|
|
|
|
|
|
|
missing_params = []
|
|
|
|
|
|
|
|
for required_params in [
|
|
|
|
|
|
|
|
'email',
|
|
|
|
'email',
|
|
|
|
'username',
|
|
|
|
'username',
|
|
|
|
'password',
|
|
|
|
'password',
|
|
|
|
'first_name',
|
|
|
|
'first_name',
|
|
|
|
'last_name',
|
|
|
|
'last_name',
|
|
|
|
]:
|
|
|
|
]
|
|
|
|
if not self.module.params.get(required_params):
|
|
|
|
self.module.fail_on_missing_params(required_params=required_params)
|
|
|
|
missing_params.append(required_params)
|
|
|
|
|
|
|
|
if missing_params:
|
|
|
|
|
|
|
|
self.module.fail_json(msg="missing required arguments: %s" % ','.join(missing_params))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
account = self.get_account()
|
|
|
|
account = self.get_account()
|
|
|
|
|
|
|
|
|
|
|
|
if not account:
|
|
|
|
if not account:
|
|
|
|
self.result['changed'] = True
|
|
|
|
self.result['changed'] = True
|
|
|
|
|
|
|
|
|
|
|
|
args = {}
|
|
|
|
args = {
|
|
|
|
args['account'] = self.module.params.get('name')
|
|
|
|
'account': self.module.params.get('name'),
|
|
|
|
args['domainid'] = self.get_domain('id')
|
|
|
|
'domainid': self.get_domain(key='id'),
|
|
|
|
args['accounttype'] = self.get_account_type()
|
|
|
|
'accounttype': self.get_account_type(),
|
|
|
|
args['networkdomain'] = self.module.params.get('network_domain')
|
|
|
|
'networkdomain': self.module.params.get('network_domain'),
|
|
|
|
args['username'] = self.module.params.get('username')
|
|
|
|
'username': self.module.params.get('username'),
|
|
|
|
args['password'] = self.module.params.get('password')
|
|
|
|
'password': self.module.params.get('password'),
|
|
|
|
args['firstname'] = self.module.params.get('first_name')
|
|
|
|
'firstname': self.module.params.get('first_name'),
|
|
|
|
args['lastname'] = self.module.params.get('last_name')
|
|
|
|
'lastname': self.module.params.get('last_name'),
|
|
|
|
args['email'] = self.module.params.get('email')
|
|
|
|
'email': self.module.params.get('email'),
|
|
|
|
args['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.cs.createAccount(**args)
|
|
|
|
if 'errortext' in res:
|
|
|
|
if 'errortext' in res:
|
|
|
@ -313,7 +298,6 @@ class AnsibleCloudStackAccount(AnsibleCloudStack):
|
|
|
|
account = res['account']
|
|
|
|
account = res['account']
|
|
|
|
return account
|
|
|
|
return account
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def absent_account(self):
|
|
|
|
def absent_account(self):
|
|
|
|
account = self.get_account()
|
|
|
|
account = self.get_account()
|
|
|
|
if account:
|
|
|
|
if account:
|
|
|
@ -327,10 +311,9 @@ class AnsibleCloudStackAccount(AnsibleCloudStack):
|
|
|
|
|
|
|
|
|
|
|
|
poll_async = self.module.params.get('poll_async')
|
|
|
|
poll_async = self.module.params.get('poll_async')
|
|
|
|
if poll_async:
|
|
|
|
if poll_async:
|
|
|
|
res = self._poll_job(res, 'account')
|
|
|
|
self.poll_job(res, 'account')
|
|
|
|
return account
|
|
|
|
return account
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_result(self, account):
|
|
|
|
def get_result(self, account):
|
|
|
|
super(AnsibleCloudStackAccount, self).get_result(account)
|
|
|
|
super(AnsibleCloudStackAccount, self).get_result(account)
|
|
|
|
if account:
|
|
|
|
if account:
|
|
|
@ -365,9 +348,6 @@ def main():
|
|
|
|
supports_check_mode=True
|
|
|
|
supports_check_mode=True
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if not has_lib_cs:
|
|
|
|
|
|
|
|
module.fail_json(msg="python library cs required: pip install cs")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
acs_acc = AnsibleCloudStackAccount(module)
|
|
|
|
acs_acc = AnsibleCloudStackAccount(module)
|
|
|
|
|
|
|
|
|
|
|
|