Support config_drive and user_data in rax_scaling_group
This commit is contained in:
parent
1c2995d71f
commit
0a399fd971
1 changed files with 40 additions and 6 deletions
|
@ -24,6 +24,14 @@ description:
|
||||||
- Manipulate Rackspace Cloud Autoscale Groups
|
- Manipulate Rackspace Cloud Autoscale Groups
|
||||||
version_added: 1.7
|
version_added: 1.7
|
||||||
options:
|
options:
|
||||||
|
config_drive:
|
||||||
|
description:
|
||||||
|
- Attach read-only configuration drive to server as label config-2
|
||||||
|
default: no
|
||||||
|
choices:
|
||||||
|
- "yes"
|
||||||
|
- "no"
|
||||||
|
version_added: 1.8
|
||||||
cooldown:
|
cooldown:
|
||||||
description:
|
description:
|
||||||
- The period of time, in seconds, that must pass before any scaling can
|
- The period of time, in seconds, that must pass before any scaling can
|
||||||
|
@ -92,6 +100,11 @@ options:
|
||||||
- present
|
- present
|
||||||
- absent
|
- absent
|
||||||
default: present
|
default: present
|
||||||
|
user_data:
|
||||||
|
description:
|
||||||
|
- Data to be uploaded to the servers config drive. This option implies
|
||||||
|
I(config_drive). Can be a file path or a string
|
||||||
|
version_added: 1.8
|
||||||
author: Matt Martz
|
author: Matt Martz
|
||||||
extends_documentation_fragment: rackspace
|
extends_documentation_fragment: rackspace
|
||||||
'''
|
'''
|
||||||
|
@ -128,17 +141,27 @@ except ImportError:
|
||||||
def rax_asg(module, cooldown=300, disk_config=None, files={}, flavor=None,
|
def rax_asg(module, cooldown=300, disk_config=None, files={}, flavor=None,
|
||||||
image=None, key_name=None, loadbalancers=[], meta={},
|
image=None, key_name=None, loadbalancers=[], meta={},
|
||||||
min_entities=0, max_entities=0, name=None, networks=[],
|
min_entities=0, max_entities=0, name=None, networks=[],
|
||||||
server_name=None, state='present'):
|
server_name=None, state='present', user_data=None,
|
||||||
|
config_drive=False):
|
||||||
changed = False
|
changed = False
|
||||||
|
|
||||||
au = pyrax.autoscale
|
au = pyrax.autoscale
|
||||||
cnw = pyrax.cloud_networks
|
if not au:
|
||||||
cs = pyrax.cloudservers
|
|
||||||
if not au or not cnw or not cs:
|
|
||||||
module.fail_json(msg='Failed to instantiate clients. This '
|
module.fail_json(msg='Failed to instantiate clients. This '
|
||||||
'typically indicates an invalid region or an '
|
'typically indicates an invalid region or an '
|
||||||
'incorrectly capitalized region name.')
|
'incorrectly capitalized region name.')
|
||||||
|
|
||||||
|
if user_data:
|
||||||
|
config_drive = True
|
||||||
|
|
||||||
|
if user_data and os.path.isfile(user_data):
|
||||||
|
try:
|
||||||
|
f = open(user_data)
|
||||||
|
user_data = f.read()
|
||||||
|
f.close()
|
||||||
|
except Exception, e:
|
||||||
|
module.fail_json(msg='Failed to load %s' % user_data)
|
||||||
|
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
# Normalize and ensure all metadata values are strings
|
# Normalize and ensure all metadata values are strings
|
||||||
if meta:
|
if meta:
|
||||||
|
@ -204,7 +227,8 @@ def rax_asg(module, cooldown=300, disk_config=None, files={}, flavor=None,
|
||||||
flavor=flavor, disk_config=disk_config,
|
flavor=flavor, disk_config=disk_config,
|
||||||
metadata=meta, personality=files,
|
metadata=meta, personality=files,
|
||||||
networks=nics, load_balancers=lbs,
|
networks=nics, load_balancers=lbs,
|
||||||
key_name=key_name)
|
key_name=key_name, config_drive=config_drive,
|
||||||
|
user_data=user_data)
|
||||||
changed = True
|
changed = True
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
module.fail_json(msg='%s' % e.message)
|
module.fail_json(msg='%s' % e.message)
|
||||||
|
@ -256,6 +280,12 @@ def rax_asg(module, cooldown=300, disk_config=None, files={}, flavor=None,
|
||||||
if key_name != lc.get('key_name'):
|
if key_name != lc.get('key_name'):
|
||||||
lc_args['key_name'] = key_name
|
lc_args['key_name'] = key_name
|
||||||
|
|
||||||
|
if config_drive != lc.get('config_drive'):
|
||||||
|
lc_args['config_drive'] = config_drive
|
||||||
|
|
||||||
|
if user_data != lc.get('user_data'):
|
||||||
|
lc_args['user_data'] = user_data
|
||||||
|
|
||||||
if lc_args:
|
if lc_args:
|
||||||
# Work around for https://github.com/rackspace/pyrax/pull/389
|
# Work around for https://github.com/rackspace/pyrax/pull/389
|
||||||
if 'flavor' not in lc_args:
|
if 'flavor' not in lc_args:
|
||||||
|
@ -284,6 +314,7 @@ def main():
|
||||||
argument_spec = rax_argument_spec()
|
argument_spec = rax_argument_spec()
|
||||||
argument_spec.update(
|
argument_spec.update(
|
||||||
dict(
|
dict(
|
||||||
|
config_drive=dict(default=False, type='bool'),
|
||||||
cooldown=dict(type='int', default=300),
|
cooldown=dict(type='int', default=300),
|
||||||
disk_config=dict(choices=['auto', 'manual']),
|
disk_config=dict(choices=['auto', 'manual']),
|
||||||
files=dict(type='list', default=[]),
|
files=dict(type='list', default=[]),
|
||||||
|
@ -298,6 +329,7 @@ def main():
|
||||||
networks=dict(type='list', default=['public', 'private']),
|
networks=dict(type='list', default=['public', 'private']),
|
||||||
server_name=dict(required=True),
|
server_name=dict(required=True),
|
||||||
state=dict(default='present', choices=['present', 'absent']),
|
state=dict(default='present', choices=['present', 'absent']),
|
||||||
|
user_data=dict(no_log=True),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -309,6 +341,7 @@ def main():
|
||||||
if not HAS_PYRAX:
|
if not HAS_PYRAX:
|
||||||
module.fail_json(msg='pyrax is required for this module')
|
module.fail_json(msg='pyrax is required for this module')
|
||||||
|
|
||||||
|
config_drive = module.params.get('config_drive')
|
||||||
cooldown = module.params.get('cooldown')
|
cooldown = module.params.get('cooldown')
|
||||||
disk_config = module.params.get('disk_config')
|
disk_config = module.params.get('disk_config')
|
||||||
if disk_config:
|
if disk_config:
|
||||||
|
@ -325,6 +358,7 @@ def main():
|
||||||
networks = module.params.get('networks')
|
networks = module.params.get('networks')
|
||||||
server_name = module.params.get('server_name')
|
server_name = module.params.get('server_name')
|
||||||
state = module.params.get('state')
|
state = module.params.get('state')
|
||||||
|
user_data = module.params.get('user_data')
|
||||||
|
|
||||||
if not 0 <= min_entities <= 1000 or not 0 <= max_entities <= 1000:
|
if not 0 <= min_entities <= 1000 or not 0 <= max_entities <= 1000:
|
||||||
module.fail_json(msg='min_entities and max_entities must be an '
|
module.fail_json(msg='min_entities and max_entities must be an '
|
||||||
|
@ -340,7 +374,7 @@ def main():
|
||||||
key_name=key_name, loadbalancers=loadbalancers,
|
key_name=key_name, loadbalancers=loadbalancers,
|
||||||
min_entities=min_entities, max_entities=max_entities,
|
min_entities=min_entities, max_entities=max_entities,
|
||||||
name=name, networks=networks, server_name=server_name,
|
name=name, networks=networks, server_name=server_name,
|
||||||
state=state)
|
state=state, config_drive=config_drive, user_data=user_data)
|
||||||
|
|
||||||
|
|
||||||
# import module snippets
|
# import module snippets
|
||||||
|
|
Loading…
Reference in a new issue