Browse Source

Support preferred edge paths in Policy

Add GET and SET preferred edge paths in T1 API

Change-Id: Iaf3f7ec9ecee99d95df5297f9daff59e984336ee
(cherry picked from commit 17eeeff0ea)
changes/11/781811/1
Enhao Cui 3 months ago
parent
commit
238308fa01
3 changed files with 32 additions and 4 deletions
  1. +17
    -0
      vmware_nsxlib/tests/unit/v3/policy/test_resources.py
  2. +1
    -0
      vmware_nsxlib/v3/policy/core_defs.py
  3. +14
    -4
      vmware_nsxlib/v3/policy/core_resources.py

+ 17
- 0
vmware_nsxlib/tests/unit/v3/policy/test_resources.py View File

@ -3186,16 +3186,19 @@ class TestPolicyTier1(NsxPolicyLibTestCase):
def test_set_edge_cluster(self):
tier1_id = '111'
path = 'dummy/path'
preferred_edge_paths = ['dummy/path/edge/0', 'dummy/path/edge/1']
with mock.patch.object(self.policy_api,
"create_or_update") as api_call:
self.resourceApi.set_edge_cluster_path(
tier1_id, path,
preferred_edge_paths=preferred_edge_paths,
tenant=TEST_TENANT)
expected_def = core_defs.Tier1LocaleServiceDef(
tier1_id=tier1_id,
service_id=self.resourceApi._locale_service_id(tier1_id),
edge_cluster_path=path,
preferred_edge_paths=preferred_edge_paths,
tenant=TEST_TENANT)
self.assert_called_with_def(api_call, expected_def)
@ -3542,6 +3545,20 @@ class TestPolicyTier1(NsxPolicyLibTestCase):
self.assert_called_with_def(api_call, expected_def)
self.assertIsNotNone(result)
def test_get_preferred_edge_paths(self):
tier1_id = "1111"
preferred_edge_paths = [
"/fake/edge-clusters/edge-nodes/0",
"/fake/edge-clusters/edge-nodes/0"
]
with mock.patch.object(
self.resourceApi, "get_locale_tier1_services",
return_value=[{"preferred_edge_paths": preferred_edge_paths}]):
result = self.resourceApi.get_preferred_edge_paths(tier1_id)
self.assertEqual(
preferred_edge_paths,
result)
class TestPolicyTier1NoPassthrough(TestPolicyTier1):


+ 1
- 0
vmware_nsxlib/v3/policy/core_defs.py View File

@ -516,6 +516,7 @@ class RouterLocaleServiceDef(ResourceDef):
def get_obj_dict(self):
body = super(RouterLocaleServiceDef, self).get_obj_dict()
self._set_attr_if_specified(body, 'edge_cluster_path')
self._set_attr_if_specified(body, 'preferred_edge_paths')
return body


+ 14
- 4
vmware_nsxlib/v3/policy/core_resources.py View File

@ -1248,13 +1248,23 @@ class NsxPolicyTier1Api(NsxPolicyResourceBase):
tenant=tenant)
self._delete_with_retry(t1service_def)
def get_preferred_edge_paths(self, tier1_id,
tenant=constants.POLICY_INFRA_TENANT):
services = self.get_locale_tier1_services(tier1_id, tenant=tenant)
for srv in services:
if 'preferred_edge_paths' in srv:
return srv['preferred_edge_paths']
def set_edge_cluster_path(self, tier1_id, edge_cluster_path,
preferred_edge_paths=IGNORE,
tenant=constants.POLICY_INFRA_TENANT):
t1service_def = core_defs.Tier1LocaleServiceDef(
tier1_id=tier1_id,
service_id=self._locale_service_id(tier1_id),
kwargs = self._get_user_args(
tier1_id=tier1_id, service_id=self._locale_service_id(tier1_id),
edge_cluster_path=edge_cluster_path,
tenant=tenant)
preferred_edge_paths=preferred_edge_paths,
tenant=tenant
)
t1service_def = core_defs.Tier1LocaleServiceDef(**kwargs)
self._create_or_store(t1service_def)
def remove_edge_cluster(self, tier1_id,


Loading…
Cancel
Save