Skip to content

Commit

Permalink
No dynamic NAT for routers without external gw
Browse files Browse the repository at this point in the history
Routers that do not have an external gateway also don't have a bridge
domain associated with it, meaning the dynamic NAT list would always
produce a diff. Therefore we delete the dynamic NAT list if there's
nothing to configure and also make sure it doesn't appear in the diff.
  • Loading branch information
sebageek committed Jan 29, 2025
1 parent 6799026 commit 55340ea
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions asr1k_neutron_l3/models/neutron/l3/nat.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,19 @@ def _rest_definition(self):

class DynamicNAT(BaseNAT):
def __init__(self, router_id, gateway_interface=None, redundancy=None, mapping_id=None,
mode=asr1k_constants.SNAT_MODE_POOL, bridge_domain=None):
mode=asr1k_constants.SNAT_MODE_POOL):
super().__init__(router_id, gateway_interface, redundancy, mapping_id)

self.specific_acl = True
self.mode = mode

self.id = utils.vrf_to_access_list_id(self.router_id)
self.bridge_domain = bridge_domain
self.bridge_domain = None
if self.gateway_interface:
self.bridge_domain = self.gateway_interface.bridge_domain

@property
def _rest_definition(self):
if self.gateway_interface is not None:
self.bridge_domain = self.gateway_interface.bridge_domain

if self.mode == asr1k_constants.SNAT_MODE_POOL:
return l3_nat.PoolDynamicNat(id=self.id, vrf=self.router_id, pool=l3_nat.NatPool.gen_id(self.router_id),
bridge_domain=self.bridge_domain, redundancy=self.redundancy,
Expand All @@ -78,6 +77,15 @@ def _rest_definition(self):
bridge_domain=self.bridge_domain, redundancy=self.redundancy,
mapping_id=self.mapping_id, overload=True)

def diff(self, should_be_none=False):
return super().diff(should_be_none=not bool(self.bridge_domain))

def update(self):
if self.bridge_domain:
return super().update()
else:
return super().delete()


class NatList(BaseNAT):
yang_model = None
Expand Down

0 comments on commit 55340ea

Please sign in to comment.