Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor(eos_designs): structured_config for core_interfaces_and_l3_edge/router_ospf.py #4977

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 AvdStructuredConfigCoreInterfacesAndL3EdgeProtocol

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

@cached_property
def router_ospf(self: AvdStructuredConfigCoreInterfacesAndL3EdgeProtocol) -> dict | None:
"""Return structured config for router_ospf."""
@structured_config_contributor
def router_ospf(self: AvdStructuredConfigCoreInterfacesAndL3EdgeProtocol) -> None:
"""Set the structured config for router_ospf."""
if not self.shared_utils.underlay_ospf:
return None
return

no_passive_interfaces = EosCliConfigGen.RouterOspf.ProcessIdsItem.NoPassiveInterfaces()
for p2p_link, p2p_link_data in self._filtered_p2p_links:
if p2p_link.include_in_underlay_protocol:
no_passive_interfaces.append(p2p_link_data["interface"])

no_passive_interfaces = [p2p_link_data["interface"] for p2p_link, p2p_link_data in self._filtered_p2p_links if p2p_link.include_in_underlay_protocol]
if no_passive_interfaces:
MaheshGSLAB marked this conversation as resolved.
Show resolved Hide resolved
return {
"process_ids": [
{
"id": self.inputs.underlay_ospf_process_id,
"no_passive_interfaces": no_passive_interfaces,
},
],
}

return None
self.structured_config.router_ospf.process_ids.append_new(
id=self.inputs.underlay_ospf_process_id,
no_passive_interfaces=EosCliConfigGen.RouterOspf.ProcessIdsItem.NoPassiveInterfaces(no_passive_interfaces),
)