Support arbitrary extra args in rax module

Add extra_create_args and extra_client_args to rax module to support passing
advanced configuration options to client instantiation and server create calls.
pull/6707/head
Matt Martz 11 years ago
parent 2ce77b8ccf
commit e093b216ff

@ -98,6 +98,17 @@ options:
state=active/present state=active/present
default: no default: no
version_added: 1.4 version_added: 1.4
extra_client_args:
description:
- A hash of key/value pairs to be used when creating the cloudservers
client. This is considered an advanced option, use it wisely and
with caution.
version_added: 1.6
extra_create_args:
description:
- A hash of key/value pairs to be used when creating a new server.
This is considered an advanced option, use it wisely and with caution.
version_added: 1.6
files: files:
description: description:
- Files to insert into the instance. remotefilename:localcontent - Files to insert into the instance. remotefilename:localcontent
@ -246,7 +257,8 @@ def pyrax_object_to_dict(obj):
def create(module, names, flavor, image, meta, key_name, files, def create(module, names, flavor, image, meta, key_name, files,
wait, wait_timeout, disk_config, group, nics): wait, wait_timeout, disk_config, group, nics,
extra_create_args):
cs = pyrax.cloudservers cs = pyrax.cloudservers
changed = False changed = False
@ -266,7 +278,8 @@ def create(module, names, flavor, image, meta, key_name, files,
flavor=flavor, meta=meta, flavor=flavor, meta=meta,
key_name=key_name, key_name=key_name,
files=files, nics=nics, files=files, nics=nics,
disk_config=disk_config)) disk_config=disk_config,
**extra_create_args))
except Exception, e: except Exception, e:
module.fail_json(msg='%s' % e.message) module.fail_json(msg='%s' % e.message)
else: else:
@ -405,7 +418,7 @@ def delete(module, instance_ids, wait, wait_timeout):
def cloudservers(module, state, name, flavor, image, meta, key_name, files, def cloudservers(module, state, name, flavor, image, meta, key_name, files,
wait, wait_timeout, disk_config, count, group, wait, wait_timeout, disk_config, count, group,
instance_ids, exact_count, networks, count_offset, instance_ids, exact_count, networks, count_offset,
auto_increment): auto_increment, extra_create_args):
cs = pyrax.cloudservers cs = pyrax.cloudservers
cnw = pyrax.cloud_networks cnw = pyrax.cloud_networks
servers = [] servers = []
@ -602,7 +615,7 @@ def cloudservers(module, state, name, flavor, image, meta, key_name, files,
names = [name] * (count - len(servers)) names = [name] * (count - len(servers))
create(module, names, flavor, image, meta, key_name, files, create(module, names, flavor, image, meta, key_name, files,
wait, wait_timeout, disk_config, group, nics) wait, wait_timeout, disk_config, group, nics, extra_create_args)
elif state == 'absent': elif state == 'absent':
if instance_ids is None: if instance_ids is None:
@ -647,6 +660,8 @@ def main():
count_offset=dict(default=1, type='int'), count_offset=dict(default=1, type='int'),
disk_config=dict(choices=['auto', 'manual']), disk_config=dict(choices=['auto', 'manual']),
exact_count=dict(default=False, type='bool'), exact_count=dict(default=False, type='bool'),
extra_client_args=dict(type='dict', default={}),
extra_create_args=dict(type='dict', default={}),
files=dict(type='dict', default={}), files=dict(type='dict', default={}),
flavor=dict(), flavor=dict(),
group=dict(), group=dict(),
@ -682,6 +697,8 @@ def main():
if disk_config: if disk_config:
disk_config = disk_config.upper() disk_config = disk_config.upper()
exact_count = module.params.get('exact_count', False) exact_count = module.params.get('exact_count', False)
extra_client_args = module.params.get('extra_client_args')
extra_create_args = module.params.get('extra_create_args')
files = module.params.get('files') files = module.params.get('files')
flavor = module.params.get('flavor') flavor = module.params.get('flavor')
group = module.params.get('group') group = module.params.get('group')
@ -697,10 +714,23 @@ def main():
setup_rax_module(module, pyrax) setup_rax_module(module, pyrax)
if pyrax.cloudservers is None:
module.fail_json(msg='Failed to instantiate client. This '
'typically indicates an invalid region or an '
'incorrectly capitalized region name.')
if extra_client_args:
pyrax.cloudservers = pyrax.connect_to_cloudservers(
region=pyrax.cloudservers.client.region_name,
**extra_client_args)
client = pyrax.cloudservers.client
if 'bypass_url' in extra_client_args:
client.management_url = extra_client_args['bypass_url']
cloudservers(module, state, name, flavor, image, meta, key_name, files, cloudservers(module, state, name, flavor, image, meta, key_name, files,
wait, wait_timeout, disk_config, count, group, wait, wait_timeout, disk_config, count, group,
instance_ids, exact_count, networks, count_offset, instance_ids, exact_count, networks, count_offset,
auto_increment) auto_increment, extra_create_args)
# import module snippets # import module snippets

Loading…
Cancel
Save