From d8596e784e6e6f641c6d195de8cbd7f5af0408fc Mon Sep 17 00:00:00 2001 From: Rongrong_Miao Date: Wed, 21 Apr 2021 15:23:30 -0700 Subject: [PATCH] [T0API] Added SCOPE parameter in static route In setting T0 static route, a scope parameter is needed. This patch fixes the problem with previous implementation by adding the scope field in static route definition Issue: # Jira: # Signed-off-by: Rongrong_Miao Change-Id: I9b6e579e8e57e13cb1ba9e797c7348e23e3aaa8f --- vmware_nsxlib/tests/unit/v3/policy/test_resources.py | 9 +++++++-- vmware_nsxlib/v3/policy/core_defs.py | 11 ++++++++++- vmware_nsxlib/v3/policy/core_resources.py | 6 ++++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py index cccee07b..5a50ca50 100644 --- a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py +++ b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py @@ -6934,6 +6934,7 @@ class TestPolicyTier0StaticRoute(NsxPolicyLibTestCase): static_route_id = '222' network = '1.1.1.1/24' nexthop = '2.2.2.2' + scope = 'ContainerT0' with mock.patch.object(self.policy_api, "create_or_update") as api_call: @@ -6943,7 +6944,9 @@ class TestPolicyTier0StaticRoute(NsxPolicyLibTestCase): description=description, network=network, next_hop=nexthop, - tenant=TEST_TENANT) + tenant=TEST_TENANT, + scope=scope + ) expected_def = core_defs.Tier0StaticRoute( tier0_id=tier0_id, @@ -6952,7 +6955,9 @@ class TestPolicyTier0StaticRoute(NsxPolicyLibTestCase): description=description, network=network, next_hop=nexthop, - tenant=TEST_TENANT) + tenant=TEST_TENANT, + scope=scope + ) self.assert_called_with_def(api_call, expected_def) self.assertIsNotNone(result) diff --git a/vmware_nsxlib/v3/policy/core_defs.py b/vmware_nsxlib/v3/policy/core_defs.py index 4b5c1403..141384ee 100644 --- a/vmware_nsxlib/v3/policy/core_defs.py +++ b/vmware_nsxlib/v3/policy/core_defs.py @@ -740,8 +740,17 @@ class RouterStaticRoute(ResourceDef): # next hops if self.has_attr('next_hop'): + next_hops = [] + param_dict = dict() next_hop = self.get_attr('next_hop') - next_hops = [{'ip_address': next_hop}] + param_dict['ip_address'] = next_hop + + # scope parameter + if self.has_attr('scope'): + scope_path = self.get_attr('scope') + param_dict['scope'] = [scope_path] + + next_hops.append(param_dict) self._set_attr_if_specified(body, 'next_hop', body_attr='next_hops', value=next_hops) diff --git a/vmware_nsxlib/v3/policy/core_resources.py b/vmware_nsxlib/v3/policy/core_resources.py index 29c40f3f..15c01636 100644 --- a/vmware_nsxlib/v3/policy/core_resources.py +++ b/vmware_nsxlib/v3/policy/core_resources.py @@ -2012,7 +2012,8 @@ class NSXPolicyTier0StaticRouteApi(NsxPolicyResourceBase): network=IGNORE, next_hop=IGNORE, tags=IGNORE, - tenant=constants.POLICY_INFRA_TENANT): + tenant=constants.POLICY_INFRA_TENANT, + scope=IGNORE): static_route_id = self._init_obj_uuid(static_route_id) static_route_def = self._init_def(tier0_id=tier0_id, static_route_id=static_route_id, @@ -2021,7 +2022,8 @@ class NSXPolicyTier0StaticRouteApi(NsxPolicyResourceBase): network=network, next_hop=next_hop, tags=tags, - tenant=tenant) + tenant=tenant, + scope=scope) self._create_or_store(static_route_def) return static_route_id