From 29df0482dc8dce0800dde5657abcbb8ddd3d952f Mon Sep 17 00:00:00 2001 From: Adit Sarfaty <asarfaty@vmware.com> Date: Mon, 15 Jul 2019 13:36:26 +0300 Subject: [PATCH] Support policy edge cluster nodes getter Change-Id: I0074c8a1096c11f22e5a56f1f073037da0c6f14e --- .../tests/unit/v3/policy/test_resources.py | 13 +++++++++++++ vmware_nsxlib/v3/policy/core_defs.py | 19 +++++++++++++++++++ vmware_nsxlib/v3/policy/core_resources.py | 8 ++++++++ 3 files changed, 40 insertions(+) diff --git a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py index 8a5e3b4a..aa108c1b 100644 --- a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py +++ b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py @@ -2388,6 +2388,19 @@ class TestPolicyEdgeCluster(NsxPolicyLibTestCase): self.assert_called_with_def(api_call, expected_def) self.assertEqual([], result) + def test_get_nodes(self): + obj_id = '111' + node_id = 'node1' + with mock.patch.object( + self.policy_api, "list", + return_value={'results': [{'id': node_id}]}) as api_call: + result = self.resourceApi.get_edge_node_ids( + obj_id, tenant=TEST_TENANT) + expected_def = core_defs.EdgeClusterNodeDef( + ec_id=obj_id, tenant=TEST_TENANT) + self.assert_called_with_def(api_call, expected_def) + self.assertEqual([node_id], result) + class TestPolicyTier1(NsxPolicyLibTestCase): diff --git a/vmware_nsxlib/v3/policy/core_defs.py b/vmware_nsxlib/v3/policy/core_defs.py index 7c8fb95c..953b3272 100644 --- a/vmware_nsxlib/v3/policy/core_defs.py +++ b/vmware_nsxlib/v3/policy/core_defs.py @@ -1493,6 +1493,25 @@ class EdgeClusterDef(ResourceDef): return True +class EdgeClusterNodeDef(ResourceDef): + + @property + def path_pattern(self): + return (EDGE_CLUSTER_PATTERN + '%s/edge-nodes/') + + @property + def path_ids(self): + return ('tenant', 'ep_id', 'ec_id', 'node_id') + + @staticmethod + def resource_type(): + return 'PolicyEdgeNode' + + @staticmethod + def resource_use_cache(): + return True + + # Currently assumes one deployment point per id class DeploymentMapDef(ResourceDef): diff --git a/vmware_nsxlib/v3/policy/core_resources.py b/vmware_nsxlib/v3/policy/core_resources.py index 2cce13e8..0850bdba 100644 --- a/vmware_nsxlib/v3/policy/core_resources.py +++ b/vmware_nsxlib/v3/policy/core_resources.py @@ -3394,6 +3394,14 @@ class NsxPolicyEdgeClusterApi(NsxPolicyResourceBase): ep_id=ep_id, ec_id=ec_id, tenant=tenant) return ec_def.get_resource_full_path() + def get_edge_node_ids(self, ec_id, + ep_id=constants.DEFAULT_ENFORCEMENT_POINT, + tenant=constants.POLICY_INFRA_TENANT): + nodes_def = core_defs.EdgeClusterNodeDef( + ep_id=ep_id, ec_id=ec_id, tenant=tenant) + nodes = self._list(nodes_def) + return [node['id'] for node in nodes] + class NsxPolicyDeploymentMapApi(NsxPolicyResourceBase): """NSX Policy Deployment Map."""