From 1e3f067d6da62cd1f0c3282aeef42a9e531770aa Mon Sep 17 00:00:00 2001 From: Ran Gu Date: Thu, 30 Apr 2020 11:55:40 +0800 Subject: [PATCH] Add ls_id property for SegmentApi We will reuse the deprecated ls_id attribute to specify LogicalSwitch ID when creating segment. The ls_id field will remain deprecated for the general purpose. Change-Id: Ie4d1186ac455b752efde9e2aff2e92ddfa24b570 --- vmware_nsxlib/tests/unit/v3/policy/test_resources.py | 8 +++++++- vmware_nsxlib/v3/policy/core_defs.py | 3 ++- vmware_nsxlib/v3/policy/core_resources.py | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py index 69f3a62b..bac1b7de 100644 --- a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py +++ b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py @@ -4026,7 +4026,7 @@ class TestPolicySegment(NsxPolicyLibTestCase): def _test_create(self, tier1_id=None, tier0_id=None, mdproxy=None, dhcp_server=None, admin_state=None, - ip_pool_id='external-ip-pool'): + ip_pool_id='external-ip-pool', ls_id=None): name = 'test' description = 'desc' subnets = [core_defs.Subnet(gateway_address="2.2.2.0/24")] @@ -4048,6 +4048,9 @@ class TestPolicySegment(NsxPolicyLibTestCase): if admin_state: kwargs['admin_state'] = admin_state + if ls_id: + kwargs['ls_id'] = ls_id + with mock.patch.object(self.policy_api, "create_or_update") as api_call: result = self.resourceApi.create_or_overwrite(name, **kwargs) @@ -4098,6 +4101,9 @@ class TestPolicySegment(NsxPolicyLibTestCase): def test_create_without_ip_pool(self): self._test_create(ip_pool_id=None) + def test_create_with_ls_id(self): + self._test_create(ls_id='lsid1') + def test_delete(self): segment_id = '111' with mock.patch.object(self.policy_api, "delete") as api_call: diff --git a/vmware_nsxlib/v3/policy/core_defs.py b/vmware_nsxlib/v3/policy/core_defs.py index 96ba0a33..3c280a54 100644 --- a/vmware_nsxlib/v3/policy/core_defs.py +++ b/vmware_nsxlib/v3/policy/core_defs.py @@ -907,7 +907,8 @@ class BaseSegmentDef(ResourceDef): self._set_attr_if_specified(body, 'ip_pool_id', body_attr='advanced_config', value=adv_cfg) - self._set_attrs_if_specified(body, ['domain_name', 'vlan_ids']) + self._set_attrs_if_specified( + body, ['domain_name', 'vlan_ids', 'ls_id']) return body @staticmethod diff --git a/vmware_nsxlib/v3/policy/core_resources.py b/vmware_nsxlib/v3/policy/core_resources.py index 38cba13d..b0a45510 100644 --- a/vmware_nsxlib/v3/policy/core_resources.py +++ b/vmware_nsxlib/v3/policy/core_resources.py @@ -1940,6 +1940,7 @@ class NsxPolicySegmentApi(NsxPolicyResourceBase): metadata_proxy_id=IGNORE, dhcp_server_config_id=IGNORE, admin_state=IGNORE, + ls_id=IGNORE, tags=IGNORE, tenant=constants.POLICY_INFRA_TENANT): @@ -1963,6 +1964,7 @@ class NsxPolicySegmentApi(NsxPolicyResourceBase): metadata_proxy_id=metadata_proxy_id, dhcp_server_config_id=dhcp_server_config_id, admin_state=admin_state, + ls_id=ls_id, tags=tags, tenant=tenant) self._create_or_store(segment_def)