From a48efe76c957726b684a659c672c99533b6e6740 Mon Sep 17 00:00:00 2001 From: Shivani-gslab Date: Tue, 4 Feb 2025 19:01:47 +0530 Subject: [PATCH 1/6] Refactor(eos_designs): structured_config for core_interfaces_and_l3_edge/router_ospf.py --- .../router_ospf.py | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/python-avd/pyavd/_eos_designs/structured_config/core_interfaces_and_l3_edge/router_ospf.py b/python-avd/pyavd/_eos_designs/structured_config/core_interfaces_and_l3_edge/router_ospf.py index ce3d794673e..1e6fc1391b7 100644 --- a/python-avd/pyavd/_eos_designs/structured_config/core_interfaces_and_l3_edge/router_ospf.py +++ b/python-avd/pyavd/_eos_designs/structured_config/core_interfaces_and_l3_edge/router_ospf.py @@ -6,6 +6,9 @@ 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 @@ -21,17 +24,17 @@ class RouterOspfMixin(Protocol): def router_ospf(self: AvdStructuredConfigCoreInterfacesAndL3EdgeProtocol) -> dict | None: """Return 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: - 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( + EosCliConfigGen.RouterOspf.ProcessIdsItem( + id=self.inputs.underlay_ospf_process_id, + no_passive_interfaces=EosCliConfigGen.RouterOspf.ProcessIdsItem.NoPassiveInterfaces(no_passive_interfaces), + ) + ) From 5a2a962bf8a8418c58514da679a8581fd859dc09 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 4 Feb 2025 13:38:29 +0000 Subject: [PATCH 2/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../core_interfaces_and_l3_edge/router_ospf.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/python-avd/pyavd/_eos_designs/structured_config/core_interfaces_and_l3_edge/router_ospf.py b/python-avd/pyavd/_eos_designs/structured_config/core_interfaces_and_l3_edge/router_ospf.py index 1e6fc1391b7..500dce2e28b 100644 --- a/python-avd/pyavd/_eos_designs/structured_config/core_interfaces_and_l3_edge/router_ospf.py +++ b/python-avd/pyavd/_eos_designs/structured_config/core_interfaces_and_l3_edge/router_ospf.py @@ -7,7 +7,6 @@ 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 @@ -34,7 +33,7 @@ def router_ospf(self: AvdStructuredConfigCoreInterfacesAndL3EdgeProtocol) -> dic if no_passive_interfaces: self.structured_config.router_ospf.process_ids.append( EosCliConfigGen.RouterOspf.ProcessIdsItem( - id=self.inputs.underlay_ospf_process_id, - no_passive_interfaces=EosCliConfigGen.RouterOspf.ProcessIdsItem.NoPassiveInterfaces(no_passive_interfaces), + id=self.inputs.underlay_ospf_process_id, + no_passive_interfaces=EosCliConfigGen.RouterOspf.ProcessIdsItem.NoPassiveInterfaces(no_passive_interfaces), ) ) From 6025c3d3542699c33c064e8dfd08861d19936f30 Mon Sep 17 00:00:00 2001 From: Shivani-gslab Date: Tue, 4 Feb 2025 19:21:10 +0530 Subject: [PATCH 3/6] fix pre-commit fail --- .../core_interfaces_and_l3_edge/router_ospf.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python-avd/pyavd/_eos_designs/structured_config/core_interfaces_and_l3_edge/router_ospf.py b/python-avd/pyavd/_eos_designs/structured_config/core_interfaces_and_l3_edge/router_ospf.py index 500dce2e28b..d6bbb3ec223 100644 --- a/python-avd/pyavd/_eos_designs/structured_config/core_interfaces_and_l3_edge/router_ospf.py +++ b/python-avd/pyavd/_eos_designs/structured_config/core_interfaces_and_l3_edge/router_ospf.py @@ -3,10 +3,10 @@ # 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 @@ -19,8 +19,8 @@ class RouterOspfMixin(Protocol): Class should only be used as Mixin to a AvdStructuredConfig class. """ - @cached_property - def router_ospf(self: AvdStructuredConfigCoreInterfacesAndL3EdgeProtocol) -> dict | None: + @structured_config_contributor + def router_ospf(self: AvdStructuredConfigCoreInterfacesAndL3EdgeProtocol) -> None: """Return structured config for router_ospf.""" if not self.shared_utils.underlay_ospf: return From 73466be4246d66919f6a947bda359e84263905df Mon Sep 17 00:00:00 2001 From: Shivani-gslab <145646625+Shivani-gslab@users.noreply.github.com> Date: Wed, 5 Feb 2025 11:22:39 +0530 Subject: [PATCH 4/6] Update python-avd/pyavd/_eos_designs/structured_config/core_interfaces_and_l3_edge/router_ospf.py --- .../core_interfaces_and_l3_edge/router_ospf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python-avd/pyavd/_eos_designs/structured_config/core_interfaces_and_l3_edge/router_ospf.py b/python-avd/pyavd/_eos_designs/structured_config/core_interfaces_and_l3_edge/router_ospf.py index d6bbb3ec223..f7836964719 100644 --- a/python-avd/pyavd/_eos_designs/structured_config/core_interfaces_and_l3_edge/router_ospf.py +++ b/python-avd/pyavd/_eos_designs/structured_config/core_interfaces_and_l3_edge/router_ospf.py @@ -21,7 +21,7 @@ class RouterOspfMixin(Protocol): @structured_config_contributor def router_ospf(self: AvdStructuredConfigCoreInterfacesAndL3EdgeProtocol) -> None: - """Return structured config for router_ospf.""" + """Set the structured config for router_ospf.""" if not self.shared_utils.underlay_ospf: return From 6a93fdd3bec01474b83e187f40d6c10d354d9887 Mon Sep 17 00:00:00 2001 From: Shivani-gslab <145646625+Shivani-gslab@users.noreply.github.com> Date: Thu, 6 Feb 2025 18:41:05 +0530 Subject: [PATCH 5/6] Apply suggestion Co-authored-by: Vibhu-gslab <109593615+Vibhu-gslab@users.noreply.github.com> --- .../core_interfaces_and_l3_edge/router_ospf.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/python-avd/pyavd/_eos_designs/structured_config/core_interfaces_and_l3_edge/router_ospf.py b/python-avd/pyavd/_eos_designs/structured_config/core_interfaces_and_l3_edge/router_ospf.py index f7836964719..62d9d0c9518 100644 --- a/python-avd/pyavd/_eos_designs/structured_config/core_interfaces_and_l3_edge/router_ospf.py +++ b/python-avd/pyavd/_eos_designs/structured_config/core_interfaces_and_l3_edge/router_ospf.py @@ -31,9 +31,7 @@ def router_ospf(self: AvdStructuredConfigCoreInterfacesAndL3EdgeProtocol) -> Non no_passive_interfaces.append(p2p_link_data["interface"]) if no_passive_interfaces: - self.structured_config.router_ospf.process_ids.append( - EosCliConfigGen.RouterOspf.ProcessIdsItem( + 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), - ) ) From b9a6b6742890144cb553474d19caa59809716701 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 6 Feb 2025 13:15:40 +0000 Subject: [PATCH 6/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../core_interfaces_and_l3_edge/router_ospf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python-avd/pyavd/_eos_designs/structured_config/core_interfaces_and_l3_edge/router_ospf.py b/python-avd/pyavd/_eos_designs/structured_config/core_interfaces_and_l3_edge/router_ospf.py index 62d9d0c9518..500c45f5e85 100644 --- a/python-avd/pyavd/_eos_designs/structured_config/core_interfaces_and_l3_edge/router_ospf.py +++ b/python-avd/pyavd/_eos_designs/structured_config/core_interfaces_and_l3_edge/router_ospf.py @@ -32,6 +32,6 @@ def router_ospf(self: AvdStructuredConfigCoreInterfacesAndL3EdgeProtocol) -> Non if no_passive_interfaces: 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), + id=self.inputs.underlay_ospf_process_id, + no_passive_interfaces=EosCliConfigGen.RouterOspf.ProcessIdsItem.NoPassiveInterfaces(no_passive_interfaces), )