Skip to content

Commit

Permalink
Refactor(eos_designs): Refactor structured_config code for `underlay/…
Browse files Browse the repository at this point in the history
  • Loading branch information
laxmikantchintakindi authored Feb 7, 2025
1 parent 394a23f commit 8e7752b
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions python-avd/pyavd/_eos_designs/structured_config/underlay/as_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
# that can be found in the LICENSE file.
from __future__ import annotations

from functools import cached_property
from typing import TYPE_CHECKING, Protocol

from pyavd._eos_cli_config_gen.schema import EosCliConfigGen
from pyavd._eos_designs.structured_config.structured_config_generator import structured_config_contributor

if TYPE_CHECKING:
from . import AvdStructuredConfigUnderlayProtocol

Expand All @@ -17,27 +19,13 @@ class AsPathMixin(Protocol):
Class should only be used as Mixin to a AvdStructuredConfig class.
"""

@cached_property
def as_path(self: AvdStructuredConfigUnderlayProtocol) -> dict | None:
"""Return structured config for as_path."""
@structured_config_contributor
def as_path(self: AvdStructuredConfigUnderlayProtocol) -> None:
"""Set the structured config for as_path."""
if self.shared_utils.underlay_routing_protocol != "ebgp":
return None
return

access_lists = []
if self.shared_utils.wan_ha and self.shared_utils.use_uplinks_for_wan_ha:
access_lists.append(
{
"name": "ASPATH-WAN",
"entries": [
{
"type": "permit",
"match": self.shared_utils.bgp_as,
},
],
},
)

if access_lists:
return {"access_lists": access_lists}

return None
entries = EosCliConfigGen.AsPath.AccessListsItem.Entries()
entries.append_new(type="permit", match=self.shared_utils.bgp_as)
self.structured_config.as_path.access_lists.append_new(name="ASPATH-WAN", entries=entries)

0 comments on commit 8e7752b

Please sign in to comment.