summaryrefslogtreecommitdiffstats
path: root/snaps/openstack/utils/neutron_utils.py
diff options
context:
space:
mode:
authorspisarski <s.pisarski@cablelabs.com>2018-02-26 09:51:45 -0700
committerspisarski <s.pisarski@cablelabs.com>2018-02-28 07:42:45 -0700
commit8a7e0ddf0ddc631a1271319cd97f43773012e3ca (patch)
treec57dfa6a18d4a6facd5afacf84578f008adbf2f4 /snaps/openstack/utils/neutron_utils.py
parent65f23fa8e2f0a6a402546229a321a5fea4bc2ffb (diff)
Ensure project for routers are handled properly.
Routers should be able to be created by admin users to other projects. Routers without admin users should only be able to create ones to their default project. JIRA: SNAPS-266 Change-Id: I5ecfbcc2ed94bbab211751da9521f3ec1d4ff66d Signed-off-by: spisarski <s.pisarski@cablelabs.com>
Diffstat (limited to 'snaps/openstack/utils/neutron_utils.py')
-rw-r--r--snaps/openstack/utils/neutron_utils.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/snaps/openstack/utils/neutron_utils.py b/snaps/openstack/utils/neutron_utils.py
index f2ee648..8685d14 100644
--- a/snaps/openstack/utils/neutron_utils.py
+++ b/snaps/openstack/utils/neutron_utils.py
@@ -325,14 +325,17 @@ def get_router_by_id(neutron, router_id):
return __map_router(neutron, router['router'])
-def get_router(neutron, router_settings=None, router_name=None):
+def get_router(neutron, keystone, router_settings=None, router_name=None,
+ project_name=None):
"""
Returns the first router object (dictionary) found the given the settings
values if not None, else finds the first with the value of the router_name
parameter, else None
- :param neutron: the client
+ :param neutron: the Neutron client
+ :param keystone: the Keystone client
:param router_settings: the RouterConfig object
:param router_name: the name of the network to retrieve
+ :param project_name: the name of the router's project
:return: a SNAPS-OO Router domain object
"""
router_filter = dict()
@@ -345,12 +348,13 @@ def get_router(neutron, router_settings=None, router_name=None):
else:
return None
- routers = neutron.list_routers(**router_filter)
-
- for routerInst in routers['routers']:
- return __map_router(neutron, routerInst)
-
- return None
+ os_routers = neutron.list_routers(**router_filter)
+ for os_router in os_routers['routers']:
+ if project_name:
+ project = keystone_utils.get_project_by_id(
+ keystone, os_router['project_id'])
+ if project and project.name == project_name:
+ return __map_router(neutron, os_router)
def __map_router(neutron, os_router):