From f505cc251fd653172d10a87a3582c2a0eb9b6f27 Mon Sep 17 00:00:00 2001 From: Adit Sarfaty Date: Mon, 28 Aug 2017 11:58:13 +0300 Subject: [PATCH] New api: list logical routers by type Change-Id: If2642bd480743774e32cc663dd5e1db4f955f727 --- vmware_nsxlib/tests/unit/v3/test_resources.py | 16 ++++++++++++++++ vmware_nsxlib/v3/core_resources.py | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/vmware_nsxlib/tests/unit/v3/test_resources.py b/vmware_nsxlib/tests/unit/v3/test_resources.py index 17a9b93a..42dd0244 100644 --- a/vmware_nsxlib/tests/unit/v3/test_resources.py +++ b/vmware_nsxlib/tests/unit/v3/test_resources.py @@ -484,6 +484,22 @@ class LogicalRouterTestCase(nsxlib_testcase.NsxClientTestCase): 'delete', router, 'https://1.2.3.4/api/v1/logical-routers/%s?force=True' % uuid) + def test_list_logical_router(self): + router = self._mocked_lrouter() + router.list() + test_client.assert_json_call( + 'get', router, + 'https://1.2.3.4/api/v1/logical-routers') + + def test_list_logical_router_by_type(self): + router = self._mocked_lrouter() + router_type = 'TIER0' + router.list(router_type=router_type) + test_client.assert_json_call( + 'get', router, + 'https://1.2.3.4/api/v1/logical-routers?router_type=%s' % + router_type) + def test_get_logical_router_fw_section(self): fake_router = test_constants.FAKE_ROUTER.copy() diff --git a/vmware_nsxlib/v3/core_resources.py b/vmware_nsxlib/v3/core_resources.py index 1466d03a..37fa1890 100644 --- a/vmware_nsxlib/v3/core_resources.py +++ b/vmware_nsxlib/v3/core_resources.py @@ -642,6 +642,14 @@ class NsxLibLogicalRouter(utils.NsxLibApiBase): sec.get('target_type') == "FirewallSection"): return firewall_sections[0].get('target_id') + def list(self, router_type=None): + """List all/by type logical routers.""" + if router_type: + resource = '%s?router_type=%s' % (self.get_path(), router_type) + else: + resource = self.get_path() + return self.client.list(resource) + class NsxLibEdgeCluster(utils.NsxLibApiBase):