diff --git a/vmware_nsxlib/v3/policy/core_defs.py b/vmware_nsxlib/v3/policy/core_defs.py index ee4274a0..fd93b0db 100644 --- a/vmware_nsxlib/v3/policy/core_defs.py +++ b/vmware_nsxlib/v3/policy/core_defs.py @@ -2569,11 +2569,14 @@ class NsxPolicyApi(object): self.client.patch(path, body) - def delete(self, resource_def): + def delete(self, resource_def, force=False): + headers = None + if force: + headers = {'X-Allow-Overwrite': 'true'} path = resource_def.get_resource_path() if resource_def.resource_use_cache(): self.cache.remove(path) - self.client.delete(path) + self.client.delete(path, headers=headers) def get(self, resource_def, silent=False): path = resource_def.get_resource_path() diff --git a/vmware_nsxlib/v3/policy/core_resources.py b/vmware_nsxlib/v3/policy/core_resources.py index 68363eaf..c44f7512 100644 --- a/vmware_nsxlib/v3/policy/core_resources.py +++ b/vmware_nsxlib/v3/policy/core_resources.py @@ -466,7 +466,8 @@ class NsxPolicyResourceBase(object, metaclass=abc.ABCMeta): def _list(self, obj_def, silent=False): return self.policy_api.list(obj_def, silent=silent).get('results', []) - def _create_or_store(self, policy_def, child_def=None): + def _create_or_store(self, policy_def, child_def=None, + force=False): transaction = trans.NsxPolicyTransaction.get_current() if transaction: # Store this def for batch apply for this transaction @@ -480,13 +481,15 @@ class NsxPolicyResourceBase(object, metaclass=abc.ABCMeta): @utils.retry_upon_exception( (exceptions.NsxPendingDelete, exceptions.StaleRevision), max_attempts=self.policy_api.client.max_attempts) - def _do_create_with_retry(): + def _do_create_with_retry(force=False): if child_def: self.policy_api.create_with_parent(policy_def, child_def) else: - self.policy_api.create_or_update(policy_def) + self.policy_api.create_or_update( + policy_def, force=force) - _do_create_with_retry() + _do_create_with_retry( + force=force) def _delete_or_store(self, policy_def): transaction = trans.NsxPolicyTransaction.get_current() @@ -502,15 +505,15 @@ class NsxPolicyResourceBase(object, metaclass=abc.ABCMeta): # No transaction - apply now self._delete_with_retry(policy_def) - def _delete_with_retry(self, policy_def): + def _delete_with_retry(self, policy_def, force=False): @utils.retry_upon_exception( exceptions.StaleRevision, max_attempts=self.policy_api.client.max_attempts) - def do_delete(): - self.policy_api.delete(policy_def) + def do_delete(force=False): + self.policy_api.delete(policy_def, force=force) - do_delete() + do_delete(force=force) class NsxPolicyDomainApi(NsxPolicyResourceBase): @@ -2104,7 +2107,8 @@ class NsxPolicyTier1StaticRouteApi(NsxPolicyResourceBase): network=IGNORE, next_hop=IGNORE, tags=IGNORE, - tenant=constants.POLICY_INFRA_TENANT): + tenant=constants.POLICY_INFRA_TENANT, + force=False): static_route_id = self._init_obj_uuid(static_route_id) static_route_def = self._init_def(tier1_id=tier1_id, @@ -2115,15 +2119,16 @@ class NsxPolicyTier1StaticRouteApi(NsxPolicyResourceBase): next_hop=next_hop, tags=tags, tenant=tenant) - self._create_or_store(static_route_def) + self._create_or_store( + static_route_def, force=force) return static_route_id def delete(self, tier1_id, static_route_id, - tenant=constants.POLICY_INFRA_TENANT): + tenant=constants.POLICY_INFRA_TENANT, force=False): static_route_def = self.entry_def(tier1_id=tier1_id, static_route_id=static_route_id, tenant=tenant) - self._delete_with_retry(static_route_def) + self._delete_with_retry(static_route_def, force=force) def get(self, tier1_id, static_route_id, tenant=constants.POLICY_INFRA_TENANT, silent=False):