Set variable types, defined choices, and cleaned up whitespace.

This commit is contained in:
Ethan Devenport 2016-08-31 06:24:55 +00:00
parent e9fd5ad5dc
commit 86285e8824
2 changed files with 25 additions and 18 deletions

View file

@ -580,15 +580,16 @@ def main():
datacenter=dict(), datacenter=dict(),
name=dict(), name=dict(),
image=dict(), image=dict(),
cores=dict(default=2), cores=dict(type='int', default=2),
ram=dict(default=2048), ram=dict(type='int', default=2048),
cpu_family=dict(default='AMD_OPTERON'), cpu_family=dict(choices=['AMD_OPTERON', 'INTEL_XEON'],
volume_size=dict(default=10), default='AMD_OPTERON'),
disk_type=dict(default='HDD'), volume_size=dict(type='int', default=10),
disk_type=dict(choices=['HDD', 'SSD'], default='HDD'),
image_password=dict(default=None), image_password=dict(default=None),
ssh_keys=dict(type='list', default=[]), ssh_keys=dict(type='list', default=[]),
bus=dict(default='VIRTIO'), bus=dict(default='VIRTIO'),
lan=dict(default=1), lan=dict(type='int', default=1),
count=dict(type='int', default=1), count=dict(type='int', default=1),
auto_increment=dict(type='bool', default=True), auto_increment=dict(type='bool', default=True),
instance_ids=dict(type='list', default=[]), instance_ids=dict(type='list', default=[]),

View file

@ -170,6 +170,7 @@ def _wait_for_completion(profitbricks, promise, wait_timeout, msg):
promise['requestId'] promise['requestId']
) + '" to complete.') ) + '" to complete.')
def _create_volume(module, profitbricks, datacenter, name): def _create_volume(module, profitbricks, datacenter, name):
size = module.params.get('size') size = module.params.get('size')
bus = module.params.get('bus') bus = module.params.get('bus')
@ -204,12 +205,14 @@ def _create_volume(module, profitbricks, datacenter, name):
return volume_response return volume_response
def _delete_volume(module, profitbricks, datacenter, volume): def _delete_volume(module, profitbricks, datacenter, volume):
try: try:
profitbricks.delete_volume(datacenter, volume) profitbricks.delete_volume(datacenter, volume)
except Exception as e: except Exception as e:
module.fail_json(msg="failed to remove the volume: %s" % str(e)) module.fail_json(msg="failed to remove the volume: %s" % str(e))
def create_volume(module, profitbricks): def create_volume(module, profitbricks):
""" """
Creates a volume. Creates a volume.
@ -256,7 +259,7 @@ def create_volume(module, profitbricks):
else: else:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
number_range = xrange(count_offset,count_offset + count + len(numbers)) number_range = xrange(count_offset, count_offset + count + len(numbers))
available_numbers = list(set(number_range).difference(numbers)) available_numbers = list(set(number_range).difference(numbers))
names = [] names = []
numbers_to_use = available_numbers[:count] numbers_to_use = available_numbers[:count]
@ -282,6 +285,7 @@ def create_volume(module, profitbricks):
return results return results
def delete_volume(module, profitbricks): def delete_volume(module, profitbricks):
""" """
Removes a volume. Removes a volume.
@ -324,6 +328,7 @@ def delete_volume(module, profitbricks):
return changed return changed
def _attach_volume(module, profitbricks, datacenter, volume): def _attach_volume(module, profitbricks, datacenter, volume):
""" """
Attaches a volume. Attaches a volume.
@ -344,7 +349,7 @@ def _attach_volume(module, profitbricks, datacenter, volume):
server_list = profitbricks.list_servers(datacenter) server_list = profitbricks.list_servers(datacenter)
for s in server_list['items']: for s in server_list['items']:
if server == s['properties']['name']: if server == s['properties']['name']:
server= s['id'] server = s['id']
break break
try: try:
@ -352,18 +357,19 @@ def _attach_volume(module, profitbricks, datacenter, volume):
except Exception as e: except Exception as e:
module.fail_json(msg='failed to attach volume: %s' % str(e)) module.fail_json(msg='failed to attach volume: %s' % str(e))
def main(): def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec=dict( argument_spec=dict(
datacenter=dict(), datacenter=dict(),
server=dict(), server=dict(),
name=dict(), name=dict(),
size=dict(default=10), size=dict(type='int', default=10),
bus=dict(default='VIRTIO'), bus=dict(default='VIRTIO'),
image=dict(), image=dict(),
image_password=dict(default=None), image_password=dict(default=None),
ssh_keys=dict(type='list', default=[]), ssh_keys=dict(type='list', default=[]),
disk_type=dict(default='HDD'), disk_type=dict(choices=['HDD', 'SSD'], default='HDD'),
licence_type=dict(default='UNKNOWN'), licence_type=dict(default='UNKNOWN'),
count=dict(type='int', default=1), count=dict(type='int', default=1),
auto_increment=dict(type='bool', default=True), auto_increment=dict(type='bool', default=True),