diff --git a/vmware_nsxlib/tests/unit/v3/test_resources.py b/vmware_nsxlib/tests/unit/v3/test_resources.py index 6f317881..ba19d585 100644 --- a/vmware_nsxlib/tests/unit/v3/test_resources.py +++ b/vmware_nsxlib/tests/unit/v3/test_resources.py @@ -523,6 +523,17 @@ class LogicalPortTestCase(BaseTestResource): super(LogicalPortTestCase, self).test_delete_resource( extra_params='detach=true') + def test_delete_port_skip_host_detach(self): + """Test deleting port with skip_host_detach=true.""" + mocked_resource = self.get_mocked_resource() + fake_uuid = uuidutils.generate_uuid() + mocked_resource.delete_skip_host_detach(fake_uuid) + uri = ('https://1.2.3.4/api/v1/%s/%s?detach=true&skip_host_detach=' + 'true' % (mocked_resource.uri_segment, fake_uuid)) + test_client.assert_json_call( + 'delete', mocked_resource, uri, + headers=self.default_headers()) + def test_get_logical_port_by_attachment(self): """Test deleting port.""" mocked_resource = self.get_mocked_resource() diff --git a/vmware_nsxlib/v3/client.py b/vmware_nsxlib/v3/client.py index de158c19..84b52d5e 100644 --- a/vmware_nsxlib/v3/client.py +++ b/vmware_nsxlib/v3/client.py @@ -112,7 +112,8 @@ def http_error_to_exception(status_code, error_code, related_error_codes=None): '500232': exceptions.StaleRevision, # Missing dependent objects '503040': exceptions.NsxSegemntWithVM, '100148': exceptions.StaleRevision, - '500012': exceptions.NsxInvalidPath}, + '500012': exceptions.NsxInvalidPath, + '612504': exceptions.VifRestoreAlreadyCompleted}, requests.codes.CONFLICT: exceptions.StaleRevision, requests.codes.PRECONDITION_FAILED: exceptions.StaleRevision, requests.codes.INTERNAL_SERVER_ERROR: diff --git a/vmware_nsxlib/v3/exceptions.py b/vmware_nsxlib/v3/exceptions.py index 922d2e48..0a576e4d 100644 --- a/vmware_nsxlib/v3/exceptions.py +++ b/vmware_nsxlib/v3/exceptions.py @@ -249,3 +249,7 @@ class RetryConfirm(NsxLibException): class ResourceInUse(ManagerError): message = _("The object cannot be deleted as either it has children or it " "is being referenced by other objects") + + +class VifRestoreAlreadyCompleted(ManagerError): + message = _("Vif Restore failed: %(details)s") diff --git a/vmware_nsxlib/v3/resources.py b/vmware_nsxlib/v3/resources.py index 3bebfefe..9a135830 100644 --- a/vmware_nsxlib/v3/resources.py +++ b/vmware_nsxlib/v3/resources.py @@ -187,6 +187,10 @@ class LogicalPort(utils.NsxLibApiBase): def delete(self, lport_id): self._delete_with_retry('%s?detach=true' % lport_id) + def delete_skip_host_detach(self, lport_id): + self._delete_with_retry( + '%s?detach=true&skip_host_detach=true' % lport_id) + def update(self, lport_id, vif_uuid, name=None, admin_state=None, address_bindings=None, switch_profile_ids=None,