Merge pull request #5806 from sivel/rax-mod-utils-improvements

Rax mod utils improvements
This commit is contained in:
jctanner 2014-01-29 16:17:06 -08:00
commit 360f06b41d
2 changed files with 82 additions and 20 deletions

View file

@ -3,10 +3,16 @@ import os
def rax_argument_spec(): def rax_argument_spec():
return dict( return dict(
api_key=dict(type='str', no_log=True), api_key=dict(type='str', aliases=['password'], no_log=True),
auth_endpoint=dict(type='str'),
credentials=dict(type='str', aliases=['creds_file']), credentials=dict(type='str', aliases=['creds_file']),
env=dict(type='str'),
identity_type=dict(type='str', default='rackspace'),
region=dict(type='str'), region=dict(type='str'),
tenant_id=dict(type='str'),
tenant_name=dict(type='str'),
username=dict(type='str'), username=dict(type='str'),
verify_ssl=dict(choices=BOOLEANS, type='bool'),
) )
@ -16,25 +22,51 @@ def rax_required_together():
def setup_rax_module(module, rax_module): def setup_rax_module(module, rax_module):
api_key = module.params.get('api_key') api_key = module.params.get('api_key')
auth_endpoint = module.params.get('auth_endpoint')
credentials = module.params.get('credentials') credentials = module.params.get('credentials')
env = module.params.get('env')
identity_type = module.params.get('identity_type')
region = module.params.get('region') region = module.params.get('region')
tenant_id = module.params.get('tenant_id')
tenant_name = module.params.get('tenant_name')
username = module.params.get('username') username = module.params.get('username')
verify_ssl = module.params.get('verify_ssl')
if env is not None:
rax_module.set_environment(env)
rax_module.set_setting('identity_type', identity_type)
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:
rax_module.set_setting('tenant_id', tenant_id)
if tenant_name is not None:
rax_module.set_setting('tenant_name', tenant_name)
try: try:
username = username or os.environ.get('RAX_USERNAME') username = username or os.environ.get('RAX_USERNAME')
api_key = api_key or os.environ.get('RAX_API_KEY') if not username:
username = rax_module.get_setting('keyring_username')
if username:
api_key = 'USE_KEYRING'
if not api_key:
api_key = os.environ.get('RAX_API_KEY')
credentials = (credentials or os.environ.get('RAX_CREDENTIALS') or credentials = (credentials or os.environ.get('RAX_CREDENTIALS') or
os.environ.get('RAX_CREDS_FILE')) os.environ.get('RAX_CREDS_FILE'))
region = region or os.environ.get('RAX_REGION') region = (region or os.environ.get('RAX_REGION') or
rax_module.get_setting('region'))
except KeyError, e: except KeyError, e:
module.fail_json(msg='Unable to load %s' % e.message) module.fail_json(msg='Unable to load %s' % e.message)
try: try:
rax_module.set_setting('identity_type', 'rackspace')
if api_key and username: if api_key and username:
rax_module.set_credentials(username, api_key=api_key, if api_key == 'USE_KEYRING':
region=region) rax_module.keyring_auth(username, region=region)
else:
rax_module.set_credentials(username, api_key=api_key,
region=region)
elif credentials: elif credentials:
credentials = os.path.expanduser(credentials) credentials = os.path.expanduser(credentials)
rax_module.set_credential_file(credentials, region=region) rax_module.set_credential_file(credentials, region=region)

View file

@ -26,6 +26,49 @@ options:
api_key: api_key:
description: description:
- Rackspace API key (overrides I(credentials)) - Rackspace API key (overrides I(credentials))
aliases:
- password
auth_endpoint:
description:
- The URI of the authentication service
default: https://identity.api.rackspacecloud.com/v2.0/
version_added: 1.5
credentials:
description:
- File to find the Rackspace credentials in (ignored if I(api_key) and
I(username) are provided)
default: null
aliases:
- creds_file
env:
description:
- Environment as configured in ~/.pyrax.cfg,
see U(https://github.com/rackspace/pyrax/blob/master/docs/getting_started.md#pyrax-configuration)
version_added: 1.5
identity_type:
description:
- Authentication machanism to use, such as rackspace or keystone
default: rackspace
version_added: 1.5
region:
description:
- Region to create an instance in
default: DFW
tenant_id:
description:
- The tenant ID used for authentication
version_added: 1.5
tenant_name:
description:
- The tenant name used for authentication
version_added: 1.5
username:
description:
- Rackspace username (overrides I(credentials))
verify_ssl:
description:
- Whether or not to require SSL validation of API endpoints
version_added: 1.5
auto_increment: auto_increment:
description: description:
- Whether or not to increment a single number with the name of the - Whether or not to increment a single number with the name of the
@ -43,12 +86,6 @@ options:
- number count to start at - number count to start at
default: 1 default: 1
version_added: 1.4 version_added: 1.4
credentials:
description:
- File to find the Rackspace credentials in (ignored if I(api_key) and
I(username) are provided)
default: null
aliases: ['creds_file']
disk_config: disk_config:
description: description:
- Disk partitioning strategy - Disk partitioning strategy
@ -103,18 +140,11 @@ options:
or C(label). or C(label).
default: ['public', 'private'] default: ['public', 'private']
version_added: 1.4 version_added: 1.4
region:
description:
- Region to create an instance in
default: DFW
state: state:
description: description:
- Indicate desired state of the resource - Indicate desired state of the resource
choices: ['present', 'absent'] choices: ['present', 'absent']
default: present default: present
username:
description:
- Rackspace username (overrides I(credentials))
wait: wait:
description: description:
- wait for the instance to be in state 'running' before returning - wait for the instance to be in state 'running' before returning