Skip to content

Commit

Permalink
optimized the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahesh Kumar authored and Mahesh Kumar committed Feb 12, 2025
1 parent 440bc64 commit e3255b9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,5 @@ def ip_access_lists(self: AvdStructuredConfigNetworkServicesProtocol) -> None:

for ie_policy_type in self._filtered_internet_exit_policy_types:
self._acl_internet_exit(ie_policy_type)

self.structured_config.ip_access_lists = EosCliConfigGen.IpAccessLists(natural_sort(self.structured_config.ip_access_lists, sort_key="name"))
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,10 @@ def _get_vlan_interface_config_for_svi(
mtu=svi.mtu if self.shared_utils.platform_settings.feature_support.per_interface_mtu else None,
eos_cli=svi.raw_eos_cli,
)
access_group_in = get(self._svi_acls, f"{interface_name}.ipv4_acl_in")
if access_group_in:
vlan_interface_config.access_group_in = access_group_in.name
access_group_out = get(self._svi_acls, f"{interface_name}.ipv4_acl_out")
if access_group_out:
vlan_interface_config.access_group_out = access_group_out.name

for direction in ["in", "out"]:
if access_group := get(self._svi_acls, f"{interface_name}.ipv4_acl_{direction}"):
setattr(vlan_interface_config, f"access_group_{direction}", access_group.name)

if svi.structured_config:
self.custom_structured_configs.nested.vlan_interfaces.obtain(interface_name)._deepmerge(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class IpAccesslistsMixin(Protocol):
@structured_config_contributor
def ip_access_lists(self: AvdStructuredConfigUnderlayProtocol) -> None:
"""
Return structured config for ip_access_lists.
Set the structured config for ip_access_lists.
Covers ipv4_acl_in/out defined under node l3_interfaces or l3_port_channels.
"""
Expand All @@ -34,4 +34,5 @@ def ip_access_lists(self: AvdStructuredConfigUnderlayProtocol) -> None:
for interface_acls in chain(self._l3_interface_acls.values(), self._l3_port_channel_acls.values()):
for acl in interface_acls.values():
self.structured_config.ip_access_lists.append(acl)

self.structured_config.ip_access_lists = EosCliConfigGen.IpAccessLists(natural_sort(self.structured_config.ip_access_lists, sort_key="name"))
21 changes: 9 additions & 12 deletions python-avd/pyavd/_eos_designs/structured_config/underlay/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,10 @@ def _get_l3_interface_cfg(
)
if self.inputs.fabric_sflow.l3_interfaces is not None:
interface["sflow"] = {"enable": self.inputs.fabric_sflow.l3_interfaces}
ipv4_acl_in = get(self._l3_interface_acls, f"{l3_interface.name}..ipv4_acl_in", separator="..")
if ipv4_acl_in:
interface["access_group_in"] = ipv4_acl_in.name
ipv4_acl_out = get(self._l3_interface_acls, f"{l3_interface.name}..ipv4_acl_out", separator="..")
if ipv4_acl_out:
interface["access_group_out"] = ipv4_acl_out.name

for direction in ["in", "out"]:
if acl := get(self._l3_interface_acls, f"{l3_interface.name}..ipv4_acl_{direction}", separator=".."):
interface[f"access_group_{direction}"] = acl.name

if (
self.shared_utils.is_wan_router
Expand Down Expand Up @@ -224,12 +222,11 @@ def _get_l3_port_channel_cfg(
self.custom_structured_configs.nested.port_channel_interfaces.obtain(l3_port_channel.name)._deepmerge(
l3_port_channel.structured_config, list_merge=self.custom_structured_configs.list_merge_strategy
)
ipv4_acl_in = get(self._l3_port_channel_acls, f"{l3_port_channel.name}..ipv4_acl_in", separator="..")
if ipv4_acl_in:
interface["access_group_in"] = ipv4_acl_in.name
ipv4_acl_out = get(self._l3_port_channel_acls, f"{l3_port_channel.name}..ipv4_acl_out", separator="..")
if ipv4_acl_out:
interface["access_group_out"] = ipv4_acl_out.name

for direction in ["in", "out"]:
if acl := get(self._l3_port_channel_acls, f"{l3_port_channel.name}..ipv4_acl_{direction}", separator=".."):
interface[f"access_group_{direction}"] = acl.name

if (
self.shared_utils.is_wan_router
and (wan_carrier_name := l3_port_channel.wan_carrier) is not None
Expand Down

0 comments on commit e3255b9

Please sign in to comment.