mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix up docs and add ability to insert files
Files can be inserted during server creation (like a fully formed authorized_keys file). This code allows that to happen. Docs were updated for formatting, location, and to add the new entry for files.
This commit is contained in:
parent
c47fd199bd
commit
34e585024c
1 changed files with 32 additions and 14 deletions
34
library/rax
34
library/rax
|
@ -54,12 +54,20 @@ options:
|
||||||
- image to use for the instance
|
- image to use for the instance
|
||||||
required: false
|
required: false
|
||||||
default: null
|
default: null
|
||||||
|
meta:
|
||||||
|
description:
|
||||||
|
- A hash of metadata to associate with the instance
|
||||||
|
default: null
|
||||||
key_name:
|
key_name:
|
||||||
description:
|
description:
|
||||||
- key pair to use on the instance
|
- key pair to use on the instance
|
||||||
required: false
|
required: false
|
||||||
default: null
|
default: null
|
||||||
aliases: ['keypair']
|
aliases: ['keypair']
|
||||||
|
files:
|
||||||
|
description:
|
||||||
|
- Files to insert into the instance. remotefilename:localcontent
|
||||||
|
default: null
|
||||||
region:
|
region:
|
||||||
description:
|
description:
|
||||||
- Region to create an instance in
|
- Region to create an instance in
|
||||||
|
@ -99,8 +107,8 @@ except ImportError:
|
||||||
SUPPORTEDSERVICES = ['cloudservers', 'cloudfiles', 'cloud_blockstorage',
|
SUPPORTEDSERVICES = ['cloudservers', 'cloudfiles', 'cloud_blockstorage',
|
||||||
'cloud_databases', 'cloud_loadbalancers']
|
'cloud_databases', 'cloud_loadbalancers']
|
||||||
|
|
||||||
def cloudservers(module, state, name, flavor, image, meta, key_name, wait,
|
def cloudservers(module, state, name, flavor, image, meta, key_name, files,
|
||||||
wait_timeout):
|
wait, wait_timeout):
|
||||||
# Check our args (this could be done better)
|
# Check our args (this could be done better)
|
||||||
for arg in (state, name, flavor, image):
|
for arg in (state, name, flavor, image):
|
||||||
if not arg:
|
if not arg:
|
||||||
|
@ -124,14 +132,22 @@ def cloudservers(module, state, name, flavor, image, meta, key_name, wait,
|
||||||
|
|
||||||
# act on the state
|
# act on the state
|
||||||
if state in ('active', 'present'):
|
if state in ('active', 'present'):
|
||||||
# See if we already have any servers:
|
|
||||||
if not servers:
|
if not servers:
|
||||||
|
# Handle the file contents
|
||||||
|
for rpath in files.keys():
|
||||||
|
lpath = os.path.expanduser(files[rpath])
|
||||||
|
try:
|
||||||
|
fileobj = open(lpath, 'r')
|
||||||
|
files[rpath] = fileobj
|
||||||
|
except Exception, e:
|
||||||
|
module.fail_json(msg = 'Failed to load %s' % lpath)
|
||||||
try:
|
try:
|
||||||
servers = [pyrax.cloudservers.servers.create(name=name,
|
servers = [pyrax.cloudservers.servers.create(name=name,
|
||||||
image=image,
|
image=image,
|
||||||
flavor=flavor,
|
flavor=flavor,
|
||||||
key_name=key_name,
|
key_name=key_name,
|
||||||
meta=meta)]
|
meta=meta,
|
||||||
|
files=files)]
|
||||||
changed = True
|
changed = True
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
module.fail_json(msg = '%s' % e.message)
|
module.fail_json(msg = '%s' % e.message)
|
||||||
|
@ -188,10 +204,11 @@ def main():
|
||||||
'deleted', 'absent']),
|
'deleted', 'absent']),
|
||||||
creds_file = dict(),
|
creds_file = dict(),
|
||||||
name = dict(),
|
name = dict(),
|
||||||
key_name = dict(aliases = ['keypair']),
|
|
||||||
flavor = dict(),
|
flavor = dict(),
|
||||||
image = dict(),
|
image = dict(),
|
||||||
meta = dict(type='dict', default={}),
|
meta = dict(type='dict', default={}),
|
||||||
|
key_name = dict(aliases = ['keypair']),
|
||||||
|
files = dict(type='dict', default={}),
|
||||||
region = dict(),
|
region = dict(),
|
||||||
wait = dict(type='bool', choices=BOOLEANS),
|
wait = dict(type='bool', choices=BOOLEANS),
|
||||||
wait_timeout = dict(default=300),
|
wait_timeout = dict(default=300),
|
||||||
|
@ -202,10 +219,11 @@ def main():
|
||||||
state = module.params.get('state')
|
state = module.params.get('state')
|
||||||
creds_file = module.params.get('creds_file')
|
creds_file = module.params.get('creds_file')
|
||||||
name = module.params.get('name')
|
name = module.params.get('name')
|
||||||
key_name = module.params.get('key_name')
|
|
||||||
flavor = module.params.get('flavor')
|
flavor = module.params.get('flavor')
|
||||||
image = module.params.get('image')
|
image = module.params.get('image')
|
||||||
meta = module.params.get('meta')
|
meta = module.params.get('meta')
|
||||||
|
key_name = module.params.get('key_name')
|
||||||
|
files = module.params.get('files')
|
||||||
region = module.params.get('region')
|
region = module.params.get('region')
|
||||||
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'))
|
||||||
|
@ -233,8 +251,8 @@ def main():
|
||||||
|
|
||||||
# Act based on service
|
# Act based on service
|
||||||
if service == 'cloudservers':
|
if service == 'cloudservers':
|
||||||
cloudservers(module, state, name, flavor, image, meta, key_name, wait,
|
cloudservers(module, state, name, flavor, image, meta, key_name, files,
|
||||||
wait_timeout)
|
wait, wait_timeout)
|
||||||
elif service in ['cloudfiles', 'cloud_blockstorage',
|
elif service in ['cloudfiles', 'cloud_blockstorage',
|
||||||
'cloud_databases', 'cloud_loadbalancers']:
|
'cloud_databases', 'cloud_loadbalancers']:
|
||||||
module.fail_json(msg = 'Service %s is not supported at this time' %
|
module.fail_json(msg = 'Service %s is not supported at this time' %
|
||||||
|
|
Loading…
Reference in a new issue