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): Refactor eos_designs structured_config code for monitor_connectivity #4947

Draft
wants to merge 3 commits into
base: devel
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ zscaler_endpoints:
ip_address: 10.37.121.1 # Not the correct address

expected_error_message: >-
Found duplicate objects with conflicting data while generating configuration for Tunnel interface for Internet Exit policy.
{'name': 'Tunnel100', 'description': 'Internet Exit ZSCALER-EXIT-POLICY-2 PRI',
'ipsec_profile': 'IE-ZSCALER-EXIT-POLICY-2-PROFILE', 'source_interface': 'Ethernet2'}
Found duplicate objects with conflicting data while generating configuration for Hosts.
{'name': 'IE-Tunnel100', 'description': 'Internet Exit ZSCALER-EXIT-POLICY-2 PRI', 'ip': '10.37.121.1',
'local_interfaces': 'SET-Tunnel100', 'address_only': False, 'url': 'http://gateway.zscalerbeta.net/vpntest'}
conflicts with
{'name': 'Tunnel100', 'description': 'Internet Exit ZSCALER-EXIT-POLICY-1 PRI',
'ipsec_profile': 'IE-ZSCALER-EXIT-POLICY-1-PROFILE', 'source_interface': 'Ethernet1'}.
{'name': 'IE-Tunnel100', 'description': 'Internet Exit ZSCALER-EXIT-POLICY-1 PRI', 'ip': '10.37.121.1',
'local_interfaces': 'SET-Tunnel100', 'address_only': False, 'url': 'http://gateway.zscalerbeta.net/vpntest'}.
Original file line number Diff line number Diff line change
Expand Up @@ -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._utils import append_if_not_duplicate, strip_empties_from_dict
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 AvdStructuredConfigNetworkServicesProtocol
Expand All @@ -19,55 +19,33 @@ class MonitorConnectivityMixin(Protocol):
Class should only be used as Mixin to a AvdStructuredConfig class.
"""

@cached_property
def monitor_connectivity(self: AvdStructuredConfigNetworkServicesProtocol) -> dict | None:
@structured_config_contributor
def monitor_connectivity(self: AvdStructuredConfigNetworkServicesProtocol) -> None:
"""
Return structured config for monitor_connectivity.

Only used for CV Pathfinder edge routers today
"""
if not self._filtered_internet_exit_policies_and_connections:
return None

monitor_connectivity = {}
interface_sets = []
hosts = []
return

for _policy, connections in self._filtered_internet_exit_policies_and_connections:
for connection in connections:
interface_name = f"Tunnel{connection['tunnel_id']}" if connection["type"] == "tunnel" else connection["source_interface"]

interface_set_name = f"SET-{self.shared_utils.sanitize_interface_name(interface_name)}"
interface_sets.append(
{
"name": interface_set_name,
"interfaces": interface_name,
},
)

host = {
"name": connection["monitor_name"],
"description": connection["description"],
"ip": connection["monitor_host"],
"local_interfaces": interface_set_name,
"address_only": False,
"url": connection.get("monitor_url"),
}
append_if_not_duplicate(
list_of_dicts=hosts,
primary_key="name",
new_dict=host,
context="Monitor connectivity host for Internet Exit policy",
context_keys=["name"],
interface_set = EosCliConfigGen.MonitorConnectivity.InterfaceSetsItem(name=interface_set_name, interfaces=interface_name)
self.structured_config.monitor_connectivity.interface_sets.append(interface_set)

host = EosCliConfigGen.MonitorConnectivity.HostsItem(
name=connection["monitor_name"],
description=connection["description"],
ip=connection["monitor_host"],
local_interfaces=interface_set_name,
address_only=False,
url=connection.get("monitor_url"),
)
self.structured_config.monitor_connectivity.hosts.append(host)

monitor_connectivity["interface_sets"] = interface_sets
monitor_connectivity["hosts"] = hosts

monitor_connectivity = strip_empties_from_dict(monitor_connectivity)

if monitor_connectivity:
monitor_connectivity["shutdown"] = False
return monitor_connectivity

return None
if self.structured_config.monitor_connectivity:
self.structured_config.monitor_connectivity.shutdown = False