2013-11-19 18:51:04 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
def rax_argument_spec():
|
|
|
|
return dict(
|
2014-01-24 01:54:37 +00:00
|
|
|
api_key=dict(type='str', aliases=['password'], no_log=True),
|
2014-01-24 17:34:21 +00:00
|
|
|
auth_endpoint=dict(type='str'),
|
2013-11-19 18:51:04 +00:00
|
|
|
credentials=dict(type='str', aliases=['creds_file']),
|
2014-01-24 17:34:21 +00:00
|
|
|
env=dict(type='str'),
|
2014-01-24 01:54:37 +00:00
|
|
|
identity_type=dict(type='str', default='rackspace'),
|
2013-11-19 18:51:04 +00:00
|
|
|
region=dict(type='str'),
|
2014-01-24 01:54:37 +00:00
|
|
|
tenant_id=dict(type='str'),
|
2013-11-19 18:51:04 +00:00
|
|
|
username=dict(type='str'),
|
2014-01-24 17:34:21 +00:00
|
|
|
verify_ssl=dict(choices=BOOLEANS, type='bool'),
|
2013-11-19 18:51:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def rax_required_together():
|
|
|
|
return [['api_key', 'username']]
|
|
|
|
|
|
|
|
|
|
|
|
def setup_rax_module(module, rax_module):
|
|
|
|
api_key = module.params.get('api_key')
|
2014-01-24 01:54:37 +00:00
|
|
|
auth_endpoint = module.params.get('auth_endpoint')
|
2013-11-19 18:51:04 +00:00
|
|
|
credentials = module.params.get('credentials')
|
2014-01-24 17:34:21 +00:00
|
|
|
env = module.params.get('env')
|
2014-01-24 01:54:37 +00:00
|
|
|
identity_type = module.params.get('identity_type')
|
2013-11-19 18:51:04 +00:00
|
|
|
region = module.params.get('region')
|
2014-01-24 01:54:37 +00:00
|
|
|
tenant_id = module.params.get('tenant_id')
|
2013-11-19 18:51:04 +00:00
|
|
|
username = module.params.get('username')
|
2014-01-24 01:54:37 +00:00
|
|
|
verify_ssl = module.params.get('verify_ssl')
|
|
|
|
|
2014-01-24 17:34:21 +00:00
|
|
|
if env is not None:
|
|
|
|
rax_module.set_environment(env)
|
|
|
|
|
2014-01-24 01:54:37 +00:00
|
|
|
rax_module.set_setting('identity_type', identity_type)
|
2014-01-24 17:34:21 +00:00
|
|
|
if verify_ssl is not None:
|
|
|
|
rax_module.set_setting('verify_ssl', verify_ssl)
|
|
|
|
if auth_endpoint is not None:
|
|
|
|
rax_module.set_setting('auth_endpoint', auth_endpoint)
|
|
|
|
if tenant_id is not None:
|
2014-01-24 01:54:37 +00:00
|
|
|
rax_module.set_setting('tenant_id', tenant_id)
|
2013-11-19 18:51:04 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
username = username or os.environ.get('RAX_USERNAME')
|
2014-01-24 17:34:21 +00:00
|
|
|
if not username:
|
|
|
|
username = rax_module.get_setting('keyring_username')
|
|
|
|
api_key = 'USE_KEYRING'
|
|
|
|
if not api_key:
|
|
|
|
api_key = os.environ.get('RAX_API_KEY')
|
2013-11-19 18:51:04 +00:00
|
|
|
credentials = (credentials or os.environ.get('RAX_CREDENTIALS') or
|
|
|
|
os.environ.get('RAX_CREDS_FILE'))
|
2014-01-24 17:34:21 +00:00
|
|
|
region = (region or os.environ.get('RAX_REGION') or
|
|
|
|
rax_module.get_setting('region'))
|
2013-11-19 18:51:04 +00:00
|
|
|
except KeyError, e:
|
|
|
|
module.fail_json(msg='Unable to load %s' % e.message)
|
|
|
|
|
|
|
|
try:
|
|
|
|
if api_key and username:
|
2014-01-24 01:52:32 +00:00
|
|
|
if api_key == 'USE_KEYRING':
|
|
|
|
rax_module.keyring_auth(username)
|
|
|
|
else:
|
|
|
|
rax_module.set_credentials(username, api_key=api_key,
|
|
|
|
region=region)
|
2013-11-19 18:51:04 +00:00
|
|
|
elif credentials:
|
|
|
|
credentials = os.path.expanduser(credentials)
|
|
|
|
rax_module.set_credential_file(credentials, region=region)
|
|
|
|
else:
|
|
|
|
raise Exception('No credentials supplied!')
|
|
|
|
except Exception, e:
|
|
|
|
module.fail_json(msg='%s' % e.message)
|
|
|
|
|
|
|
|
return rax_module
|