From 8ba6031da48ec85e6887d9d1e82c2e52dddb5b4a Mon Sep 17 00:00:00 2001 From: gmuloc Date: Fri, 20 Sep 2024 00:02:46 +0200 Subject: [PATCH 1/6] Feat(eos_designs): Add possibility to change network mask for direct WAN HA link --- .../intended/configs/cv-pathfinder-edge3A.cfg | 4 +-- .../intended/configs/cv-pathfinder-edge3B.cfg | 4 +-- .../cv-pathfinder-edge3A.yml | 4 +-- .../cv-pathfinder-edge3B.yml | 4 +-- .../group_vars/CV_PATHFINDER_TESTS.yml | 4 +++ .../docs/tables/fabric-ip-addressing.md | 8 +++++ .../schema/eos_designs.schema.yml | 14 +++++++++ .../fabric_ip_addressing.schema.yml | 12 ++++++++ .../pyavd/_eos_designs/shared_utils/misc.py | 4 +++ .../pyavd/_eos_designs/shared_utils/wan.py | 30 +++++-------------- .../pyavd/api/ip_addressing/__init__.py | 21 +++++++++++++ python-avd/pyavd/api/ip_addressing/utils.py | 4 +++ 12 files changed, 82 insertions(+), 31 deletions(-) diff --git a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/configs/cv-pathfinder-edge3A.cfg b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/configs/cv-pathfinder-edge3A.cfg index 0a3b5d1b354..633d69785de 100644 --- a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/configs/cv-pathfinder-edge3A.cfg +++ b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/configs/cv-pathfinder-edge3A.cfg @@ -127,7 +127,7 @@ router path-selection ! peer static router-ip 192.168.142.7 name cv-pathfinder-edge3B - ipv4 address 10.10.10.1 + ipv4 address 10.10.10.2 ! load-balance policy LB-DEFAULT-AVT-POLICY-CONTROL-PLANE path-group INET @@ -226,7 +226,7 @@ interface Ethernet52 no shutdown mtu 9100 no switchport - ip address 10.10.10.0/31 + ip address 10.10.10.1/24 ! interface Loopback0 description ROUTER_ID diff --git a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/configs/cv-pathfinder-edge3B.cfg b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/configs/cv-pathfinder-edge3B.cfg index 329e6696a9c..54b0f54d9cb 100644 --- a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/configs/cv-pathfinder-edge3B.cfg +++ b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/configs/cv-pathfinder-edge3B.cfg @@ -114,7 +114,7 @@ router path-selection ! peer static router-ip 192.168.142.6 name cv-pathfinder-edge3A - ipv4 address 10.10.10.0 + ipv4 address 10.10.10.1 ! path-group MPLS id 100 keepalive interval 300 milliseconds failure-threshold 5 intervals @@ -226,7 +226,7 @@ interface Ethernet52 no shutdown mtu 9100 no switchport - ip address 10.10.10.1/31 + ip address 10.10.10.2/24 ! interface Loopback0 description ROUTER_ID diff --git a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/structured_configs/cv-pathfinder-edge3A.yml b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/structured_configs/cv-pathfinder-edge3A.yml index 9ea401b5caf..e0236945e7f 100644 --- a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/structured_configs/cv-pathfinder-edge3A.yml +++ b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/structured_configs/cv-pathfinder-edge3A.yml @@ -163,7 +163,7 @@ ethernet_interfaces: peer: cv-pathfinder-edge3B shutdown: false description: DIRECT LAN HA LINK - ip_address: 10.10.10.0/31 + ip_address: 10.10.10.1/24 flow_tracker: null mtu: 9100 loopback_interfaces: @@ -417,7 +417,7 @@ router_path_selection: - router_ip: 192.168.142.7 name: cv-pathfinder-edge3B ipv4_addresses: - - 10.10.10.1 + - 10.10.10.2 ipsec_profile: DP-PROFILE load_balance_policies: - name: LB-DEFAULT-AVT-POLICY-CONTROL-PLANE diff --git a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/structured_configs/cv-pathfinder-edge3B.yml b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/structured_configs/cv-pathfinder-edge3B.yml index c5c100c2124..b55e7a2b28c 100644 --- a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/structured_configs/cv-pathfinder-edge3B.yml +++ b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/structured_configs/cv-pathfinder-edge3B.yml @@ -162,7 +162,7 @@ ethernet_interfaces: peer: cv-pathfinder-edge3A shutdown: false description: DIRECT LAN HA LINK - ip_address: 10.10.10.1/31 + ip_address: 10.10.10.2/24 flow_tracker: null mtu: 9100 loopback_interfaces: @@ -417,7 +417,7 @@ router_path_selection: - router_ip: 192.168.142.6 name: cv-pathfinder-edge3A ipv4_addresses: - - 10.10.10.0 + - 10.10.10.1 ipsec_profile: DP-PROFILE load_balance_policies: - name: LB-DEFAULT-AVT-POLICY-CONTROL-PLANE diff --git a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/CV_PATHFINDER_TESTS.yml b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/CV_PATHFINDER_TESTS.yml index f38cb9daa7a..b02008dfd6a 100644 --- a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/CV_PATHFINDER_TESTS.yml +++ b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/CV_PATHFINDER_TESTS.yml @@ -59,6 +59,10 @@ bgp_peer_groups: - 192.168.142.0/24 - 192.168.143.0/24 +fabric_ip_addressing: + wan_ha: + ipv4_prefix_length: 24 + wan_stun_dtls_profile_name: profileA wan_route_servers: diff --git a/ansible_collections/arista/avd/roles/eos_designs/docs/tables/fabric-ip-addressing.md b/ansible_collections/arista/avd/roles/eos_designs/docs/tables/fabric-ip-addressing.md index 5a31cd414eb..a636aad54f2 100644 --- a/ansible_collections/arista/avd/roles/eos_designs/docs/tables/fabric-ip-addressing.md +++ b/ansible_collections/arista/avd/roles/eos_designs/docs/tables/fabric-ip-addressing.md @@ -14,6 +14,8 @@ | [    ipv6_prefix_length](## "fabric_ip_addressing.mlag.ipv6_prefix_length") | Integer | | `64` | Min: 1
Max: 127 | IPv6 prefix length used for MLAG peer-vlan and L3 point-to-point SVIs over the MLAG peer-link. | | [  p2p_uplinks](## "fabric_ip_addressing.p2p_uplinks") | Dictionary | | | | | | [    ipv4_prefix_length](## "fabric_ip_addressing.p2p_uplinks.ipv4_prefix_length") | Integer | | `31` | Min: 1
Max: 31 | IPv4 prefix length used for L3 point-to-point uplinks. | + | [  wan_ha](## "fabric_ip_addressing.wan_ha") | Dictionary | | | | Allow to manipulate the IP addressing scheme for WAN HA direct subnets. | + | [    ipv4_prefix_length](## "fabric_ip_addressing.wan_ha.ipv4_prefix_length") | Integer | | `31` | Min: 1
Max: 31 | IPv4 prefix length used for point-to-point interface for direct WAN HA link. | === "YAML" @@ -41,4 +43,10 @@ # IPv4 prefix length used for L3 point-to-point uplinks. ipv4_prefix_length: + + # Allow to manipulate the IP addressing scheme for WAN HA direct subnets. + wan_ha: + + # IPv4 prefix length used for point-to-point interface for direct WAN HA link. + ipv4_prefix_length: ``` diff --git a/python-avd/pyavd/_eos_designs/schema/eos_designs.schema.yml b/python-avd/pyavd/_eos_designs/schema/eos_designs.schema.yml index 35581fddd55..89f9efd195e 100644 --- a/python-avd/pyavd/_eos_designs/schema/eos_designs.schema.yml +++ b/python-avd/pyavd/_eos_designs/schema/eos_designs.schema.yml @@ -1374,6 +1374,20 @@ keys: convert_types: - str description: IPv4 prefix length used for L3 point-to-point uplinks. + wan_ha: + type: dict + description: Allow to manipulate the IP addressing scheme for WAN HA direct + subnets. + keys: + ipv4_prefix_length: + type: int + default: 31 + min: 1 + max: 31 + convert_types: + - str + description: IPv4 prefix length used for point-to-point interface for + direct WAN HA link. fabric_name: documentation_options: table: fabric-topology diff --git a/python-avd/pyavd/_eos_designs/schema/schema_fragments/fabric_ip_addressing.schema.yml b/python-avd/pyavd/_eos_designs/schema/schema_fragments/fabric_ip_addressing.schema.yml index d77116523d8..c196b9a7000 100644 --- a/python-avd/pyavd/_eos_designs/schema/schema_fragments/fabric_ip_addressing.schema.yml +++ b/python-avd/pyavd/_eos_designs/schema/schema_fragments/fabric_ip_addressing.schema.yml @@ -56,3 +56,15 @@ keys: convert_types: - str description: IPv4 prefix length used for L3 point-to-point uplinks. + wan_ha: + type: dict + description: Allow to manipulate the IP addressing scheme for WAN HA direct subnets. + keys: + ipv4_prefix_length: + type: int + default: 31 + min: 1 + max: 31 + convert_types: + - str + description: IPv4 prefix length used for point-to-point interface for direct WAN HA link. diff --git a/python-avd/pyavd/_eos_designs/shared_utils/misc.py b/python-avd/pyavd/_eos_designs/shared_utils/misc.py index dbebbae66de..a6c9972ed50 100644 --- a/python-avd/pyavd/_eos_designs/shared_utils/misc.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/misc.py @@ -323,6 +323,10 @@ def fabric_ip_addressing_mlag_ipv6_prefix_length(self: SharedUtils) -> int: def fabric_ip_addressing_p2p_uplinks_ipv4_prefix_length(self: SharedUtils) -> int: return get(self.hostvars, "fabric_ip_addressing.p2p_uplinks.ipv4_prefix_length", default=31) + @cached_property + def fabric_ip_addressing_wan_ha_ipv4_prefix_length(self: SharedUtils) -> int: + return get(self.hostvars, "fabric_ip_addressing.wan_ha.ipv4_prefix_length", default=31) + @cached_property def fabric_sflow_uplinks(self: SharedUtils) -> bool | None: return get(self.hostvars, "fabric_sflow.uplinks") diff --git a/python-avd/pyavd/_eos_designs/shared_utils/wan.py b/python-avd/pyavd/_eos_designs/shared_utils/wan.py index 14b53ca1fc6..3247da774ad 100644 --- a/python-avd/pyavd/_eos_designs/shared_utils/wan.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/wan.py @@ -7,7 +7,7 @@ from typing import TYPE_CHECKING, Literal from pyavd._errors import AristaAvdError, AristaAvdMissingVariableError -from pyavd._utils import default, get, get_ip_from_ip_prefix, get_ip_from_pool, get_item, strip_empties_from_dict +from pyavd._utils import default, get, get_ip_from_ip_prefix, get_item, strip_empties_from_dict from pyavd.j2filters import natural_sort if TYPE_CHECKING: @@ -568,7 +568,7 @@ def wan_ha_peer_ip_addresses(self: SharedUtils) -> list: ip_addresses.append(f"{ip_address}/{prefix_length}") else: # Only one supported HA interface today when not using uplinks - ip_addresses.append(self.get_wan_ha_ip_address(local=False)) + ip_addresses.append(self.ip_addressing.get_wan_ha_ip_address(local=False)) return ip_addresses @cached_property @@ -595,35 +595,19 @@ def wan_ha_ip_addresses(self: SharedUtils) -> list: ip_addresses.append(f"{ip_address}/{prefix_length}") else: # Only one supported HA interface today when not using uplinks - ip_addresses.append(self.get_wan_ha_ip_address(local=True)) + ip_addresses.append(self.ip_addressing.get_wan_ha_ip_address(local=True)) return ip_addresses - def get_wan_ha_ip_address(self: SharedUtils, local: bool) -> str | None: - """ - Render ipv4 address for wan_ha_ip_address using dynamically loaded python module. - - local: When true, request the first IP address else request the remote peer IP. - TODO: Move this to ip_addressing module to allow for custom logic. - """ - wan_ha_ipv4_pool = get( + @cached_property + def wan_ha_ipv4_pool(self: SharedUtils) -> str: + """Return the configured wan_ha.ha_ipv4_pool.""" + return get( self.switch_data_combined, "wan_ha.ha_ipv4_pool", required=True, org_key="Missing `wan_ha.ha_ipv4_pool` node settings to allocate an IP address to defined HA interface", ) - first_ip_address = get_ip_from_pool(wan_ha_ipv4_pool, 31, 0, 0) - second_ip_address = get_ip_from_pool(wan_ha_ipv4_pool, 31, 0, 1) - - if self.is_first_ha_peer: - local_ip, remote_ip = first_ip_address, second_ip_address - else: - local_ip, remote_ip = second_ip_address, first_ip_address - - ip_address = local_ip if local else remote_ip - - return f"{ip_address}/31" - def generate_lb_policy_name(self: SharedUtils, name: str) -> str: """Returns LB-{name}.""" return f"LB-{name}" diff --git a/python-avd/pyavd/api/ip_addressing/__init__.py b/python-avd/pyavd/api/ip_addressing/__init__.py index fd08dc88254..892cd6abb7b 100644 --- a/python-avd/pyavd/api/ip_addressing/__init__.py +++ b/python-avd/pyavd/api/ip_addressing/__init__.py @@ -331,3 +331,24 @@ def evpn_underlay_l2_multicast_group( """Return IP address to be used for EVPN underlay L2 multicast group.""" offset = vlan_id - 1 + underlay_l2_multicast_group_ipv4_pool_offset return get_ip_from_pool(underlay_l2_multicast_group_ipv4_pool, 32, offset, 0) + + def get_wan_ha_ip_address(self, local: bool) -> str | None: + """ + Render ipv4 address for wan_ha_ip_address using dynamically loaded python module. + + local: When true, request the first IP address else request the remote peer IP. + """ + wan_ha_ipv4_pool = self.shared_utils.wan_ha_ipv4_pool + prefixlen = self._fabric_ip_addressing_wan_ha_ipv4_prefix_length + + first_ip_address = get_ip_from_pool(wan_ha_ipv4_pool, prefixlen, 0, 0) + second_ip_address = get_ip_from_pool(wan_ha_ipv4_pool, prefixlen, 0, 1) + + if self.shared_utils.is_first_ha_peer: + local_ip, remote_ip = first_ip_address, second_ip_address + else: + local_ip, remote_ip = second_ip_address, first_ip_address + + ip_address = local_ip if local else remote_ip + + return f"{ip_address}/{prefixlen}" diff --git a/python-avd/pyavd/api/ip_addressing/utils.py b/python-avd/pyavd/api/ip_addressing/utils.py index 2b2bed7c57d..823ebe454cf 100644 --- a/python-avd/pyavd/api/ip_addressing/utils.py +++ b/python-avd/pyavd/api/ip_addressing/utils.py @@ -193,3 +193,7 @@ def _get_p2p_ipv4_pool_and_offset(self: AvdIpAddressing, uplink_switch_index: in return (uplink_pool, uplink_offset) return (downlink_pool, downlink_offset) + + @cached_property + def _fabric_ip_addressing_wan_ha_ipv4_prefix_length(self: AvdIpAddressing) -> int: + return self.shared_utils.fabric_ip_addressing_wan_ha_ipv4_prefix_length From db668e0d6dd3bda6f2e8a7dfb601ff8434ffe1db Mon Sep 17 00:00:00 2001 From: gmuloc Date: Fri, 20 Sep 2024 15:30:35 +0200 Subject: [PATCH 2/6] Refactor: Address PR comment --- .../pyavd/_eos_designs/shared_utils/wan.py | 4 +-- .../pyavd/api/ip_addressing/__init__.py | 25 ++++++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/python-avd/pyavd/_eos_designs/shared_utils/wan.py b/python-avd/pyavd/_eos_designs/shared_utils/wan.py index 3247da774ad..d5a02f01b2d 100644 --- a/python-avd/pyavd/_eos_designs/shared_utils/wan.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/wan.py @@ -568,7 +568,7 @@ def wan_ha_peer_ip_addresses(self: SharedUtils) -> list: ip_addresses.append(f"{ip_address}/{prefix_length}") else: # Only one supported HA interface today when not using uplinks - ip_addresses.append(self.ip_addressing.get_wan_ha_ip_address(local=False)) + ip_addresses.append(self.ip_addressing.wan_ha_ip_remote()) return ip_addresses @cached_property @@ -595,7 +595,7 @@ def wan_ha_ip_addresses(self: SharedUtils) -> list: ip_addresses.append(f"{ip_address}/{prefix_length}") else: # Only one supported HA interface today when not using uplinks - ip_addresses.append(self.ip_addressing.get_wan_ha_ip_address(local=True)) + ip_addresses.append(self.ip_addressing.get_wan_ha_ip_local()) return ip_addresses @cached_property diff --git a/python-avd/pyavd/api/ip_addressing/__init__.py b/python-avd/pyavd/api/ip_addressing/__init__.py index 892cd6abb7b..66fc4254f3e 100644 --- a/python-avd/pyavd/api/ip_addressing/__init__.py +++ b/python-avd/pyavd/api/ip_addressing/__init__.py @@ -332,23 +332,30 @@ def evpn_underlay_l2_multicast_group( offset = vlan_id - 1 + underlay_l2_multicast_group_ipv4_pool_offset return get_ip_from_pool(underlay_l2_multicast_group_ipv4_pool, 32, offset, 0) - def get_wan_ha_ip_address(self, local: bool) -> str | None: + def wan_ha_ip_local(self) -> str: """ Render ipv4 address for wan_ha_ip_address using dynamically loaded python module. - - local: When true, request the first IP address else request the remote peer IP. """ wan_ha_ipv4_pool = self.shared_utils.wan_ha_ipv4_pool prefixlen = self._fabric_ip_addressing_wan_ha_ipv4_prefix_length - first_ip_address = get_ip_from_pool(wan_ha_ipv4_pool, prefixlen, 0, 0) - second_ip_address = get_ip_from_pool(wan_ha_ipv4_pool, prefixlen, 0, 1) - if self.shared_utils.is_first_ha_peer: - local_ip, remote_ip = first_ip_address, second_ip_address + ip_address = get_ip_from_pool(wan_ha_ipv4_pool, prefixlen, 0, 0) else: - local_ip, remote_ip = second_ip_address, first_ip_address + ip_address = get_ip_from_pool(wan_ha_ipv4_pool, prefixlen, 0, 1) + + return f"{ip_address}/{prefixlen}" + + def wan_ha_ip_remote(self) -> str: + """ + Render ipv4 address for wan_ha_ip_address using dynamically loaded python module. + """ + wan_ha_ipv4_pool = self.shared_utils.wan_ha_ipv4_pool + prefixlen = self._fabric_ip_addressing_wan_ha_ipv4_prefix_length - ip_address = local_ip if local else remote_ip + if self.shared_utils.is_first_ha_peer: + ip_address = get_ip_from_pool(wan_ha_ipv4_pool, prefixlen, 0, 1) + else: + ip_address = get_ip_from_pool(wan_ha_ipv4_pool, prefixlen, 0, 0) return f"{ip_address}/{prefixlen}" From 7880c1bca5351c5c1d82ac34c82eb7fc5bce435b Mon Sep 17 00:00:00 2001 From: gmuloc Date: Fri, 20 Sep 2024 15:48:32 +0200 Subject: [PATCH 3/6] Fix: Wrong funciton name --- python-avd/pyavd/_eos_designs/shared_utils/wan.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python-avd/pyavd/_eos_designs/shared_utils/wan.py b/python-avd/pyavd/_eos_designs/shared_utils/wan.py index d5a02f01b2d..4092edb2485 100644 --- a/python-avd/pyavd/_eos_designs/shared_utils/wan.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/wan.py @@ -595,7 +595,7 @@ def wan_ha_ip_addresses(self: SharedUtils) -> list: ip_addresses.append(f"{ip_address}/{prefix_length}") else: # Only one supported HA interface today when not using uplinks - ip_addresses.append(self.ip_addressing.get_wan_ha_ip_local()) + ip_addresses.append(self.ip_addressing.wan_ha_ip_local()) return ip_addresses @cached_property From c002079d9d402738d224c78d17a9977a8b0af764 Mon Sep 17 00:00:00 2001 From: gmuloc Date: Fri, 20 Sep 2024 17:10:09 +0200 Subject: [PATCH 4/6] CI: In the darkness my old pre-commit friend --- python-avd/pyavd/api/ip_addressing/__init__.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/python-avd/pyavd/api/ip_addressing/__init__.py b/python-avd/pyavd/api/ip_addressing/__init__.py index 66fc4254f3e..6024211f3ad 100644 --- a/python-avd/pyavd/api/ip_addressing/__init__.py +++ b/python-avd/pyavd/api/ip_addressing/__init__.py @@ -333,9 +333,7 @@ def evpn_underlay_l2_multicast_group( return get_ip_from_pool(underlay_l2_multicast_group_ipv4_pool, 32, offset, 0) def wan_ha_ip_local(self) -> str: - """ - Render ipv4 address for wan_ha_ip_address using dynamically loaded python module. - """ + """Render ipv4 address for wan_ha_ip_address using dynamically loaded python module. """ wan_ha_ipv4_pool = self.shared_utils.wan_ha_ipv4_pool prefixlen = self._fabric_ip_addressing_wan_ha_ipv4_prefix_length @@ -347,9 +345,7 @@ def wan_ha_ip_local(self) -> str: return f"{ip_address}/{prefixlen}" def wan_ha_ip_remote(self) -> str: - """ - Render ipv4 address for wan_ha_ip_address using dynamically loaded python module. - """ + """Render ipv4 address for wan_ha_ip_address using dynamically loaded python module. """ wan_ha_ipv4_pool = self.shared_utils.wan_ha_ipv4_pool prefixlen = self._fabric_ip_addressing_wan_ha_ipv4_prefix_length From 780acb5a3338ba253894238c744bb8fb4365d1e9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 20 Sep 2024 15:12:52 +0000 Subject: [PATCH 5/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- python-avd/pyavd/api/ip_addressing/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python-avd/pyavd/api/ip_addressing/__init__.py b/python-avd/pyavd/api/ip_addressing/__init__.py index 6024211f3ad..9554309405c 100644 --- a/python-avd/pyavd/api/ip_addressing/__init__.py +++ b/python-avd/pyavd/api/ip_addressing/__init__.py @@ -333,7 +333,7 @@ def evpn_underlay_l2_multicast_group( return get_ip_from_pool(underlay_l2_multicast_group_ipv4_pool, 32, offset, 0) def wan_ha_ip_local(self) -> str: - """Render ipv4 address for wan_ha_ip_address using dynamically loaded python module. """ + """Render ipv4 address for wan_ha_ip_address using dynamically loaded python module.""" wan_ha_ipv4_pool = self.shared_utils.wan_ha_ipv4_pool prefixlen = self._fabric_ip_addressing_wan_ha_ipv4_prefix_length @@ -345,7 +345,7 @@ def wan_ha_ip_local(self) -> str: return f"{ip_address}/{prefixlen}" def wan_ha_ip_remote(self) -> str: - """Render ipv4 address for wan_ha_ip_address using dynamically loaded python module. """ + """Render ipv4 address for wan_ha_ip_address using dynamically loaded python module.""" wan_ha_ipv4_pool = self.shared_utils.wan_ha_ipv4_pool prefixlen = self._fabric_ip_addressing_wan_ha_ipv4_prefix_length From 59c964161484832c34381785ca2353da77e513ab Mon Sep 17 00:00:00 2001 From: gmuloc Date: Tue, 24 Sep 2024 14:31:45 +0200 Subject: [PATCH 6/6] Refactor: Address PR comments --- python-avd/pyavd/_eos_designs/shared_utils/wan.py | 4 ++-- python-avd/pyavd/api/ip_addressing/__init__.py | 12 ++++++------ python-avd/pyavd/api/ip_addressing/utils.py | 4 ---- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/python-avd/pyavd/_eos_designs/shared_utils/wan.py b/python-avd/pyavd/_eos_designs/shared_utils/wan.py index 4092edb2485..d962f1e4885 100644 --- a/python-avd/pyavd/_eos_designs/shared_utils/wan.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/wan.py @@ -568,7 +568,7 @@ def wan_ha_peer_ip_addresses(self: SharedUtils) -> list: ip_addresses.append(f"{ip_address}/{prefix_length}") else: # Only one supported HA interface today when not using uplinks - ip_addresses.append(self.ip_addressing.wan_ha_ip_remote()) + ip_addresses.append(self.ip_addressing.wan_ha_peer_ip()) return ip_addresses @cached_property @@ -595,7 +595,7 @@ def wan_ha_ip_addresses(self: SharedUtils) -> list: ip_addresses.append(f"{ip_address}/{prefix_length}") else: # Only one supported HA interface today when not using uplinks - ip_addresses.append(self.ip_addressing.wan_ha_ip_local()) + ip_addresses.append(self.ip_addressing.wan_ha_ip()) return ip_addresses @cached_property diff --git a/python-avd/pyavd/api/ip_addressing/__init__.py b/python-avd/pyavd/api/ip_addressing/__init__.py index 9554309405c..352bb60e778 100644 --- a/python-avd/pyavd/api/ip_addressing/__init__.py +++ b/python-avd/pyavd/api/ip_addressing/__init__.py @@ -332,10 +332,10 @@ def evpn_underlay_l2_multicast_group( offset = vlan_id - 1 + underlay_l2_multicast_group_ipv4_pool_offset return get_ip_from_pool(underlay_l2_multicast_group_ipv4_pool, 32, offset, 0) - def wan_ha_ip_local(self) -> str: - """Render ipv4 address for wan_ha_ip_address using dynamically loaded python module.""" + def wan_ha_ip(self) -> str: + """Return the WAN HA local IP address.""" wan_ha_ipv4_pool = self.shared_utils.wan_ha_ipv4_pool - prefixlen = self._fabric_ip_addressing_wan_ha_ipv4_prefix_length + prefixlen = self.shared_utils.fabric_ip_addressing_wan_ha_ipv4_prefix_length if self.shared_utils.is_first_ha_peer: ip_address = get_ip_from_pool(wan_ha_ipv4_pool, prefixlen, 0, 0) @@ -344,10 +344,10 @@ def wan_ha_ip_local(self) -> str: return f"{ip_address}/{prefixlen}" - def wan_ha_ip_remote(self) -> str: - """Render ipv4 address for wan_ha_ip_address using dynamically loaded python module.""" + def wan_ha_peer_ip(self) -> str: + """Return the WAN HA peer IP.""" wan_ha_ipv4_pool = self.shared_utils.wan_ha_ipv4_pool - prefixlen = self._fabric_ip_addressing_wan_ha_ipv4_prefix_length + prefixlen = self.shared_utils.fabric_ip_addressing_wan_ha_ipv4_prefix_length if self.shared_utils.is_first_ha_peer: ip_address = get_ip_from_pool(wan_ha_ipv4_pool, prefixlen, 0, 1) diff --git a/python-avd/pyavd/api/ip_addressing/utils.py b/python-avd/pyavd/api/ip_addressing/utils.py index 823ebe454cf..2b2bed7c57d 100644 --- a/python-avd/pyavd/api/ip_addressing/utils.py +++ b/python-avd/pyavd/api/ip_addressing/utils.py @@ -193,7 +193,3 @@ def _get_p2p_ipv4_pool_and_offset(self: AvdIpAddressing, uplink_switch_index: in return (uplink_pool, uplink_offset) return (downlink_pool, downlink_offset) - - @cached_property - def _fabric_ip_addressing_wan_ha_ipv4_prefix_length(self: AvdIpAddressing) -> int: - return self.shared_utils.fabric_ip_addressing_wan_ha_ipv4_prefix_length