Extending Overwrite Header for different PI in T1 Static routes
Extending support for adding overwrite header in T1 Static Route Issue: #3016445 Change-Id: I8b4dc401b659d7feaa090c4d3fd9bb359b671b7f
This commit is contained in:
parent
9523d737ba
commit
8481b2ab51
@ -2569,11 +2569,14 @@ class NsxPolicyApi(object):
|
|||||||
|
|
||||||
self.client.patch(path, body)
|
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()
|
path = resource_def.get_resource_path()
|
||||||
if resource_def.resource_use_cache():
|
if resource_def.resource_use_cache():
|
||||||
self.cache.remove(path)
|
self.cache.remove(path)
|
||||||
self.client.delete(path)
|
self.client.delete(path, headers=headers)
|
||||||
|
|
||||||
def get(self, resource_def, silent=False):
|
def get(self, resource_def, silent=False):
|
||||||
path = resource_def.get_resource_path()
|
path = resource_def.get_resource_path()
|
||||||
|
@ -466,7 +466,8 @@ class NsxPolicyResourceBase(object, metaclass=abc.ABCMeta):
|
|||||||
def _list(self, obj_def, silent=False):
|
def _list(self, obj_def, silent=False):
|
||||||
return self.policy_api.list(obj_def, silent=silent).get('results', [])
|
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()
|
transaction = trans.NsxPolicyTransaction.get_current()
|
||||||
if transaction:
|
if transaction:
|
||||||
# Store this def for batch apply for this transaction
|
# Store this def for batch apply for this transaction
|
||||||
@ -480,13 +481,15 @@ class NsxPolicyResourceBase(object, metaclass=abc.ABCMeta):
|
|||||||
@utils.retry_upon_exception(
|
@utils.retry_upon_exception(
|
||||||
(exceptions.NsxPendingDelete, exceptions.StaleRevision),
|
(exceptions.NsxPendingDelete, exceptions.StaleRevision),
|
||||||
max_attempts=self.policy_api.client.max_attempts)
|
max_attempts=self.policy_api.client.max_attempts)
|
||||||
def _do_create_with_retry():
|
def _do_create_with_retry(force=False):
|
||||||
if child_def:
|
if child_def:
|
||||||
self.policy_api.create_with_parent(policy_def, child_def)
|
self.policy_api.create_with_parent(policy_def, child_def)
|
||||||
else:
|
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):
|
def _delete_or_store(self, policy_def):
|
||||||
transaction = trans.NsxPolicyTransaction.get_current()
|
transaction = trans.NsxPolicyTransaction.get_current()
|
||||||
@ -502,15 +505,15 @@ class NsxPolicyResourceBase(object, metaclass=abc.ABCMeta):
|
|||||||
# No transaction - apply now
|
# No transaction - apply now
|
||||||
self._delete_with_retry(policy_def)
|
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(
|
@utils.retry_upon_exception(
|
||||||
exceptions.StaleRevision,
|
exceptions.StaleRevision,
|
||||||
max_attempts=self.policy_api.client.max_attempts)
|
max_attempts=self.policy_api.client.max_attempts)
|
||||||
def do_delete():
|
def do_delete(force=False):
|
||||||
self.policy_api.delete(policy_def)
|
self.policy_api.delete(policy_def, force=force)
|
||||||
|
|
||||||
do_delete()
|
do_delete(force=force)
|
||||||
|
|
||||||
|
|
||||||
class NsxPolicyDomainApi(NsxPolicyResourceBase):
|
class NsxPolicyDomainApi(NsxPolicyResourceBase):
|
||||||
@ -2104,7 +2107,8 @@ class NsxPolicyTier1StaticRouteApi(NsxPolicyResourceBase):
|
|||||||
network=IGNORE,
|
network=IGNORE,
|
||||||
next_hop=IGNORE,
|
next_hop=IGNORE,
|
||||||
tags=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_id = self._init_obj_uuid(static_route_id)
|
||||||
static_route_def = self._init_def(tier1_id=tier1_id,
|
static_route_def = self._init_def(tier1_id=tier1_id,
|
||||||
@ -2115,15 +2119,16 @@ class NsxPolicyTier1StaticRouteApi(NsxPolicyResourceBase):
|
|||||||
next_hop=next_hop,
|
next_hop=next_hop,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
tenant=tenant)
|
tenant=tenant)
|
||||||
self._create_or_store(static_route_def)
|
self._create_or_store(
|
||||||
|
static_route_def, force=force)
|
||||||
return static_route_id
|
return static_route_id
|
||||||
|
|
||||||
def delete(self, tier1_id, 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_def = self.entry_def(tier1_id=tier1_id,
|
||||||
static_route_id=static_route_id,
|
static_route_id=static_route_id,
|
||||||
tenant=tenant)
|
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,
|
def get(self, tier1_id, static_route_id,
|
||||||
tenant=constants.POLICY_INFRA_TENANT, silent=False):
|
tenant=constants.POLICY_INFRA_TENANT, silent=False):
|
||||||
|
Loading…
Reference in New Issue
Block a user