Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update rax to sync with rax_clb_nodes #3763

Merged
merged 1 commit into from
Aug 11, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
62 changes: 40 additions & 22 deletions library/cloud/rax
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,18 @@ options:
- Indicate desired state of the resource
choices: ['present', 'active', 'absent', 'deleted']
default: present
creds_file:
credentials:
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
aliases: ['creds_file']
api_key:
description:
- Rackspace API key (overrides C(credentials))
username:
description:
- Rackspace username (overrides C(credentials))
name:
description:
- Name to give the instance
Expand Down Expand Up @@ -64,7 +72,7 @@ options:
region:
description:
- Region to create an instance in
default: null
default: DFW
wait:
description:
- wait for the instance to be in state 'running' before returning
Expand All @@ -77,16 +85,19 @@ options:
requirements: [ "pyrax" ]
author: Jesse Keating
notes:
- Two environment variables can be used, RAX_CREDS and RAX_REGION.
- RAX_CREDS points to a credentials file appropriate for pyrax
- RAX_REGION defines a Rackspace Public Cloud region (DFW, ORD, LON, ...)
- The following environment variables can be used, C(RAX_USERNAME),
C(RAX_API_KEY), C(RAX_CREDS), C(RAX_CREDENTIALS), C(RAX_REGION).
- 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 = '''
# Create a server
- local_action:
module: rax
creds_file: ~/.raxpub
credentials: ~/.raxpub
service: cloudservers
name: rax-test1
flavor: 5
Expand Down Expand Up @@ -208,7 +219,9 @@ def main():
service = dict(default='cloudservers', choices=SUPPORTEDSERVICES),
state = dict(default='present', choices=['active', 'present',
'deleted', 'absent']),
creds_file = dict(),
credentials = dict(aliases = ['creds_file']),
api_key=dict(),
username=dict(),
name = dict(),
flavor = dict(),
image = dict(),
Expand All @@ -223,7 +236,9 @@ def main():

service = module.params.get('service')
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')
flavor = module.params.get('flavor')
image = module.params.get('image')
Expand All @@ -234,24 +249,27 @@ def main():
wait = module.params.get('wait')
wait_timeout = int(module.params.get('wait_timeout'))

# Setup the credentials file
if not creds_file:
try:
creds_file = os.environ['RAX_CREDS_FILE']
except KeyError, e:
module.fail_json(msg = 'Unable to load %s' % e.message)
# Setup the credentials and region
try:
username = username or os.environ.get('RAX_USERNAME')
api_key = api_key or os.environ.get('RAX_API_KEY')
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:
module.fail_json(msg = 'Unable to load %s' % e.message)
except KeyError, e:
module.fail_json(msg = 'Unable to load %s' % e.message)

# setup the auth
try:
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:
module.fail_json(msg = '%s' % e.message)

Expand Down