diff --git a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py index 44c3ed98..2e9c44ab 100644 --- a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py +++ b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py @@ -5418,6 +5418,22 @@ class TestPolicySegmentPort(NsxPolicyLibTestCase): super(TestPolicySegmentPort, self).setUp() self.resourceApi = self.policy_lib.segment_port + def testSegmentPortDef(self): + port_def = core_defs.SegmentPortDef( + segment_id="mock_seg", port_id="mock_port", + tenant=constants.POLICY_INFRA_TENANT) + path = port_def.get_resource_path() + self.assertEqual(path, + "infra/segments/mock_seg/ports/mock_port") + port_def = core_defs.SegmentPortDef( + segment_id="mock_seg", port_id="mock_port", + tenant=constants.POLICY_INFRA_TENANT, + skip_host_detach=True) + path = port_def.get_resource_path() + self.assertEqual(path, + "infra/segments/mock_seg/ports/mock_port?" + "skip_host_detach=true") + def test_feature_supported(self): with mock.patch.object(self.policy_lib, "get_version", return_value='2.5.0'): @@ -5708,6 +5724,17 @@ class TestPolicySegmentPort(NsxPolicyLibTestCase): "%s/segments/%s/ports/%s" % (TEST_TENANT, segment_id, port_id), {'attachment': None, 'tags': tags}) + def test_delete_skip_host_detach(self): + segment_id = "segment" + port_id = "port" + with mock.patch.object(self.policy_api.client, + "delete", return_value={}) as api_delete: + self.resourceApi.delete_skip_host_detach(segment_id=segment_id, + port_id=port_id) + api_delete.assert_called_once_with( + "%s/segments/%s/ports/%s?skip_host_detach=true" % ( + "infra", segment_id, port_id), headers=None) + def test_detach_with_vif(self): segment_id = "segment" port_id = "port" diff --git a/vmware_nsxlib/v3/policy/core_defs.py b/vmware_nsxlib/v3/policy/core_defs.py index 74a23133..7b6a2c89 100644 --- a/vmware_nsxlib/v3/policy/core_defs.py +++ b/vmware_nsxlib/v3/policy/core_defs.py @@ -1299,6 +1299,12 @@ class SegmentPortDef(ResourceDef): def path_ids(self): return ('tenant', 'segment_id', 'port_id') + def get_resource_path(self): + if self.has_attr("skip_host_detach"): + base_path = super().get_resource_path() + return base_path + "?skip_host_detach=true" + return super().get_resource_path() + @staticmethod def resource_type(): return 'SegmentPort' diff --git a/vmware_nsxlib/v3/policy/core_resources.py b/vmware_nsxlib/v3/policy/core_resources.py index 730a5afa..e8986525 100644 --- a/vmware_nsxlib/v3/policy/core_resources.py +++ b/vmware_nsxlib/v3/policy/core_resources.py @@ -2594,6 +2594,13 @@ class NsxPolicySegmentPortApi(NsxPolicyResourceBase): tenant=tenant) self._delete_with_retry(port_def) + def delete_skip_host_detach(self, segment_id, port_id): + port_def = self.entry_def(segment_id=segment_id, + port_id=port_id, + tenant=constants.POLICY_INFRA_TENANT, + skip_host_detach=True) + self._delete_with_retry(port_def) + def get(self, segment_id, port_id, tenant=constants.POLICY_INFRA_TENANT, silent=False):