diff --git a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py index 29b2b462..f38a7e78 100644 --- a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py +++ b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py @@ -4153,6 +4153,18 @@ class TestPolicySegment(NsxPolicyLibTestCase): '%s/segments/%s' % (TEST_TENANT, segment_id), {'id': segment_id, 'connectivity_path': None, 'subnets': None}) + def test_remove_connectivity_path(self): + segment_id = '111' + with mock.patch.object(self.policy_api, "get", + return_value={'id': segment_id}) as api_get,\ + mock.patch.object(self.policy_api.client, "update") as api_put: + self.resourceApi.remove_connectivity_path( + segment_id, tenant=TEST_TENANT) + api_get.assert_called_once() + api_put.assert_called_once_with( + '%s/segments/%s' % (TEST_TENANT, segment_id), + {'id': segment_id, 'connectivity_path': None}) + def test_build_subnet(self): gateway_address = "10.0.0.1/24" dhcp_ranges = None diff --git a/vmware_nsxlib/v3/policy/core_resources.py b/vmware_nsxlib/v3/policy/core_resources.py index 8b8aed12..ba49f915 100644 --- a/vmware_nsxlib/v3/policy/core_resources.py +++ b/vmware_nsxlib/v3/policy/core_resources.py @@ -2028,6 +2028,21 @@ class NsxPolicySegmentApi(NsxPolicyResourceBase): self.policy_api.client.update(path, segment) + def remove_connectivity_path(self, segment_id, + tenant=constants.POLICY_INFRA_TENANT): + """Disconnect a segment from a router. + + PATCH does not support this action so PUT is used for this + """ + # Get the current segment and update it + segment = self.get(segment_id) + segment['connectivity_path'] = None + + segment_def = self.entry_def(segment_id=segment_id, tenant=tenant) + path = segment_def.get_resource_path() + + self.policy_api.client.update(path, segment) + def get_realized_state(self, segment_id, entity_type=None, tenant=constants.POLICY_INFRA_TENANT, realization_info=None):