Create subnet by domain

A cloud/domain admin should be able to create a subnet on any
project it is granted on.
This change adds the 'project' parameter that accepts either
a name (admin-only) or id.
This commit is contained in:
Ricardo Carrillo Cruz 2016-03-14 12:29:13 +00:00
parent eef9c54874
commit 8a03ae5287

View file

@ -104,6 +104,11 @@ options:
choices: ['dhcpv6-stateful', 'dhcpv6-stateless', 'slaac']
required: false
default: None
project:
description:
- Project name or ID containing the subnet (name admin-only)
required: false
default: None
requirements:
- "python >= 2.6"
- "shade"
@ -232,6 +237,7 @@ def main():
ipv6_ra_mode=dict(default=None, choice=ipv6_mode_choices),
ipv6_address_mode=dict(default=None, choice=ipv6_mode_choices),
state=dict(default='present', choices=['absent', 'present']),
project=dict(default=None)
)
module_kwargs = openstack_module_kwargs()
@ -255,6 +261,7 @@ def main():
host_routes = module.params['host_routes']
ipv6_ra_mode = module.params['ipv6_ra_mode']
ipv6_a_mode = module.params['ipv6_address_mode']
project = module.params.pop('project')
# Check for required parameters when state == 'present'
if state == 'present':
@ -271,7 +278,17 @@ def main():
try:
cloud = shade.openstack_cloud(**module.params)
subnet = cloud.get_subnet(subnet_name)
if project is not None:
proj = cloud.get_project(project)
if proj is None:
module.fail_json(msg='Project %s could not be found' % project)
project_id = proj['id']
filters = {'tenant_id': project_id}
else:
project_id = None
filters = None
subnet = cloud.get_subnet(subnet_name, filters=filters)
if module.check_mode:
module.exit_json(changed=_system_state_change(module, subnet,
@ -288,7 +305,8 @@ def main():
allocation_pools=pool,
host_routes=host_routes,
ipv6_ra_mode=ipv6_ra_mode,
ipv6_address_mode=ipv6_a_mode)
ipv6_address_mode=ipv6_a_mode,
tenant_id=project_id)
changed = True
else:
if _needs_update(subnet, module, cloud):