diff --git a/vmware_nsxlib/v3/client.py b/vmware_nsxlib/v3/client.py index 4c02a99b..3f18c700 100644 --- a/vmware_nsxlib/v3/client.py +++ b/vmware_nsxlib/v3/client.py @@ -39,7 +39,8 @@ def http_error_to_exception(status_code, error_code): '60514': exceptions.NsxSearchTimeout, '500045': exceptions.NsxPendingDelete, '500030': exceptions.ResourceInUse, - '500105': exceptions.NsxOverlapAddresses}, + '500105': exceptions.NsxOverlapAddresses, + '503040': exceptions.NsxSegemntWithVM}, 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 77ac0a92..a4c3c0a4 100644 --- a/vmware_nsxlib/v3/exceptions.py +++ b/vmware_nsxlib/v3/exceptions.py @@ -199,6 +199,10 @@ class NsxPendingDelete(NsxLibException): "remove the deleted object") +class NsxSegemntWithVM(ManagerError): + message = _("Cannot delete segment as it still has VMs or VIFs attached") + + class NsxOverlapAddresses(NsxLibInvalidInput): message = _("Overlapping addresses found: %(details)s") diff --git a/vmware_nsxlib/v3/policy/core_resources.py b/vmware_nsxlib/v3/policy/core_resources.py index 6adaba47..828b24d8 100644 --- a/vmware_nsxlib/v3/policy/core_resources.py +++ b/vmware_nsxlib/v3/policy/core_resources.py @@ -1774,7 +1774,14 @@ class NsxPolicySegmentApi(NsxPolicyResourceBase): def delete(self, segment_id, tenant=constants.POLICY_INFRA_TENANT): segment_def = self.entry_def(segment_id=segment_id, tenant=tenant) - self.policy_api.delete(segment_def) + + @utils.retry_upon_exception( + exceptions.NsxSegemntWithVM, + max_attempts=self.policy_api.client.max_attempts) + def do_delete(): + self.policy_api.delete(segment_def) + + do_delete() def get(self, segment_id, tenant=constants.POLICY_INFRA_TENANT, silent=False):