diff options
author | spisarski <s.pisarski@cablelabs.com> | 2017-08-07 10:30:29 -0600 |
---|---|---|
committer | spisarski <s.pisarski@cablelabs.com> | 2017-08-07 10:30:29 -0600 |
commit | 8d71b60aa3fc785627b488383c17ef30a3838030 (patch) | |
tree | e7e4d69a7c23735a5f9f081843c64538543fb7b6 /snaps/openstack/utils | |
parent | 27b8b1c246d63c14f112a99362873fe887c13c10 (diff) |
Refactored neutron_utils#get_router_by_name() to get_router()
Added a router_settings (RouterSettings) object parameter
in addition to router_name for more robust query options.
JIRA: SNAPS-163
Change-Id: I47672f531171d6ee0c90dabb6641640bf97c1d20
Signed-off-by: spisarski <s.pisarski@cablelabs.com>
Diffstat (limited to 'snaps/openstack/utils')
-rw-r--r-- | snaps/openstack/utils/neutron_utils.py | 25 | ||||
-rw-r--r-- | snaps/openstack/utils/tests/neutron_utils_tests.py | 2 |
2 files changed, 19 insertions, 8 deletions
diff --git a/snaps/openstack/utils/neutron_utils.py b/snaps/openstack/utils/neutron_utils.py index 4bc1be2..e7b002a 100644 --- a/snaps/openstack/utils/neutron_utils.py +++ b/snaps/openstack/utils/neutron_utils.py @@ -218,18 +218,29 @@ def delete_router(neutron, router): neutron.delete_router(router=router.id) -def get_router_by_name(neutron, router_name): +def get_router(neutron, router_settings=None, router_name=None): """ - Returns the first router object (dictionary) found with a given name + 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 router_settings: the RouterSettings object :param router_name: the name of the network to retrieve :return: a SNAPS-OO Router domain object """ - routers = neutron.list_routers(**{'name': router_name}) - for router, routerInst in routers.items(): - for inst in routerInst: - if inst.get('name') == router_name: - return Router(**inst) + router_filter = dict() + if router_settings: + router_filter['name'] = router_settings.name + if router_settings.admin_state_up is not None: + router_filter['admin_state_up'] = router_settings.admin_state_up + elif router_name: + router_filter['name'] = router_name + else: + return None + + routers = neutron.list_routers(**router_filter) + for routerInst in routers['routers']: + return Router(**routerInst) return None diff --git a/snaps/openstack/utils/tests/neutron_utils_tests.py b/snaps/openstack/utils/tests/neutron_utils_tests.py index 6929c4b..f6fc2bb 100644 --- a/snaps/openstack/utils/tests/neutron_utils_tests.py +++ b/snaps/openstack/utils/tests/neutron_utils_tests.py @@ -828,7 +828,7 @@ def validate_router(neutron, name, exists): :param exists: Whether or not the network name should exist or not :return: True/False """ - router = neutron_utils.get_router_by_name(neutron, name) + router = neutron_utils.get_router(neutron, router_name=name) if exists and router: return True return False |