Utilize ansible.module_utils.rax

reviewable/pr18780/r1
Matt Martz 11 years ago
parent 4a0efeceab
commit 77377be11c

@ -41,7 +41,7 @@ options:
default: null default: null
region: region:
description: description:
- Region to create the load balancer in - Region to create the key pair in
default: DFW default: DFW
username: username:
description: description:
@ -89,7 +89,6 @@ EXAMPLES = '''
''' '''
import sys import sys
import os
from types import NoneType from types import NoneType
@ -148,49 +147,32 @@ def rax_keypair(module, name, public_key, state):
def main(): def main():
module = AnsibleModule( argument_spec = rax_argument_spec()
argument_spec=dict( argument_spec.update(
api_key=dict(), dict(
credentials=dict(aliases=['creds_file']),
name=dict(), name=dict(),
public_key=dict(), public_key=dict(),
region=dict(),
state=dict(default='present', choices=['absent', 'present']), state=dict(default='present', choices=['absent', 'present']),
username=dict(), )
), )
module = AnsibleModule(
argument_spec=argument_spec,
required_together=rax_required_together(),
) )
api_key = module.params.get('api_key')
credentials = module.params.get('credentials')
name = module.params.get('name') name = module.params.get('name')
public_key = module.params.get('public_key') public_key = module.params.get('public_key')
region = module.params.get('region')
state = module.params.get('state') state = module.params.get('state')
username = module.params.get('username')
try: setup_rax_module(module, pyrax)
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')
except KeyError, e:
module.fail_json(msg='Unable to load %s' % e.message)
try:
pyrax.set_setting('identity_type', 'rackspace')
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)
rax_keypair(module, name, public_key, state) rax_keypair(module, name, public_key, state)
# import module snippets
from ansible.module_utils.basic import * from ansible.module_utils.basic import *
from ansible.module_utils.rax import *
### invoke the module
main() main()

Loading…
Cancel
Save