From f1ea566168a84d2764ec71e776264c40f199a2a1 Mon Sep 17 00:00:00 2001 From: Claus Holbech Date: Thu, 5 Sep 2024 15:31:44 +0200 Subject: [PATCH] Refactor(eos_designs)!: Import AvdIpAddressing class from PyAVD (#4422) --- .../arista/avd/docs/porting-guides/5.x.x.md | 11 ++++++++++- .../custom_modules/custom_ip_addressing.py | 3 +-- .../group_vars/UPLINK_P2P_VRFS_TESTS.yml | 2 -- .../plugins/plugin_utils/utils/__init__.py | 8 +++----- .../python_modules/MOVED_TO_PYAVD.txt | 2 ++ .../python_modules/ip_addressing/__init__.py | 19 ------------------- .../_cv/workflows/deploy_configs_to_cv.py | 1 - .../pyavd/_cv/workflows/deploy_to_cv.py | 1 - .../shared_utils/ip_addressing.py | 2 +- .../network_services/utils.py | 2 +- .../structured_config/overlay/router_bgp.py | 4 ++-- .../ip_addressing/__init__.py | 0 .../ip_addressing/utils.py | 0 13 files changed, 20 insertions(+), 35 deletions(-) delete mode 100644 ansible_collections/arista/avd/roles/eos_designs/python_modules/ip_addressing/__init__.py rename python-avd/pyavd/{_eos_designs => api}/ip_addressing/__init__.py (100%) rename python-avd/pyavd/{_eos_designs => api}/ip_addressing/utils.py (100%) diff --git a/ansible_collections/arista/avd/docs/porting-guides/5.x.x.md b/ansible_collections/arista/avd/docs/porting-guides/5.x.x.md index 08c28843b6d..7409ac04eac 100644 --- a/ansible_collections/arista/avd/docs/porting-guides/5.x.x.md +++ b/ansible_collections/arista/avd/docs/porting-guides/5.x.x.md @@ -75,7 +75,16 @@ The following ansible plugins have been removed from the `arista.avd` Ansible co TODO: Level 3 sections for each change with details on how to migrate -### AvdInterfaceDescriptions breaking changes +### Base class for custom IP addressing `AvdIpAddressing` was moved + +The `AvdIpAddressing` class was moved from the Ansible collection to `pyavd.api.ip_addressing`. Import statements must be updated. + +```diff +- from ansible_collections.arista.avd.roles.eos_designs.python_modules.ip_addressing import AvdIpAddressing ++ from pyavd.api.ip_addressing import AvdIpAddressing +``` + +### Base class for custom interface descriptions `AvdInterfaceDescriptions` breaking changes The `AvdInterfaceDescriptions` class and the associated `InterfaceDescriptionData` data class were moved from the Ansible collection to `pyavd.api.interface_descriptions`. Import statements must be updated. diff --git a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/custom_modules/custom_ip_addressing.py b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/custom_modules/custom_ip_addressing.py index 08f202021fd..f3c6fd5351b 100644 --- a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/custom_modules/custom_ip_addressing.py +++ b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/custom_modules/custom_ip_addressing.py @@ -3,8 +3,7 @@ # that can be found in the LICENSE file. from functools import cached_property -# TODO: AVD5.0 change this to import from PyAVD instead and remove the python_modules folder. -from ansible_collections.arista.avd.roles.eos_designs.python_modules.ip_addressing import AvdIpAddressing +from pyavd.api.ip_addressing import AvdIpAddressing class CustomAvdIpAddressing(AvdIpAddressing): diff --git a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/UPLINK_P2P_VRFS_TESTS.yml b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/UPLINK_P2P_VRFS_TESTS.yml index 058aac5da76..b4aed76121a 100644 --- a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/UPLINK_P2P_VRFS_TESTS.yml +++ b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/UPLINK_P2P_VRFS_TESTS.yml @@ -1,8 +1,6 @@ --- # TODO: Add tests for rfc5549, overlay_routing_protocol: none with bgp peers etc under network services (since this uplink type expands bgp support there) overlay_routing_protocol: none -# This is set to true by default on the nodes with uplink_type == p2p-vrfs -# new_network_services_bgp_vrf_config: true node_type_keys: # modify spine to get l3 network_services diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/utils/__init__.py b/ansible_collections/arista/avd/plugins/plugin_utils/utils/__init__.py index 6f46169d93a..4e95bbe4269 100644 --- a/ansible_collections/arista/avd/plugins/plugin_utils/utils/__init__.py +++ b/ansible_collections/arista/avd/plugins/plugin_utils/utils/__init__.py @@ -14,11 +14,11 @@ from .yaml_dumper import NoAliasDumper, YamlDumper from .yaml_loader import YamlLoader -# TODO: AVD5.0.0 Some utils are exposed in custom modules code, so we will need to keep it here until 5.0 +# TODO: The pyavd imports can be removed once validate_state has been moved to pyavd. try: - from pyavd._utils import default, get, template, template_var + from pyavd._utils import default, get except ImportError as e: - default = get = template = template_var = RaiseOnUse(ImportError(f"The 'arista.avd' collection requires the 'pyavd' Python library. Got import error {e}")) + default = get = RaiseOnUse(ImportError(f"The 'arista.avd' collection requires the 'pyavd' Python library. Got import error {e}")) __all__ = [ "compile_searchpath", @@ -34,7 +34,5 @@ "YamlLoader", "default", "get", - "template", - "template_var", "write_file", ] diff --git a/ansible_collections/arista/avd/roles/eos_designs/python_modules/MOVED_TO_PYAVD.txt b/ansible_collections/arista/avd/roles/eos_designs/python_modules/MOVED_TO_PYAVD.txt index b48ae49ac62..bd17c30c390 100644 --- a/ansible_collections/arista/avd/roles/eos_designs/python_modules/MOVED_TO_PYAVD.txt +++ b/ansible_collections/arista/avd/roles/eos_designs/python_modules/MOVED_TO_PYAVD.txt @@ -1 +1,3 @@ All Python modules have been moved to PyAVD in the folder /python-avd/pyavd/_eos_designs/structured_config/ + +Base classes from ip_addressing and interface_descriptions can be imported from pyavd.api.ip_addressing and pyavd.api.interface_descriptions. diff --git a/ansible_collections/arista/avd/roles/eos_designs/python_modules/ip_addressing/__init__.py b/ansible_collections/arista/avd/roles/eos_designs/python_modules/ip_addressing/__init__.py deleted file mode 100644 index 4a62f2fe9a4..00000000000 --- a/ansible_collections/arista/avd/roles/eos_designs/python_modules/ip_addressing/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (c) 2023-2024 Arista Networks, Inc. -# Use of this source code is governed by the Apache License 2.0 -# that can be found in the LICENSE file. -from ansible.errors import AnsibleActionFail - -from ansible_collections.arista.avd.plugins.plugin_utils.pyavd_wrappers import RaiseOnUse - -try: - from pyavd._eos_designs.ip_addressing import AvdIpAddressing -except ImportError as e: - AvdIpAddressing = RaiseOnUse( - AnsibleActionFail( - "The 'arista.avd.eos_designs' collection requires the 'pyavd' Python library. Got import error", - orig_exc=e, - ), - ) - - -__all__ = ["AvdIpAddressing"] diff --git a/python-avd/pyavd/_cv/workflows/deploy_configs_to_cv.py b/python-avd/pyavd/_cv/workflows/deploy_configs_to_cv.py index cffabfc5467..789a2efb8fc 100644 --- a/python-avd/pyavd/_cv/workflows/deploy_configs_to_cv.py +++ b/python-avd/pyavd/_cv/workflows/deploy_configs_to_cv.py @@ -31,7 +31,6 @@ async def deploy_configs_to_cv(configs: list[CVEosConfig], result: DeployToCvRes - Upload Configlets and assign to devices. TODO: See if this can be optimized to check if the configlets are already in place and correct. A hash would have been nice. - TODO: Split long configs into multiple configlets for 990KB chunks. Need to figure out how to batch it. """ LOGGER.info("deploy_configs_to_cv: %s", len(configs)) diff --git a/python-avd/pyavd/_cv/workflows/deploy_to_cv.py b/python-avd/pyavd/_cv/workflows/deploy_to_cv.py index 9a972bb5d06..905d8094a8a 100644 --- a/python-avd/pyavd/_cv/workflows/deploy_to_cv.py +++ b/python-avd/pyavd/_cv/workflows/deploy_to_cv.py @@ -50,7 +50,6 @@ async def deploy_to_cv( For any device referred under `configs`, `device_tags` and `interface_tags` the device: - The device must be present in the CloudVision Inventory and onboarded to the "Inventory & Topology Studio". - - TODO: See if we can relax the I&T requirement and add the device if it is missing. - TODO: See if we can onboard ZTP devices and/or preprovision. - The hostname will we updated in the I&T Studio. - The `serial_number` and `system_mac_address` properties will be inplace updated in the given CVDevice objects. diff --git a/python-avd/pyavd/_eos_designs/shared_utils/ip_addressing.py b/python-avd/pyavd/_eos_designs/shared_utils/ip_addressing.py index c60abe18bfa..e745dad3875 100644 --- a/python-avd/pyavd/_eos_designs/shared_utils/ip_addressing.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/ip_addressing.py @@ -6,8 +6,8 @@ from functools import cached_property from typing import TYPE_CHECKING -from pyavd._eos_designs.ip_addressing import AvdIpAddressing from pyavd._utils import get, load_python_class, merge +from pyavd.api.ip_addressing import AvdIpAddressing if TYPE_CHECKING: from . import SharedUtils diff --git a/python-avd/pyavd/_eos_designs/structured_config/network_services/utils.py b/python-avd/pyavd/_eos_designs/structured_config/network_services/utils.py index 48c4892c181..53b0d93236d 100644 --- a/python-avd/pyavd/_eos_designs/structured_config/network_services/utils.py +++ b/python-avd/pyavd/_eos_designs/structured_config/network_services/utils.py @@ -988,7 +988,7 @@ def _generate_ipsec_key(self: AvdStructuredConfigNetworkServices, name: str, sal Run type-7 obfuscation using a algorithmic salt so we ensure the same key every time. - TODO: Maybe introduce some formatting with max length of each element, since the keys can be come very very long. + TODO: Maybe introduce some formatting with max length of each element, since the keys can become very very long. """ secret = f"{self.shared_utils.hostname}_{name}_{salt}" type_7_salt = sum(salt.encode("utf-8")) % 16 diff --git a/python-avd/pyavd/_eos_designs/structured_config/overlay/router_bgp.py b/python-avd/pyavd/_eos_designs/structured_config/overlay/router_bgp.py index 72e7f3fcf72..e503dbab65b 100644 --- a/python-avd/pyavd/_eos_designs/structured_config/overlay/router_bgp.py +++ b/python-avd/pyavd/_eos_designs/structured_config/overlay/router_bgp.py @@ -393,8 +393,8 @@ def _address_family_rtc(self: AvdStructuredConfigOverlay) -> dict | None: core_peer_group["default_route_target"] = {"only": True} peer_groups.append(core_peer_group) - # Transposing the Jinja2 logic which is that if the selfevpn_overlay_core peer group is not - # configured thenthe default_route_target is applied in the evpn_overlay_peers peer group. + # Transposing the Jinja2 logic: if the evpn_overlay_core peer group is not + # configured then the default_route_target is applied in the evpn_overlay_peers peer group. elif self.shared_utils.evpn_role == "server": evpn_overlay_peers["default_route_target"] = {"only": True} diff --git a/python-avd/pyavd/_eos_designs/ip_addressing/__init__.py b/python-avd/pyavd/api/ip_addressing/__init__.py similarity index 100% rename from python-avd/pyavd/_eos_designs/ip_addressing/__init__.py rename to python-avd/pyavd/api/ip_addressing/__init__.py diff --git a/python-avd/pyavd/_eos_designs/ip_addressing/utils.py b/python-avd/pyavd/api/ip_addressing/utils.py similarity index 100% rename from python-avd/pyavd/_eos_designs/ip_addressing/utils.py rename to python-avd/pyavd/api/ip_addressing/utils.py