From fde40bd8e3b38631e7e908abf295aad9bf675d79 Mon Sep 17 00:00:00 2001 From: Claus Holbech Date: Tue, 18 Jun 2024 22:17:24 +0200 Subject: [PATCH] Refactor(eos_designs): Move eos_designs_shared_utils to PyAVD (#4126) Co-authored-by: Guillaume Mulocher --- .../eos_designs_internal_notes.md | 2 +- .../avd/plugins/action/eos_designs_facts.py | 4 +-- .../plugins/action/yaml_templates_to_facts.py | 14 +++++++- .../avd/plugins/plugin_utils/avdfacts.py | 2 +- .../MOVED_TO_PYAVD.txt | 1 + .../eos_designs_shared_utils/__init__.py | 6 ---- python-avd/Makefile | 7 +--- .../interface_descriptions/models.py | 2 +- .../_eos_designs/shared_utils/__init__.py | 0 .../shared_utils}/bgp_peer_groups.py | 4 +-- .../shared_utils}/connected_endpoints_keys.py | 6 ++-- .../_eos_designs/shared_utils}/cv_topology.py | 6 ++-- .../shared_utils}/filtered_tenants.py | 16 ++++----- .../shared_utils}/flow_tracking.py | 4 +-- .../shared_utils}/inband_management.py | 6 ++-- .../shared_utils}/interface_descriptions.py | 12 +++---- .../shared_utils}/ip_addressing.py | 16 ++++----- .../shared_utils}/l3_interfaces.py | 6 ++-- .../shared_utils}/link_tracking_groups.py | 4 +-- .../pyavd/_eos_designs/shared_utils}/mgmt.py | 12 +++---- .../pyavd/_eos_designs/shared_utils}/misc.py | 20 +++++------ .../pyavd/_eos_designs/shared_utils}/mlag.py | 19 +++++----- .../_eos_designs/shared_utils}/node_type.py | 10 +++--- .../shared_utils}/node_type_keys.py | 8 ++--- .../_eos_designs/shared_utils}/overlay.py | 12 +++---- .../_eos_designs/shared_utils}/platform.py | 4 +-- .../pyavd/_eos_designs/shared_utils}/ptp.py | 4 +-- .../_eos_designs/shared_utils}/routing.py | 36 +++++++++---------- .../_eos_designs/shared_utils}/switch_data.py | 8 ++--- .../_eos_designs/shared_utils}/underlay.py | 4 +-- .../pyavd/_eos_designs/shared_utils}/utils.py | 11 +++--- .../pyavd/_eos_designs/shared_utils}/wan.py | 12 +++---- .../structured_config/__init__.py | 2 +- python-avd/pyavd/get_avd_facts.py | 8 ++--- python-avd/pyavd/validate_inputs.py | 5 +-- 35 files changed, 142 insertions(+), 151 deletions(-) create mode 100644 ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/MOVED_TO_PYAVD.txt delete mode 100644 ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/__init__.py rename ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/shared_utils.py => python-avd/pyavd/_eos_designs/shared_utils/__init__.py (100%) rename {ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils => python-avd/pyavd/_eos_designs/shared_utils}/bgp_peer_groups.py (96%) rename {ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils => python-avd/pyavd/_eos_designs/shared_utils}/connected_endpoints_keys.py (92%) rename {ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils => python-avd/pyavd/_eos_designs/shared_utils}/cv_topology.py (94%) rename {ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils => python-avd/pyavd/_eos_designs/shared_utils}/filtered_tenants.py (97%) rename {ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils => python-avd/pyavd/_eos_designs/shared_utils}/flow_tracking.py (96%) rename {ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils => python-avd/pyavd/_eos_designs/shared_utils}/inband_management.py (96%) rename {ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils => python-avd/pyavd/_eos_designs/shared_utils}/interface_descriptions.py (85%) rename {ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils => python-avd/pyavd/_eos_designs/shared_utils}/ip_addressing.py (89%) rename {ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils => python-avd/pyavd/_eos_designs/shared_utils}/l3_interfaces.py (92%) rename {ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils => python-avd/pyavd/_eos_designs/shared_utils}/link_tracking_groups.py (92%) rename {ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils => python-avd/pyavd/_eos_designs/shared_utils}/mgmt.py (90%) rename {ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils => python-avd/pyavd/_eos_designs/shared_utils}/misc.py (96%) rename {ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils => python-avd/pyavd/_eos_designs/shared_utils}/mlag.py (92%) rename {ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils => python-avd/pyavd/_eos_designs/shared_utils}/node_type.py (94%) rename {ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils => python-avd/pyavd/_eos_designs/shared_utils}/node_type_keys.py (95%) rename {ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils => python-avd/pyavd/_eos_designs/shared_utils}/overlay.py (96%) rename {ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils => python-avd/pyavd/_eos_designs/shared_utils}/platform.py (98%) rename {ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils => python-avd/pyavd/_eos_designs/shared_utils}/ptp.py (94%) rename {ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils => python-avd/pyavd/_eos_designs/shared_utils}/routing.py (77%) rename {ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils => python-avd/pyavd/_eos_designs/shared_utils}/switch_data.py (92%) rename {ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils => python-avd/pyavd/_eos_designs/shared_utils}/underlay.py (97%) rename {ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils => python-avd/pyavd/_eos_designs/shared_utils}/utils.py (89%) rename {ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils => python-avd/pyavd/_eos_designs/shared_utils}/wan.py (97%) diff --git a/ansible_collections/arista/avd/docs/contribution/eos_designs_internal_notes.md b/ansible_collections/arista/avd/docs/contribution/eos_designs_internal_notes.md index c571e3bd590..5f5f9052ece 100644 --- a/ansible_collections/arista/avd/docs/contribution/eos_designs_internal_notes.md +++ b/ansible_collections/arista/avd/docs/contribution/eos_designs_internal_notes.md @@ -179,7 +179,7 @@ classDiagram ### SharedUtils -See the source code [here](../../plugins/plugin_utils/eos_designs_shared_utils/__init__.py) +See the source code [here](https://github.com/aristanetworks/avd/tree/devel/python-avd/pyavd/_eos_designs/shared_utils) ```mermaid classDiagram diff --git a/ansible_collections/arista/avd/plugins/action/eos_designs_facts.py b/ansible_collections/arista/avd/plugins/action/eos_designs_facts.py index 57ccee3dd6b..0d5d8ba9e28 100644 --- a/ansible_collections/arista/avd/plugins/action/eos_designs_facts.py +++ b/ansible_collections/arista/avd/plugins/action/eos_designs_facts.py @@ -11,7 +11,6 @@ from ansible.errors import AnsibleActionFail from ansible.plugins.action import ActionBase, display -from ansible_collections.arista.avd.plugins.plugin_utils.eos_designs_shared_utils import SharedUtils from ansible_collections.arista.avd.plugins.plugin_utils.errors import AristaAvdMissingVariableError from ansible_collections.arista.avd.plugins.plugin_utils.pyavd_wrappers import RaiseOnUse from ansible_collections.arista.avd.plugins.plugin_utils.schema.avdschematools import AvdSchemaTools @@ -21,9 +20,10 @@ try: from pyavd._eos_designs.eos_designs_facts import EosDesignsFacts + from pyavd._eos_designs.shared_utils import SharedUtils from pyavd.vendor.errors.errors import AristaAvdMissingVariableError as PyavdMissingVariableError except ImportError as e: - EosDesignsFacts = RaiseOnUse( + EosDesignsFacts = SharedUtils = RaiseOnUse( AnsibleActionFail( f"The '{PLUGIN_NAME}' plugin requires the 'pyavd' Python library. Got import error", orig_exc=e, diff --git a/ansible_collections/arista/avd/plugins/action/yaml_templates_to_facts.py b/ansible_collections/arista/avd/plugins/action/yaml_templates_to_facts.py index a5d494c81b4..3b4e176b57a 100644 --- a/ansible_collections/arista/avd/plugins/action/yaml_templates_to_facts.py +++ b/ansible_collections/arista/avd/plugins/action/yaml_templates_to_facts.py @@ -17,9 +17,9 @@ from ansible.utils.vars import isidentifier from ansible_collections.arista.avd.plugins.plugin_utils.avdfacts import AvdFacts -from ansible_collections.arista.avd.plugins.plugin_utils.eos_designs_shared_utils import SharedUtils from ansible_collections.arista.avd.plugins.plugin_utils.errors import AristaAvdMissingVariableError from ansible_collections.arista.avd.plugins.plugin_utils.merge import merge +from ansible_collections.arista.avd.plugins.plugin_utils.pyavd_wrappers import RaiseOnUse from ansible_collections.arista.avd.plugins.plugin_utils.schema.avdschematools import AvdSchemaTools from ansible_collections.arista.avd.plugins.plugin_utils.strip_empties import strip_null_from_data from ansible_collections.arista.avd.plugins.plugin_utils.utils import get, get_templar, load_python_class @@ -27,6 +27,18 @@ DEFAULT_PYTHON_CLASS_NAME = "AvdStructuredConfig" +PLUGIN_NAME = "arista.avd.yaml_templates_to_facts" + +try: + from pyavd._eos_designs.shared_utils import SharedUtils +except ImportError as e: + SharedUtils = RaiseOnUse( + AnsibleActionFail( + f"The '{PLUGIN_NAME}' plugin requires the 'pyavd' Python library. Got import error", + orig_exc=e, + ) + ) + class ActionModule(ActionBase): def run(self, tmp=None, task_vars=None): diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/avdfacts.py b/ansible_collections/arista/avd/plugins/plugin_utils/avdfacts.py index 89b8fd068f2..e58c4457d3d 100644 --- a/ansible_collections/arista/avd/plugins/plugin_utils/avdfacts.py +++ b/ansible_collections/arista/avd/plugins/plugin_utils/avdfacts.py @@ -7,7 +7,7 @@ from typing import TYPE_CHECKING if TYPE_CHECKING: - from ansible_collections.arista.avd.plugins.plugin_utils.eos_designs_shared_utils import SharedUtils + from pyavd._eos_designs.shared_utils import SharedUtils class AvdFacts: diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/MOVED_TO_PYAVD.txt b/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/MOVED_TO_PYAVD.txt new file mode 100644 index 00000000000..c8e9d4aa6dd --- /dev/null +++ b/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/MOVED_TO_PYAVD.txt @@ -0,0 +1 @@ +The eos_designs_shared_utils Python module has been moved to PyAVD in the folder /python-avd/pyavd/_eos_designs/shared_utils/ diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/__init__.py b/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/__init__.py deleted file mode 100644 index 9f4d9a5d3a0..00000000000 --- a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/__init__.py +++ /dev/null @@ -1,6 +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 .shared_utils import SharedUtils - -__all__ = ["SharedUtils"] diff --git a/python-avd/Makefile b/python-avd/Makefile index e66f12f3eb6..815fdeab86a 100644 --- a/python-avd/Makefile +++ b/python-avd/Makefile @@ -52,7 +52,6 @@ copy-libs: ## Copy files from Ansible AVD collection mkdir -p $(J2_DIR) mkdir -p $(SCHEMAS_DIR) mkdir -p $(EOS_CLI_CONFIG_GEN_TEMPLATE_DIR) - mkdir -p $(EOS_DESIGNS_MODULES_DIR) cp $(ANSIBLE_AVD_DIR)/LICENSE $(PACKAGE_DIR)/LICENSE cp -r $(ANSIBLE_AVD_DIR)/ansible_collections/arista/avd/plugins/plugin_utils/* $(VENDOR_DIR) @@ -62,7 +61,7 @@ copy-libs: ## Copy files from Ansible AVD collection cp -r $(ANSIBLE_AVD_DIR)/ansible_collections/arista/avd/roles/eos_cli_config_gen/templates/* $(EOS_CLI_CONFIG_GEN_TEMPLATE_DIR) rm -f $(EOS_CLI_CONFIG_GEN_TEMPLATE_DIR)/avd_schema_documentation.j2 - mv $(VENDOR_DIR)/eos_designs_* $(EOS_DESIGNS_MODULES_DIR)/ + rm -rf $(VENDOR_DIR)/eos_designs_* $(SCRIPTS_DIR)/build-schemas.py cp $(ANSIBLE_AVD_DIR)/ansible_collections/arista/avd/roles/eos_cli_config_gen/schemas/eos_cli_config_gen.schema.pickle $(SCHEMAS_DIR)/ @@ -86,7 +85,6 @@ fix-libs: ## Fix/remove various Ansible specifics things from python files find $(PACKAGE_DIR) -name '*.py' -exec sed -i -e 's/AnsibleError/AristaAvdError/g' {} + find $(PACKAGE_DIR) -name '*.py' -exec sed -i -e 's/AnsibleActionFail/AristaAvdError/g' {} + find $(PACKAGE_DIR) -name '*.py' -exec sed -i -e 's/ansible_collections\.arista\.avd\.plugins\.plugin_utils\.schema\.avdschematools/pyavd.avd_schema_tools/g' {} + - find $(PACKAGE_DIR) -name '*.py' -exec sed -i -e 's/ansible_collections\.arista\.avd\.plugins\.plugin_utils\.eos_designs_shared_utils/$(VENDOR_IMPORT)\.eos_designs\.eos_designs_shared_utils/g' {} + find $(PACKAGE_DIR) -name '*.py' -exec sed -i -e 's/ansible_collections\.arista\.avd\.plugins\.plugin_utils/$(VENDOR_IMPORT)/g' {} + find $(PACKAGE_DIR) -name '*.py' -exec sed -i -e 's/ansible_collections\.arista\.avd\.plugins\.module_utils/$(VENDOR_IMPORT)/g' {} + @@ -102,9 +100,6 @@ fix-libs: ## Fix/remove various Ansible specifics things from python files find $(PACKAGE_DIR) -name '*.py' -exec sed -i -e 's/ansible_collections\.arista\.avd\.plugins\.filter/$(VENDOR_IMPORT)\.j2\.filter/g' {} + -# Only remaining python_modules are ip_addressing and interface_descriptions referred in eos_designs_shared_utils. - find $(PACKAGE_DIR) -name '*.py' -exec sed -i -e 's/ansible_collections\.arista\.avd\.roles\.eos_designs\.python_modules/$(EOS_DESIGNS_IMPORT)/g' {} + - find $(PACKAGE_DIR) -name '*.py' -exec sed -i -e 's/from ansible\.utils\.display/from $(VENDOR_IMPORT)\.utils\.display/g' {} + cp -r $(CURRENT_DIR)/vendor_overrides/* $(VENDOR_DIR)/ diff --git a/python-avd/pyavd/_eos_designs/interface_descriptions/models.py b/python-avd/pyavd/_eos_designs/interface_descriptions/models.py index ffa0d05b0a8..e714c99daa1 100644 --- a/python-avd/pyavd/_eos_designs/interface_descriptions/models.py +++ b/python-avd/pyavd/_eos_designs/interface_descriptions/models.py @@ -7,7 +7,7 @@ from typing import TYPE_CHECKING if TYPE_CHECKING: - from ...vendor.eos_designs.eos_designs_shared_utils import SharedUtils + from ..shared_utils import SharedUtils class InterfaceDescriptionData: diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/shared_utils.py b/python-avd/pyavd/_eos_designs/shared_utils/__init__.py similarity index 100% rename from ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/shared_utils.py rename to python-avd/pyavd/_eos_designs/shared_utils/__init__.py diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/bgp_peer_groups.py b/python-avd/pyavd/_eos_designs/shared_utils/bgp_peer_groups.py similarity index 96% rename from ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/bgp_peer_groups.py rename to python-avd/pyavd/_eos_designs/shared_utils/bgp_peer_groups.py index 4351be9a03e..fd6675ced97 100644 --- a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/bgp_peer_groups.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/bgp_peer_groups.py @@ -6,10 +6,10 @@ from functools import cached_property from typing import TYPE_CHECKING -from ansible_collections.arista.avd.plugins.plugin_utils.utils import get +from ...vendor.utils import get if TYPE_CHECKING: - from .shared_utils import SharedUtils + from . import SharedUtils class BgpPeerGroupsMixin: diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/connected_endpoints_keys.py b/python-avd/pyavd/_eos_designs/shared_utils/connected_endpoints_keys.py similarity index 92% rename from ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/connected_endpoints_keys.py rename to python-avd/pyavd/_eos_designs/shared_utils/connected_endpoints_keys.py index 1102b2e2484..62b75e7a4be 100644 --- a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/connected_endpoints_keys.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/connected_endpoints_keys.py @@ -6,11 +6,11 @@ from functools import cached_property from typing import TYPE_CHECKING -from ansible_collections.arista.avd.plugins.filter.convert_dicts import convert_dicts -from ansible_collections.arista.avd.plugins.plugin_utils.utils import get +from ...j2filters.convert_dicts import convert_dicts +from ...vendor.utils import get if TYPE_CHECKING: - from .shared_utils import SharedUtils + from . import SharedUtils # NOTE: there is a static list of default endpoint keys in the fabric connected endpoints documentation templates. DEFAULT_CONNECTED_ENDPOINTS_KEYS = [ diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/cv_topology.py b/python-avd/pyavd/_eos_designs/shared_utils/cv_topology.py similarity index 94% rename from ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/cv_topology.py rename to python-avd/pyavd/_eos_designs/shared_utils/cv_topology.py index f3fbee26d34..22a7e847e48 100644 --- a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/cv_topology.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/cv_topology.py @@ -6,11 +6,11 @@ from functools import cached_property from typing import TYPE_CHECKING -from ansible_collections.arista.avd.plugins.filter.range_expand import range_expand -from ansible_collections.arista.avd.plugins.plugin_utils.utils import get, get_item +from ...vendor.j2.filter.range_expand import range_expand +from ...vendor.utils import get, get_item if TYPE_CHECKING: - from .shared_utils import SharedUtils + from . import SharedUtils class CvTopology: diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/filtered_tenants.py b/python-avd/pyavd/_eos_designs/shared_utils/filtered_tenants.py similarity index 97% rename from ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/filtered_tenants.py rename to python-avd/pyavd/_eos_designs/shared_utils/filtered_tenants.py index ac654f6a76c..ffde729c20c 100644 --- a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/filtered_tenants.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/filtered_tenants.py @@ -6,15 +6,15 @@ from functools import cached_property from typing import TYPE_CHECKING -from ansible_collections.arista.avd.plugins.filter.convert_dicts import convert_dicts -from ansible_collections.arista.avd.plugins.filter.natural_sort import natural_sort -from ansible_collections.arista.avd.plugins.filter.range_expand import range_expand -from ansible_collections.arista.avd.plugins.plugin_utils.errors import AristaAvdError, AristaAvdMissingVariableError -from ansible_collections.arista.avd.plugins.plugin_utils.merge import merge -from ansible_collections.arista.avd.plugins.plugin_utils.utils import default, get, get_item, unique +from ...j2filters.convert_dicts import convert_dicts +from ...j2filters.natural_sort import natural_sort +from ...vendor.errors import AristaAvdError, AristaAvdMissingVariableError +from ...vendor.j2.filter.range_expand import range_expand +from ...vendor.merge import merge +from ...vendor.utils import default, get, get_item, unique if TYPE_CHECKING: - from .shared_utils import SharedUtils + from . import SharedUtils class FilteredTenantsMixin: @@ -456,5 +456,3 @@ def get_additional_svi_config(svi_config: dict, svi: dict, vrf: dict) -> None: ospf_keys.append({"id": ospf_key["id"], "hash_algorithm": ospf_key.get("hash_algorithm", "sha512"), "key": ospf_key["key"]}) if ospf_keys: svi_config.update({"ospf_authentication": ospf_authentication, "ospf_message_digest_keys": ospf_keys}) - - return None diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/flow_tracking.py b/python-avd/pyavd/_eos_designs/shared_utils/flow_tracking.py similarity index 96% rename from ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/flow_tracking.py rename to python-avd/pyavd/_eos_designs/shared_utils/flow_tracking.py index 10b09eb0e7d..74d3636b4ca 100644 --- a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/flow_tracking.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/flow_tracking.py @@ -7,10 +7,10 @@ from functools import cached_property from typing import TYPE_CHECKING, Literal -from ansible_collections.arista.avd.plugins.plugin_utils.utils import get +from ...vendor.utils import get if TYPE_CHECKING: - from .shared_utils import SharedUtils + from . import SharedUtils class FlowTrackingMixin: diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/inband_management.py b/python-avd/pyavd/_eos_designs/shared_utils/inband_management.py similarity index 96% rename from ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/inband_management.py rename to python-avd/pyavd/_eos_designs/shared_utils/inband_management.py index b1c4b8a1fc5..8130c3d0656 100644 --- a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/inband_management.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/inband_management.py @@ -7,11 +7,11 @@ from ipaddress import ip_network from typing import TYPE_CHECKING -from ansible_collections.arista.avd.plugins.plugin_utils.errors import AristaAvdError, AristaAvdMissingVariableError -from ansible_collections.arista.avd.plugins.plugin_utils.utils import default, get +from ...vendor.errors import AristaAvdError, AristaAvdMissingVariableError +from ...vendor.utils import default, get if TYPE_CHECKING: - from .shared_utils import SharedUtils + from . import SharedUtils class InbandManagementMixin: diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/interface_descriptions.py b/python-avd/pyavd/_eos_designs/shared_utils/interface_descriptions.py similarity index 85% rename from ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/interface_descriptions.py rename to python-avd/pyavd/_eos_designs/shared_utils/interface_descriptions.py index 19060434957..97bcfa70487 100644 --- a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/interface_descriptions.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/interface_descriptions.py @@ -6,12 +6,12 @@ from functools import cached_property from typing import TYPE_CHECKING -from ansible_collections.arista.avd.plugins.plugin_utils.merge import merge -from ansible_collections.arista.avd.plugins.plugin_utils.utils import get, load_python_class -from ansible_collections.arista.avd.roles.eos_designs.python_modules.interface_descriptions import AvdInterfaceDescriptions +from ...vendor.merge import merge +from ...vendor.utils import get, load_python_class +from ..interface_descriptions import AvdInterfaceDescriptions if TYPE_CHECKING: - from .shared_utils import SharedUtils + from . import SharedUtils DEFAULT_AVD_INTERFACE_DESCRIPTIONS_PYTHON_CLASS_NAME = "AvdInterfaceDescriptions" @@ -54,5 +54,5 @@ def interface_descriptions_templates(self: SharedUtils) -> dict: node_type_templates = get(self.node_type_key_data, "interface_descriptions", default={}) if hostvar_templates or node_type_templates: return merge(hostvar_templates, node_type_templates, list_merge="replace", destructive_merge=False) - else: - return {} + + return {} diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/ip_addressing.py b/python-avd/pyavd/_eos_designs/shared_utils/ip_addressing.py similarity index 89% rename from ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/ip_addressing.py rename to python-avd/pyavd/_eos_designs/shared_utils/ip_addressing.py index df859d01d4b..a1370cb4eb3 100644 --- a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/ip_addressing.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/ip_addressing.py @@ -6,12 +6,12 @@ from functools import cached_property from typing import TYPE_CHECKING -from ansible_collections.arista.avd.plugins.plugin_utils.merge import merge -from ansible_collections.arista.avd.plugins.plugin_utils.utils import get, load_python_class -from ansible_collections.arista.avd.roles.eos_designs.python_modules.ip_addressing import AvdIpAddressing +from ...vendor.merge import merge +from ...vendor.utils import get, load_python_class +from ..ip_addressing import AvdIpAddressing if TYPE_CHECKING: - from .shared_utils import SharedUtils + from . import SharedUtils DEFAULT_AVD_IP_ADDRESSING_PYTHON_CLASS_NAME = "AvdIpAddressing" @@ -58,8 +58,8 @@ def vtep_ip(self: SharedUtils) -> str: """ if self.mlag is True: return self.ip_addressing.vtep_ip_mlag() - else: - return self.ip_addressing.vtep_ip() + + return self.ip_addressing.vtep_ip() @cached_property def vtep_vvtep_ip(self: SharedUtils) -> str | None: @@ -96,5 +96,5 @@ def ip_addressing_templates(self: SharedUtils) -> dict: node_type_templates = get(self.node_type_key_data, "ip_addressing", default={}) if hostvar_templates or node_type_templates: return merge(hostvar_templates, node_type_templates, list_merge="replace", destructive_merge=False) - else: - return {} + + return {} diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/l3_interfaces.py b/python-avd/pyavd/_eos_designs/shared_utils/l3_interfaces.py similarity index 92% rename from ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/l3_interfaces.py rename to python-avd/pyavd/_eos_designs/shared_utils/l3_interfaces.py index 56441b8721c..c62896a9967 100644 --- a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/l3_interfaces.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/l3_interfaces.py @@ -6,11 +6,11 @@ from functools import cached_property from typing import TYPE_CHECKING -from ansible_collections.arista.avd.plugins.plugin_utils.merge import merge -from ansible_collections.arista.avd.plugins.plugin_utils.utils import get, get_item +from ...vendor.merge import merge +from ...vendor.utils import get, get_item if TYPE_CHECKING: - from .shared_utils import SharedUtils + from . import SharedUtils class L3InterfacesMixin: diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/link_tracking_groups.py b/python-avd/pyavd/_eos_designs/shared_utils/link_tracking_groups.py similarity index 92% rename from ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/link_tracking_groups.py rename to python-avd/pyavd/_eos_designs/shared_utils/link_tracking_groups.py index a123fa4b068..8ed2729a624 100644 --- a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/link_tracking_groups.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/link_tracking_groups.py @@ -6,10 +6,10 @@ from functools import cached_property from typing import TYPE_CHECKING -from ansible_collections.arista.avd.plugins.plugin_utils.utils import get +from ...vendor.utils import get if TYPE_CHECKING: - from .shared_utils import SharedUtils + from . import SharedUtils class LinkTrackingGroupsMixin: diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/mgmt.py b/python-avd/pyavd/_eos_designs/shared_utils/mgmt.py similarity index 90% rename from ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/mgmt.py rename to python-avd/pyavd/_eos_designs/shared_utils/mgmt.py index 12aa521bbce..fcd4f120c5e 100644 --- a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/mgmt.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/mgmt.py @@ -6,11 +6,11 @@ from functools import cached_property from typing import TYPE_CHECKING -from ansible_collections.arista.avd.plugins.plugin_utils.errors import AristaAvdMissingVariableError -from ansible_collections.arista.avd.plugins.plugin_utils.utils import default, get +from ...vendor.errors import AristaAvdMissingVariableError +from ...vendor.utils import default, get if TYPE_CHECKING: - from .shared_utils import SharedUtils + from . import SharedUtils class MgmtMixin: @@ -70,7 +70,7 @@ def default_mgmt_method(self: SharedUtils) -> str | None: return default_mgmt_method - elif default_mgmt_method == "inband": + if default_mgmt_method == "inband": # Check for missing interface if self.inband_mgmt_interface is None: raise AristaAvdMissingVariableError("'default_mgmt_method: inband' requires 'inband_mgmt_interface' to be set.") @@ -83,7 +83,7 @@ def default_mgmt_method(self: SharedUtils) -> str | None: def default_mgmt_protocol_vrf(self: SharedUtils) -> str | None: if self.default_mgmt_method == "oob": return self.mgmt_interface_vrf - elif self.default_mgmt_method == "inband": + if self.default_mgmt_method == "inband": # inband_mgmt_vrf returns None for vrf default. return self.inband_mgmt_vrf or "default" @@ -93,7 +93,7 @@ def default_mgmt_protocol_vrf(self: SharedUtils) -> str | None: def default_mgmt_protocol_interface(self: SharedUtils) -> str | None: if self.default_mgmt_method == "oob": return self.mgmt_interface - elif self.default_mgmt_method == "inband": + if self.default_mgmt_method == "inband": return self.inband_mgmt_interface return None diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/misc.py b/python-avd/pyavd/_eos_designs/shared_utils/misc.py similarity index 96% rename from ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/misc.py rename to python-avd/pyavd/_eos_designs/shared_utils/misc.py index 504184ac99e..a678b5a5dd4 100644 --- a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/misc.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/misc.py @@ -7,16 +7,15 @@ from functools import cached_property from typing import TYPE_CHECKING -from ansible_collections.arista.avd.plugins.filter.convert_dicts import convert_dicts -from ansible_collections.arista.avd.plugins.filter.natural_sort import natural_sort -from ansible_collections.arista.avd.plugins.filter.range_expand import range_expand -from ansible_collections.arista.avd.plugins.plugin_utils.errors.errors import AristaAvdError, AristaAvdMissingVariableError -from ansible_collections.arista.avd.plugins.plugin_utils.utils import default, get, get_item +from ...j2filters.convert_dicts import convert_dicts +from ...j2filters.natural_sort import natural_sort +from ...vendor.errors.errors import AristaAvdError, AristaAvdMissingVariableError +from ...vendor.j2.filter.range_expand import range_expand +from ...vendor.utils import default, get, get_item if TYPE_CHECKING: - from pyavd._eos_designs.eos_designs_facts import EosDesignsFacts - - from .shared_utils import SharedUtils + from ...eos_designs_facts import EosDesignsFacts + from . import SharedUtils class MiscMixin: @@ -364,10 +363,7 @@ def new_network_services_bgp_vrf_config(self: SharedUtils) -> bool: TODO: Change default to True in all cases in AVD 5.0.0 and remove in AVD 6.0.0 """ - if self.uplink_type == "p2p-vrfs": - default_value = True - else: - default_value = False + default_value = bool(self.uplink_type == "p2p-vrfs") return get(self.hostvars, "new_network_services_bgp_vrf_config", default=default_value) @cached_property diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/mlag.py b/python-avd/pyavd/_eos_designs/shared_utils/mlag.py similarity index 92% rename from ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/mlag.py rename to python-avd/pyavd/_eos_designs/shared_utils/mlag.py index 24f20c57e88..f856785dddb 100644 --- a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/mlag.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/mlag.py @@ -8,14 +8,13 @@ from re import findall from typing import TYPE_CHECKING -from ansible_collections.arista.avd.plugins.filter.range_expand import range_expand -from ansible_collections.arista.avd.plugins.plugin_utils.errors import AristaAvdError, AristaAvdMissingVariableError -from ansible_collections.arista.avd.plugins.plugin_utils.utils import default, get +from ...vendor.errors import AristaAvdError, AristaAvdMissingVariableError +from ...vendor.j2.filter.range_expand import range_expand +from ...vendor.utils import default, get if TYPE_CHECKING: - from pyavd._eos_designs.eos_designs_facts import EosDesignsFacts - - from .shared_utils import SharedUtils + from ...eos_designs_facts import EosDesignsFacts + from . import SharedUtils class MlagMixin: @@ -84,7 +83,7 @@ def mlag_role(self: SharedUtils) -> str | None: if self.mlag: if self.switch_data_node_group_nodes[0]["name"] == self.hostname: return "primary" - elif self.switch_data_node_group_nodes[1]["name"] == self.hostname: + if self.switch_data_node_group_nodes[1]["name"] == self.hostname: return "secondary" raise AristaAvdError("Unable to detect MLAG role") return None @@ -145,7 +144,7 @@ def mlag_ip(self: SharedUtils) -> str | None: """ if self.mlag_role == "primary": return self.ip_addressing.mlag_ip_primary() - elif self.mlag_role == "secondary": + if self.mlag_role == "secondary": return self.ip_addressing.mlag_ip_secondary() @cached_property @@ -157,7 +156,7 @@ def mlag_l3_ip(self: SharedUtils) -> str | None: return None if self.mlag_role == "primary": return self.ip_addressing.mlag_l3_ip_primary() - elif self.mlag_role == "secondary": + if self.mlag_role == "secondary": return self.ip_addressing.mlag_l3_ip_secondary() @cached_property @@ -170,7 +169,7 @@ def mlag_switch_ids(self: SharedUtils) -> dict | None: if self.id is None: raise AristaAvdMissingVariableError(f"'id' is not set on '{self.hostname}' and is required to compute MLAG ids") return {"primary": self.id, "secondary": self.mlag_peer_id} - elif self.mlag_role == "secondary": + if self.mlag_role == "secondary": if self.id is None: raise AristaAvdMissingVariableError(f"'id' is not set on '{self.hostname}' and is required to compute MLAG ids") return {"primary": self.mlag_peer_id, "secondary": self.id} diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/node_type.py b/python-avd/pyavd/_eos_designs/shared_utils/node_type.py similarity index 94% rename from ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/node_type.py rename to python-avd/pyavd/_eos_designs/shared_utils/node_type.py index 214fb23ed0a..9697ab01904 100644 --- a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/node_type.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/node_type.py @@ -7,11 +7,11 @@ from re import search from typing import TYPE_CHECKING -from ansible_collections.arista.avd.plugins.plugin_utils.errors import AristaAvdMissingVariableError -from ansible_collections.arista.avd.plugins.plugin_utils.utils import get +from ...vendor.errors import AristaAvdMissingVariableError +from ...vendor.utils import get if TYPE_CHECKING: - from .shared_utils import SharedUtils + from . import SharedUtils class NodeTypeMixin: @@ -28,13 +28,13 @@ def type(self: SharedUtils) -> str: """ if (node_type := get(self.hostvars, "type")) is not None: return node_type - elif self.default_node_type: + if self.default_node_type: return self.default_node_type raise AristaAvdMissingVariableError(f"'type' for host {self.hostname}") @cached_property - def default_node_type(self: SharedUtils) -> str: + def default_node_type(self: SharedUtils) -> str | None: """ default_node_type set based on hostname, returning first node type matching a regex in default_node_types diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/node_type_keys.py b/python-avd/pyavd/_eos_designs/shared_utils/node_type_keys.py similarity index 95% rename from ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/node_type_keys.py rename to python-avd/pyavd/_eos_designs/shared_utils/node_type_keys.py index 96ca5a88131..b8c7de1d00c 100644 --- a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/node_type_keys.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/node_type_keys.py @@ -6,12 +6,12 @@ from functools import cached_property from typing import TYPE_CHECKING -from ansible_collections.arista.avd.plugins.filter.convert_dicts import convert_dicts -from ansible_collections.arista.avd.plugins.plugin_utils.errors import AristaAvdMissingVariableError -from ansible_collections.arista.avd.plugins.plugin_utils.utils import get +from ...j2filters.convert_dicts import convert_dicts +from ...vendor.errors import AristaAvdMissingVariableError +from ...vendor.utils import get if TYPE_CHECKING: - from .shared_utils import SharedUtils + from . import SharedUtils # NOTE: There is a static list of default node_type_keys in the fabric documentation templates DEFAULT_NODE_TYPE_KEYS = { diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/overlay.py b/python-avd/pyavd/_eos_designs/shared_utils/overlay.py similarity index 96% rename from ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/overlay.py rename to python-avd/pyavd/_eos_designs/shared_utils/overlay.py index 8208fb5af5c..b069dafb78c 100644 --- a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/overlay.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/overlay.py @@ -8,11 +8,11 @@ from re import fullmatch from typing import TYPE_CHECKING -from ansible_collections.arista.avd.plugins.plugin_utils.errors import AristaAvdError, AristaAvdMissingVariableError -from ansible_collections.arista.avd.plugins.plugin_utils.utils import get +from ...vendor.errors import AristaAvdError, AristaAvdMissingVariableError +from ...vendor.utils import get if TYPE_CHECKING: - from .shared_utils import SharedUtils + from . import SharedUtils class OverlayMixin: @@ -152,9 +152,9 @@ def evpn_soo(self: SharedUtils) -> str: return f"{self.router_id}:{self.wan_site['id']}" if self.is_first_ha_peer: return f"{self.router_id}:{self.wan_site['id']}" - else: - peer_fact = self.get_peer_facts(self.wan_ha_peer, required=True) - return f"{peer_fact['router_id']}:{self.wan_site['id']}" + + peer_fact = self.get_peer_facts(self.wan_ha_peer, required=True) + return f"{peer_fact['router_id']}:{self.wan_site['id']}" if self.overlay_vtep: return f"{self.vtep_ip}:1" diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/platform.py b/python-avd/pyavd/_eos_designs/shared_utils/platform.py similarity index 98% rename from ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/platform.py rename to python-avd/pyavd/_eos_designs/shared_utils/platform.py index 3dfcbb99cef..9b8baac7c35 100644 --- a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/platform.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/platform.py @@ -7,10 +7,10 @@ from re import search from typing import TYPE_CHECKING -from ansible_collections.arista.avd.plugins.plugin_utils.utils import default, get +from ...vendor.utils import default, get if TYPE_CHECKING: - from .shared_utils import SharedUtils + from . import SharedUtils # Campus platforms are separated out by their ability to support "trident_forwarding_table_partition". # This is required for EVPN multicast, currently only supported on all 720XP platforms. diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/ptp.py b/python-avd/pyavd/_eos_designs/shared_utils/ptp.py similarity index 94% rename from ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/ptp.py rename to python-avd/pyavd/_eos_designs/shared_utils/ptp.py index d511fdf3787..4b338999d44 100644 --- a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/ptp.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/ptp.py @@ -6,10 +6,10 @@ from functools import cached_property from typing import TYPE_CHECKING -from ansible_collections.arista.avd.plugins.plugin_utils.utils import get, get_item +from ...vendor.utils import get, get_item if TYPE_CHECKING: - from .shared_utils import SharedUtils + from . import SharedUtils DEFAULT_PTP_PROFILES = [ { diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/routing.py b/python-avd/pyavd/_eos_designs/shared_utils/routing.py similarity index 77% rename from ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/routing.py rename to python-avd/pyavd/_eos_designs/shared_utils/routing.py index 74f6b07671b..0da7c85e80b 100644 --- a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/routing.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/routing.py @@ -6,12 +6,12 @@ from functools import cached_property from typing import TYPE_CHECKING -from ansible_collections.arista.avd.plugins.filter.range_expand import range_expand -from ansible_collections.arista.avd.plugins.plugin_utils.errors.errors import AristaAvdError, AristaAvdMissingVariableError -from ansible_collections.arista.avd.plugins.plugin_utils.utils import get +from ...vendor.errors.errors import AristaAvdError, AristaAvdMissingVariableError +from ...vendor.j2.filter.range_expand import range_expand +from ...vendor.utils import get if TYPE_CHECKING: - from .shared_utils import SharedUtils + from . import SharedUtils class RoutingMixin: @@ -103,21 +103,19 @@ def bgp_as(self: SharedUtils) -> str | None: if self.bgp: if get(self.hostvars, "bgp_as") is not None: return str(get(self.hostvars, "bgp_as")) - else: - bgp_as_range_expanded = range_expand(str(get(self.switch_data_combined, "bgp_as", required=True))) - try: - if len(bgp_as_range_expanded) == 1: - return bgp_as_range_expanded[0] - elif self.mlag: - return bgp_as_range_expanded[self.mlag_switch_ids["primary"] - 1] - else: - if self.id is None: - raise AristaAvdMissingVariableError(f"'id' is not set on '{self.hostname}' and is required when expanding 'bgp_as'") - return bgp_as_range_expanded[self.id - 1] - except IndexError as exc: - raise AristaAvdError( - f"Unable to allocate BGP AS: bgp_as range is too small ({len(bgp_as_range_expanded)}) for the id of the device" - ) from exc + + bgp_as_range_expanded = range_expand(str(get(self.switch_data_combined, "bgp_as", required=True))) + try: + if len(bgp_as_range_expanded) == 1: + return bgp_as_range_expanded[0] + if self.mlag: + return bgp_as_range_expanded[self.mlag_switch_ids["primary"] - 1] + + if self.id is None: + raise AristaAvdMissingVariableError(f"'id' is not set on '{self.hostname}' and is required when expanding 'bgp_as'") + return bgp_as_range_expanded[self.id - 1] + except IndexError as exc: + raise AristaAvdError(f"Unable to allocate BGP AS: bgp_as range is too small ({len(bgp_as_range_expanded)}) for the id of the device") from exc @cached_property def always_configure_ip_routing(self: SharedUtils) -> bool: diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/switch_data.py b/python-avd/pyavd/_eos_designs/shared_utils/switch_data.py similarity index 92% rename from ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/switch_data.py rename to python-avd/pyavd/_eos_designs/shared_utils/switch_data.py index 0d1be55bacb..3d63a99ba29 100644 --- a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/switch_data.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/switch_data.py @@ -6,12 +6,12 @@ from functools import cached_property from typing import TYPE_CHECKING -from ansible_collections.arista.avd.plugins.filter.convert_dicts import convert_dicts -from ansible_collections.arista.avd.plugins.plugin_utils.merge import merge -from ansible_collections.arista.avd.plugins.plugin_utils.utils import get +from ...j2filters.convert_dicts import convert_dicts +from ...vendor.merge import merge +from ...vendor.utils import get if TYPE_CHECKING: - from .shared_utils import SharedUtils + from . import SharedUtils class SwitchDataMixin: diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/underlay.py b/python-avd/pyavd/_eos_designs/shared_utils/underlay.py similarity index 97% rename from ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/underlay.py rename to python-avd/pyavd/_eos_designs/shared_utils/underlay.py index 3314eb25501..72e032b9fe1 100644 --- a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/underlay.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/underlay.py @@ -6,10 +6,10 @@ from functools import cached_property from typing import TYPE_CHECKING -from ansible_collections.arista.avd.plugins.plugin_utils.utils import get, get_item +from ...vendor.utils import get, get_item if TYPE_CHECKING: - from .shared_utils import SharedUtils + from . import SharedUtils class UnderlayMixin: diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/utils.py b/python-avd/pyavd/_eos_designs/shared_utils/utils.py similarity index 89% rename from ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/utils.py rename to python-avd/pyavd/_eos_designs/shared_utils/utils.py index 206b49298d6..a028cddefa7 100644 --- a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/utils.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/utils.py @@ -6,14 +6,13 @@ from functools import lru_cache from typing import TYPE_CHECKING -from ansible_collections.arista.avd.plugins.plugin_utils.errors import AristaAvdError -from ansible_collections.arista.avd.plugins.plugin_utils.merge import merge -from ansible_collections.arista.avd.plugins.plugin_utils.utils import get, get_item, template_var +from ...vendor.errors import AristaAvdError +from ...vendor.merge import merge +from ...vendor.utils import get, get_item, template_var if TYPE_CHECKING: - from pyavd._eos_designs.eos_designs_facts import EosDesignsFacts - - from .shared_utils import SharedUtils + from ...eos_designs_facts import EosDesignsFacts + from . import SharedUtils class UtilsMixin: diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/wan.py b/python-avd/pyavd/_eos_designs/shared_utils/wan.py similarity index 97% rename from ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/wan.py rename to python-avd/pyavd/_eos_designs/shared_utils/wan.py index 4dbcace4dea..d4d8563f5da 100644 --- a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/wan.py +++ b/python-avd/pyavd/_eos_designs/shared_utils/wan.py @@ -6,13 +6,13 @@ from functools import cached_property from typing import TYPE_CHECKING, Literal -from ansible_collections.arista.avd.plugins.filter.natural_sort import natural_sort -from ansible_collections.arista.avd.plugins.plugin_utils.errors import AristaAvdError, AristaAvdMissingVariableError -from ansible_collections.arista.avd.plugins.plugin_utils.strip_empties import strip_empties_from_dict -from ansible_collections.arista.avd.plugins.plugin_utils.utils import default, get, get_item +from ...j2filters.natural_sort import natural_sort +from ...vendor.errors import AristaAvdError, AristaAvdMissingVariableError +from ...vendor.strip_empties import strip_empties_from_dict +from ...vendor.utils import default, get, get_item if TYPE_CHECKING: - from .shared_utils import SharedUtils + from . import SharedUtils class WanMixin: @@ -484,7 +484,7 @@ def wan_ha_peer(self: SharedUtils) -> str | None: return None if self.is_first_ha_peer: return self.switch_data_node_group_nodes[1]["name"] - elif self.switch_data_node_group_nodes[1]["name"] == self.hostname: + if self.switch_data_node_group_nodes[1]["name"] == self.hostname: return self.switch_data_node_group_nodes[0]["name"] raise AristaAvdError("Unable to find WAN HA peer within same node group") diff --git a/python-avd/pyavd/_eos_designs/structured_config/__init__.py b/python-avd/pyavd/_eos_designs/structured_config/__init__.py index 4062512798a..ddc225fd196 100644 --- a/python-avd/pyavd/_eos_designs/structured_config/__init__.py +++ b/python-avd/pyavd/_eos_designs/structured_config/__init__.py @@ -7,9 +7,9 @@ from ...avd_schema_tools import AvdSchemaTools from ...vendor.avdfacts import AvdFacts -from ...vendor.eos_designs.eos_designs_shared_utils import SharedUtils from ...vendor.merge import merge from ...vendor.utils import get +from ..shared_utils import SharedUtils from .base import AvdStructuredConfigBase from .connected_endpoints import AvdStructuredConfigConnectedEndpoints from .core_interfaces_and_l3_edge import AvdStructuredConfigCoreInterfacesAndL3Edge diff --git a/python-avd/pyavd/get_avd_facts.py b/python-avd/pyavd/get_avd_facts.py index 1689b93f8e7..2323396e6c0 100644 --- a/python-avd/pyavd/get_avd_facts.py +++ b/python-avd/pyavd/get_avd_facts.py @@ -1,9 +1,12 @@ # 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 __future__ import annotations + from collections import ChainMap from ._eos_designs.eos_designs_facts import EosDesignsFacts +from ._eos_designs.shared_utils import SharedUtils def get_avd_facts(all_inputs: dict[str, dict]) -> dict[str, dict]: @@ -70,11 +73,6 @@ def _create_avd_switch_facts_instances(all_inputs: dict[str, dict]) -> dict: } ``` """ - # pylint: disable=import-outside-toplevel - from .vendor.eos_designs.eos_designs_shared_utils import SharedUtils - - # pylint: enable=import-outside-toplevel - avd_switch_facts = {} for hostname, hostvars in all_inputs.items(): # Set 'inventory_hostname' on the input variables, to keep compatibility with Ansible focused code. diff --git a/python-avd/pyavd/validate_inputs.py b/python-avd/pyavd/validate_inputs.py index 79fd5a2712b..fd7e4cd8016 100644 --- a/python-avd/pyavd/validate_inputs.py +++ b/python-avd/pyavd/validate_inputs.py @@ -1,6 +1,9 @@ # 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 __future__ import annotations + +from ._eos_designs.shared_utils import SharedUtils from .avd_schema_tools import AvdSchemaTools from .constants import EOS_DESIGNS_SCHEMA_ID from .validation_result import ValidationResult @@ -20,8 +23,6 @@ def validate_inputs(inputs: dict) -> ValidationResult: Returns: Validation result object with any validation errors or deprecation warnings. """ - from .vendor.eos_designs.eos_designs_shared_utils import SharedUtils # pylint: disable=import-outside-toplevel - # Initialize a global instance of eos_designs_schema_tools global eos_designs_schema_tools if eos_designs_schema_tools is None: