Skip to content

Commit

Permalink
Refactor(eos_designs): Remove legacy interface_descriptions function (a…
Browse files Browse the repository at this point in the history
…ristanetworks#4300)

Co-authored-by: Claus Holbech <[email protected]>
  • Loading branch information
2 people authored and jrecchia1029 committed Aug 14, 2024
1 parent c013b53 commit 010343f
Show file tree
Hide file tree
Showing 21 changed files with 231 additions and 393 deletions.
27 changes: 27 additions & 0 deletions ansible_collections/arista/avd/docs/porting-guides/5.x.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,33 @@ 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

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
- from ansible_collections.arista.avd.roles.eos_designs.python_modules.interface_descriptions import AvdInterfaceDescriptions, InterfaceDescriptionData
+ from pyavd.api.interface_descriptions import AvdInterfaceDescriptions, InterfaceDescriptionData
```

Some methods of the `AvdInterfaceDescriptions` class were collapsed.
The following table indicates the removed methods and the replacement ones to
adjust the code. Note that the new method signatures are different.

| Removed method signature | Replacement method signature |
| ------------------------ | ---------------------------- |
| `underlay_ethernet_interfaces(self, link_type: str, link_peer: str, link_peer_interface: str) -> str` | `underlay_ethernet_interface(self, data: InterfaceDescriptionData) -> str` |
| `underlay_port_channel_interfaces(self, link_peer: str, link_peer_channel_group_id: int, link_channel_description: str) -> str:` | `underlay_port_channel_interface(self, data: InterfaceDescriptionData) -> str` |
| `mlag_ethernet_interfaces(self, mlag_interface: str) -> str:` | `mlag_ethernet_interface(self, data: InterfaceDescriptionData) -> str` |
| `mlag_port_channel_interfaces(self) -> str:` | `mlag_ethernet_interface(self, data: InterfaceDescriptionData) -> str` |
| `connected_endpoints_ethernet_interfaces(self, peer: str = None, peer_interface: str = None, adapter_description: str = None) -> str:` | `connected_endpoint_ethernet_interface(self, data: InterfaceDescriptionData) -> str` |
| `connected_endpoints_port_channel_interfaces(self, peer: str = None, adapter_description: str = None, adapter_port_channel_description: str = None) -> str:` | `connected_endpoint_port_channel_interface(self, data: InterfaceDescriptionData) -> str` |
| `overlay_loopback_interface(self, overlay_loopback_description: str = None) -> str` | `router_id_loopback_interface(self, data: InterfaceDescriptionData) -> str` |
| `vtep_loopback_interface(self) -> str` | `vtep_loopback_interface(self, data: InterfaceDescriptionData) -> str` |

For any method that was not previously overwritten, there should be no output change as compared to AVD 4.10.0.

### Removal of deprecated data models

The following data model keys have been removed from `eos_designs` in v5.0.0.
Expand Down
5 changes: 5 additions & 0 deletions ansible_collections/arista/avd/docs/pyavd.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,8 @@ pip install pyavd[ansible]
options:
show_root_toc_entry: false
paths: ../../../../python-avd

::: pyavd.api.interface_descriptions
options:
show_root_toc_entry: false
paths: ../../../../python-avd
8 changes: 8 additions & 0 deletions ansible_collections/arista/avd/docs/release-notes/5.x.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ With AVD version 5.0.0 `ipv6_address_virtuals` are only rendered in the configur

The `eos_designs.jsonschema.json` is no longer generated. This schema was not being used and had never been complete.

#### AvdInterfaceDescriptions breaking changes

The class `AvdInterfaceDescriptions` was moved to `pyavd` and heavily modified.
Users who have subclassed it for custom descriptions will have to adjust their code.
The updated version gives more flexibility to customizing interface descriptions.

See the [Porting guide for AVD 5.x.x](../porting-guides/5.x.x.md#avdinterfacedescriptions-breaking-changes)

### Other breaking or behavioral changes

Breaking changes may require modifications to the inventory or playbook. See the [Porting guide for AVD 5.x.x](../porting-guides/5.x.x.md)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
# 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 utils from Ansible.
from ansible_collections.arista.avd.plugins.plugin_utils.utils import get

# 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.interface_descriptions import AvdInterfaceDescriptions, InterfaceDescriptionData
from pyavd.api.interface_descriptions import AvdInterfaceDescriptions, InterfaceDescriptionData


class CustomAvdInterfaceDescriptions(AvdInterfaceDescriptions):
@cached_property
def _custom_description_prefix(self) -> str:
return get(self._hostvars, "description_prefix", "")
return str(self._hostvars.get("description_prefix") or "")

def underlay_ethernet_interface(self, data: InterfaceDescriptionData) -> str:
"""
Expand Down Expand Up @@ -132,11 +128,7 @@ def router_id_loopback_interface(self, data: InterfaceDescriptionData) -> str:
switch_type = str(data.type).upper()
return f"{self._custom_description_prefix}_EVPN_Overlay_Peering_{switch_type}"

def vtep_loopback_interface(self) -> str:
"""
Implementation of custom code similar to jinja.
TODO: AVD5.0.0 Update to use InterfaceDescriptionData.
"""
def vtep_loopback_interface(self, data: InterfaceDescriptionData) -> str: # noqa: ARG002
"""Implementation of custom code similar to jinja."""
switch_type = str(self.shared_utils.type).upper()
return f"{self._custom_description_prefix}_VTEP_VXLAN_Tunnel_Source_{switch_type}"
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ node_type_keys:
default_evpn_role: server
interface_descriptions:
# Override default interface description with a custom python module
python_module: custom_interface_descriptions
python_module: custom_interface_descriptions_with_data
python_class_name: CustomAvdInterfaceDescriptions

- key: l3leaf
Expand All @@ -26,7 +26,7 @@ node_type_keys:
python_class_name: CustomAvdIpAddressing

interface_descriptions:
# Override default interface description with a custom python module using the new api with InterfaceDescriptionData object.
# Override default interface description with a custom python module
python_module: custom_interface_descriptions_with_data
python_class_name: CustomAvdInterfaceDescriptions

Expand Down

This file was deleted.

3 changes: 3 additions & 0 deletions python-avd/pyavd/_eos_designs/avdfacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@


class AvdFacts:
_hostvars: dict
shared_utils: SharedUtils

def __init__(self, hostvars: dict, shared_utils: SharedUtils) -> None:
self._hostvars = hostvars
self.shared_utils = shared_utils
Expand Down
96 changes: 0 additions & 96 deletions python-avd/pyavd/_eos_designs/interface_descriptions/models.py

This file was deleted.

43 changes: 0 additions & 43 deletions python-avd/pyavd/_eos_designs/interface_descriptions/utils.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from functools import cached_property
from typing import TYPE_CHECKING

from pyavd._eos_designs.interface_descriptions import AvdInterfaceDescriptions
from pyavd._utils import get, load_python_class, merge
from pyavd.api.interface_descriptions import AvdInterfaceDescriptions

if TYPE_CHECKING:
from . import SharedUtils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from functools import cached_property
from typing import TYPE_CHECKING

from pyavd._eos_designs.interface_descriptions.models import InterfaceDescriptionData
from pyavd._errors import AristaAvdMissingVariableError
from pyavd._utils import get, get_item, merge
from pyavd.api.interface_descriptions import InterfaceDescriptionData

if TYPE_CHECKING:
from . import SharedUtils
Expand Down
Loading

0 comments on commit 010343f

Please sign in to comment.