Lots of formatting fixes

This commit is contained in:
Michael DeHaan
2013-05-24 23:46:23 -04:00
parent 9c5d6f11f0
commit 3a635d2d26
11 changed files with 88 additions and 89 deletions

View File

@@ -140,7 +140,7 @@ def _get_quantum_client(module, kwargs):
'endpoint_url': endpoint
}
try:
quantum = client.Client('2.0', **kwargs)
quantum = client.Client('2.0', **kwargs)
except Exception as e:
module.fail_json(msg = " Error in connecting to quantum: %s" % e.message)
return quantum
@@ -155,7 +155,7 @@ def _set_tenant_id(module):
for tenant in _os_keystone.tenants.list():
if tenant.name == tenant_name:
_os_tenant_id = tenant.id
break;
break
if not _os_tenant_id:
module.fail_json(msg = "The tenant id cannot be found, please check the paramters")
@@ -204,17 +204,19 @@ def _create_subnet(module, quantum):
'cidr': module.params['cidr'],
}
if module.params['allocation_pool_start'] and module.params['allocation_pool_end']:
allocation_pools = [
{'start': module.params['allocation_pool_start'],
'end': module.params['allocation_pool_end']}
]
subnet.update({'allocation_pools': allocation_pools})
allocation_pools = [
{
'start' : module.params['allocation_pool_start'],
'end' : module.params['allocation_pool_end']
}
]
subnet.update({'allocation_pools': allocation_pools})
if not module.params['gateway_ip']:
subnet.pop('gateway_ip')
subnet.pop('gateway_ip')
try:
new_subnet = quantum.create_subnet({'subnet': subnet })
except Exception as e:
module.fail_json( msg = "Failure in creating subnet: %s" %e.message)
new_subnet = quantum.create_subnet(dict(subnet=subnet))
except Exception, e:
module.fail_json(msg = "Failure in creating subnet: %s" % e.message)
return new_subnet['subnet']['id']
@@ -229,22 +231,22 @@ def _delete_subnet(module, quantum, subnet_id):
def main():
module = AnsibleModule(
argument_spec = dict(
login_username = dict(default='admin'),
login_password = dict(required=True),
login_tenant_name = dict(required='True'),
auth_url = dict(default='http://127.0.0.1:35357/v2.0/'),
region_name = dict(default=None),
name = dict(required=True),
network_name = dict(required=True),
cidr = dict(required=True),
tenant_name = dict(default=None),
state = dict(default='present', choices=['absent', 'present']),
ip_version = dict(default='4', choices=['4', '6']),
enable_dhcp = dict(default='true', choices=BOOLEANS),
gateway_ip = dict(default=None),
allocation_pool_start = dict(default=None),
allocation_pool_end = dict(default=None),
argument_spec = dict(
login_username = dict(default='admin'),
login_password = dict(required=True),
login_tenant_name = dict(required='True'),
auth_url = dict(default='http://127.0.0.1:35357/v2.0/'),
region_name = dict(default=None),
name = dict(required=True),
network_name = dict(required=True),
cidr = dict(required=True),
tenant_name = dict(default=None),
state = dict(default='present', choices=['absent', 'present']),
ip_version = dict(default='4', choices=['4', '6']),
enable_dhcp = dict(default='true', choices=BOOLEANS),
gateway_ip = dict(default=None),
allocation_pool_start = dict(default=None),
allocation_pool_end = dict(default=None),
),
)
quantum = _get_quantum_client(module, module.params)
@@ -259,10 +261,10 @@ def main():
else:
subnet_id = _get_subnet_id(module, quantum)
if not subnet_id:
module.exit_json(changed = False, result = "success" )
module.exit_json(changed = False, result = "success")
else:
_delete_subnet(module, quantum, subnet_id)
module.exit_json(changed = True, result = "deleted" )
_delete_subnet(module, quantum, subnet_id)
module.exit_json(changed = True, result = "deleted")
# this is magic, see lib/ansible/module.params['common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>