Add project parameter to os_network

A cloud/domain admin should be able to create a network on any project
it is granted to.
This changes adds the possibility to pass either a project ID or
project name.
reviewable/pr18780/r1
Ricardo Carrillo Cruz 9 years ago
parent 72f6238d04
commit 3e93204598

@ -82,6 +82,11 @@ options:
required: false
default: None
version_added: "2.1"
project:
description:
- Project name or ID containing the network (name admin-only)
required: false
default: None
requirements: ["shade"]
'''
@ -166,6 +171,7 @@ def main():
choices=['flat', 'vlan', 'vxlan', 'gre']),
provider_segmentation_id=dict(required=False),
state=dict(default='present', choices=['absent', 'present']),
project=dict(default=None)
)
module_kwargs = openstack_module_kwargs()
@ -174,6 +180,11 @@ def main():
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
if (module.params['project'] and
StrictVersion(shade.__version__) < StrictVersion('1.6.0')):
module.fail_json(msg="To utilize project, the installed version of"
"the shade library MUST be >=1.6.0")
state = module.params['state']
name = module.params['name']
shared = module.params['shared']
@ -182,10 +193,20 @@ def main():
provider_physical_network = module.params['provider_physical_network']
provider_network_type = module.params['provider_network_type']
provider_segmentation_id = module.params['provider_segmentation_id']
project = module.params.pop('project')
try:
cloud = shade.openstack_cloud(**module.params)
net = cloud.get_network(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
net = cloud.get_network(name, filters=filters)
if state == 'present':
if not net:
@ -201,7 +222,7 @@ def main():
module.fail_json(msg="Shade >= 1.5.0 required to use provider options")
net = cloud.create_network(name, shared, admin_state_up,
external, provider)
external, provider, project_id)
changed = True
else:
changed = False

Loading…
Cancel
Save