1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Merge pull request #3763 from j2sol/rax-updates

Update rax to sync with rax_clb_nodes
This commit is contained in:
Michael DeHaan 2013-08-11 13:37:25 -07:00
commit 4e5feb6322

View file

@ -32,10 +32,18 @@ options:
- Indicate desired state of the resource - Indicate desired state of the resource
choices: ['present', 'active', 'absent', 'deleted'] choices: ['present', 'active', 'absent', 'deleted']
default: present default: present
creds_file: credentials:
description: description:
- File to find the Rackspace Public Cloud credentials in - File to find the Rackspace credentials in (ignored if C(api_key) and
C(username) are provided)
default: null default: null
aliases: ['creds_file']
api_key:
description:
- Rackspace API key (overrides C(credentials))
username:
description:
- Rackspace username (overrides C(credentials))
name: name:
description: description:
- Name to give the instance - Name to give the instance
@ -64,7 +72,7 @@ options:
region: region:
description: description:
- Region to create an instance in - Region to create an instance in
default: null default: DFW
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
@ -77,16 +85,19 @@ options:
requirements: [ "pyrax" ] requirements: [ "pyrax" ]
author: Jesse Keating author: Jesse Keating
notes: notes:
- Two environment variables can be used, RAX_CREDS and RAX_REGION. - The following environment variables can be used, C(RAX_USERNAME),
- RAX_CREDS points to a credentials file appropriate for pyrax C(RAX_API_KEY), C(RAX_CREDS), C(RAX_CREDENTIALS), C(RAX_REGION).
- RAX_REGION defines a Rackspace Public Cloud region (DFW, ORD, LON, ...) - C(RAX_CREDENTIALS) and C(RAX_CREDS) points to a credentials file
appropriate for pyrax
- C(RAX_USERNAME) and C(RAX_API_KEY) obviate the use of a credentials file
- C(RAX_REGION) defines a Rackspace Public Cloud region (DFW, ORD, LON, ...)
''' '''
EXAMPLES = ''' EXAMPLES = '''
# Create a server # Create a server
- local_action: - local_action:
module: rax module: rax
creds_file: ~/.raxpub credentials: ~/.raxpub
service: cloudservers service: cloudservers
name: rax-test1 name: rax-test1
flavor: 5 flavor: 5
@ -208,7 +219,9 @@ def main():
service = dict(default='cloudservers', choices=SUPPORTEDSERVICES), service = dict(default='cloudservers', choices=SUPPORTEDSERVICES),
state = dict(default='present', choices=['active', 'present', state = dict(default='present', choices=['active', 'present',
'deleted', 'absent']), 'deleted', 'absent']),
creds_file = dict(), credentials = dict(aliases = ['creds_file']),
api_key=dict(),
username=dict(),
name = dict(), name = dict(),
flavor = dict(), flavor = dict(),
image = dict(), image = dict(),
@ -223,7 +236,9 @@ def main():
service = module.params.get('service') service = module.params.get('service')
state = module.params.get('state') state = module.params.get('state')
creds_file = module.params.get('creds_file') credentials = module.params.get('credentials')
api_key = module.params.get('api_key')
username = module.params.get('username')
name = module.params.get('name') name = module.params.get('name')
flavor = module.params.get('flavor') flavor = module.params.get('flavor')
image = module.params.get('image') image = module.params.get('image')
@ -234,24 +249,27 @@ def main():
wait = module.params.get('wait') wait = module.params.get('wait')
wait_timeout = int(module.params.get('wait_timeout')) wait_timeout = int(module.params.get('wait_timeout'))
# Setup the credentials file # Setup the credentials and region
if not creds_file:
try: try:
creds_file = os.environ['RAX_CREDS_FILE'] username = username or os.environ.get('RAX_USERNAME')
except KeyError, e: api_key = api_key or os.environ.get('RAX_API_KEY')
module.fail_json(msg = 'Unable to load %s' % e.message) credentials = credentials or os.environ.get('RAX_CREDENTIALS') or \
os.environ.get('RAX_CREDS_FILE')
region = region or os.environ.get('RAX_REGION')
# Define the region
if not region:
try:
region = os.environ['RAX_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)
# setup the auth # setup the auth
try: try:
pyrax.set_setting("identity_type", "rackspace") pyrax.set_setting("identity_type", "rackspace")
pyrax.set_credential_file(creds_file, region=region) if api_key and username:
pyrax.set_credentials(username, api_key=api_key, region=region)
elif credentials:
credentials = os.path.expanduser(credentials)
pyrax.set_credential_file(credentials, region=region)
else:
raise Exception('No credentials supplied!')
except Exception, e: except Exception, e:
module.fail_json(msg = '%s' % e.message) module.fail_json(msg = '%s' % e.message)