diff options
author | Steven Pisarski <s.pisarski@cablelabs.com> | 2017-08-08 14:16:16 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-08-08 14:16:16 +0000 |
commit | c52637e0f7e3a11b9ce39aa28ab16ffa57ce5e3c (patch) | |
tree | 23011eec4cc3a7cccf0586d29b6e90f88bf69eb3 /snaps/openstack/utils | |
parent | 0428c2d9e46f4ddd4a0458dbf8a48065eacabe66 (diff) | |
parent | 8d71b60aa3fc785627b488383c17ef30a3838030 (diff) |
Merge "Refactored neutron_utils#get_router_by_name() to get_router()"
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 |