From 6d26f6e6fe9f7c0454b2acfd0a3a5c7e6517e7d6 Mon Sep 17 00:00:00 2001 From: kpbush30 Date: Mon, 9 Dec 2024 15:14:22 +0000 Subject: [PATCH 01/15] Feat(eos_designs): Add platform match criteria for network_ports --- .../configs/network-ports-tests-2.cfg | 18 ++++++++++ .../configs/network-ports-tests.1.cfg | 18 ++++++++++ .../network-ports-tests-2.yml | 26 ++++++++++++++ .../network-ports-tests.1.yml | 26 ++++++++++++++ .../group_vars/NETWORK_PORTS_TESTS.yml | 36 +++++++++++++++++++ .../eos_designs/docs/tables/network-ports.md | 6 ++++ .../pyavd/_eos_designs/schema/__init__.py | 19 ++++++++++ .../schema/eos_designs.schema.yml | 7 ++++ .../schema_fragments/network_ports.schema.yml | 7 ++++ .../connected_endpoints/utils.py | 3 ++ 10 files changed, 166 insertions(+) diff --git a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/configs/network-ports-tests-2.cfg b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/configs/network-ports-tests-2.cfg index c8a739cc50e..6b85975b97a 100644 --- a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/configs/network-ports-tests-2.cfg +++ b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/configs/network-ports-tests-2.cfg @@ -597,6 +597,24 @@ interface Ethernet17 no shutdown switchport ! +interface Ethernet23 + description PCs + no shutdown + switchport access vlan 100 + switchport mode access + switchport + spanning-tree portfast + spanning-tree bpdufilter enable +! +interface Ethernet24 + description PCs + no shutdown + switchport access vlan 100 + switchport mode access + switchport + spanning-tree portfast + spanning-tree bpdufilter enable +! interface Ethernet51 no shutdown channel-group 43 mode active diff --git a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/configs/network-ports-tests.1.cfg b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/configs/network-ports-tests.1.cfg index 66d60064716..a0044036aa1 100644 --- a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/configs/network-ports-tests.1.cfg +++ b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/configs/network-ports-tests.1.cfg @@ -544,6 +544,24 @@ interface Ethernet14 no shutdown switchport ! +interface Ethernet47 + description PCs + no shutdown + switchport access vlan 100 + switchport mode access + switchport + spanning-tree portfast + spanning-tree bpdufilter enable +! +interface Ethernet48 + description PCs + no shutdown + switchport access vlan 100 + switchport mode access + switchport + spanning-tree portfast + spanning-tree bpdufilter enable +! interface Ethernet51 shutdown switchport diff --git a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/structured_configs/network-ports-tests-2.yml b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/structured_configs/network-ports-tests-2.yml index 7459a80d68f..cc820a07cdc 100644 --- a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/structured_configs/network-ports-tests-2.yml +++ b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/structured_configs/network-ports-tests-2.yml @@ -814,6 +814,30 @@ ethernet_interfaces: channel_group: id: 43 mode: active +- name: Ethernet23 + peer: PCs + peer_type: network_port + port_profile: pc + description: PCs + shutdown: false + switchport: + enabled: true + mode: access + access_vlan: 100 + spanning_tree_portfast: edge + spanning_tree_bpdufilter: enabled +- name: Ethernet24 + peer: PCs + peer_type: network_port + port_profile: pc + description: PCs + shutdown: false + switchport: + enabled: true + mode: access + access_vlan: 100 + spanning_tree_portfast: edge + spanning_tree_bpdufilter: enabled mlag_configuration: domain_id: mlag local_interface: Vlan4094 @@ -833,3 +857,5 @@ monitor_sessions: destinations: - Ethernet17 encapsulation_gre_metadata_tx: true +metadata: + platform: 720XPM-24Y6 diff --git a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/structured_configs/network-ports-tests.1.yml b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/structured_configs/network-ports-tests.1.yml index 4629462b53f..8ec8a7f62c0 100644 --- a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/structured_configs/network-ports-tests.1.yml +++ b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/structured_configs/network-ports-tests.1.yml @@ -751,6 +751,30 @@ ethernet_interfaces: shutdown: true switchport: enabled: true +- name: Ethernet47 + peer: PCs + peer_type: network_port + port_profile: pc + description: PCs + shutdown: false + switchport: + enabled: true + mode: access + access_vlan: 100 + spanning_tree_portfast: edge + spanning_tree_bpdufilter: enabled +- name: Ethernet48 + peer: PCs + peer_type: network_port + port_profile: pc + description: PCs + shutdown: false + switchport: + enabled: true + mode: access + access_vlan: 100 + spanning_tree_portfast: edge + spanning_tree_bpdufilter: enabled mlag_configuration: domain_id: mlag local_interface: Vlan4094 @@ -760,3 +784,5 @@ mlag_configuration: reload_delay_non_mlag: '330' ip_igmp_snooping: globally_enabled: true +metadata: + platform: 720XPM-48Y6 diff --git a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml index 095e7996bea..aaed9118ab5 100644 --- a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml +++ b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml @@ -141,6 +141,27 @@ network_ports: channel_id: 43 mode: "active" + # The next two switches are targeted using a like regex filtering on correct + # platform type + - switches: + - network-ports-tests.* + switch_ports: + - Ethernet47-48 # Fix ports + platforms: + - 720XPM-48Y6 + profile: pc + endpoint: PCs + + - switches: + - network-ports-tests.* + switch_ports: + - Ethernet23-24 # Fix ports + platforms: + - 720XPM-24Y6 + profile: pc + endpoint: PCs + + servers: - name: CONNECTED_ENDPOINT_OVERWRITING_NETWORK_PORT adapters: @@ -171,7 +192,22 @@ l2leaf: nodes: - name: network-ports-tests.1 id: 1 + platform: 720XPM-48Y6 - name: network-ports-tests-2 filter: only_vlans_in_use: true id: 2 + platform: 720XPM-24Y6 + +custom_platform_settings: + - platforms: + - 720XPM-48Y6 + - 720XPM-24Y6 + feature_support: + poe: true + queue_monitor_length_notify: false + reload_delay: + mlag: 300 + non_mlag: 330 + trident_forwarding_table_partition: flexible exact-match 16000 l2-shared 18000 l3-shared + 22000 \ No newline at end of file diff --git a/ansible_collections/arista/avd/roles/eos_designs/docs/tables/network-ports.md b/ansible_collections/arista/avd/roles/eos_designs/docs/tables/network-ports.md index 355bf327783..a3fab294d08 100644 --- a/ansible_collections/arista/avd/roles/eos_designs/docs/tables/network-ports.md +++ b/ansible_collections/arista/avd/roles/eos_designs/docs/tables/network-ports.md @@ -10,6 +10,8 @@ | [network_ports](## "network_ports") | List, items: Dictionary | | | | | | [  - switches](## "network_ports.[].switches") | List, items: String | | | | Regex matching the full hostname of one or more switches.
The regular expression must match the full hostname.
| | [      - <str>](## "network_ports.[].switches.[]") | String | | | | | + | [    platforms](## "network_ports.[].platforms") | List, items: String | | | | Match on platform type
| + | [      - <str>](## "network_ports.[].platforms.[]") | String | | | | | | [    switch_ports](## "network_ports.[].switch_ports") | List, items: String | | | | List of ranges using AVD range_expand syntax.
For example:

switch_ports:
- Ethernet1
- Ethernet2-48

All switch_ports ranges are expanded into individual port configurations.

For more details and examples of the `range_expand` syntax, see the [`arista.avd.range_expand` documentation](../../../docs/plugins/Filter_plugins/range_expand.md).
| | [      - <str>](## "network_ports.[].switch_ports.[]") | String | | | | | | [    description](## "network_ports.[].description") | String | | | | Description or description template to be used on all ports.
This can be a template using the AVD string formatter syntax: https://avd.arista.com/devel/roles/eos_designs/docs/how-to/custom-descriptions-names.html#avd-string-formatter-syntax.
The available template fields are:
- `endpoint_type` - always set to `network_port`.
- `endpoint` - content of the `endpoint` key if set.
- `port_channel_id`: The port-channel number for the switch.

The default description is set by `default_network_ports_description`.
By default the description is templated from the `endpoint` key if set. | @@ -192,6 +194,10 @@ - switches: - + # Match on platform type + platforms: + - + # List of ranges using AVD range_expand syntax. # For example: # diff --git a/python-avd/pyavd/_eos_designs/schema/__init__.py b/python-avd/pyavd/_eos_designs/schema/__init__.py index afa5548636b..1c71da501d5 100644 --- a/python-avd/pyavd/_eos_designs/schema/__init__.py +++ b/python-avd/pyavd/_eos_designs/schema/__init__.py @@ -6777,6 +6777,11 @@ class Switches(AvdList[str]): Switches._item_type = str + class Platforms(AvdList[str]): + """Subclass of AvdList with `str` items.""" + + Platforms._item_type = str + class SwitchPorts(AvdList[str]): """Subclass of AvdList with `str` items.""" @@ -7940,6 +7945,7 @@ class StructuredConfig(EosCliConfigGen.EthernetInterfacesItem): _fields: ClassVar[dict] = { "switches": {"type": Switches}, + "platforms": {"type": Platforms}, "switch_ports": {"type": SwitchPorts}, "description": {"type": str}, "endpoint": {"type": str}, @@ -7984,6 +7990,13 @@ class StructuredConfig(EosCliConfigGen.EthernetInterfacesItem): hostname. + Subclass of AvdList with `str` items. + """ + platforms: Platforms + """ + Match on platform type + + Subclass of AvdList with `str` items. """ switch_ports: SwitchPorts @@ -8176,6 +8189,7 @@ def __init__( self, *, switches: Switches | UndefinedType = Undefined, + platforms: Platforms | UndefinedType = Undefined, switch_ports: SwitchPorts | UndefinedType = Undefined, description: str | None | UndefinedType = Undefined, endpoint: str | None | UndefinedType = Undefined, @@ -8226,6 +8240,11 @@ def __init__( hostname. + Subclass of AvdList with `str` items. + platforms: + Match on platform type + + Subclass of AvdList with `str` items. switch_ports: List of ranges using AVD range_expand syntax. 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 b241f60331a..5cacf04478e 100644 --- a/python-avd/pyavd/_eos_designs/schema/eos_designs.schema.yml +++ b/python-avd/pyavd/_eos_designs/schema/eos_designs.schema.yml @@ -2291,6 +2291,13 @@ keys: The regular expression must match the full hostname. + ' + items: + type: str + platforms: + type: list + description: 'Match on platform type + ' items: type: str diff --git a/python-avd/pyavd/_eos_designs/schema/schema_fragments/network_ports.schema.yml b/python-avd/pyavd/_eos_designs/schema/schema_fragments/network_ports.schema.yml index 3c1ce0ce1ed..7e173060c2f 100644 --- a/python-avd/pyavd/_eos_designs/schema/schema_fragments/network_ports.schema.yml +++ b/python-avd/pyavd/_eos_designs/schema/schema_fragments/network_ports.schema.yml @@ -20,6 +20,13 @@ keys: The regular expression must match the full hostname. items: type: str + #TODO: Update for review + platforms: + type: list + description: | + Match on platform type, you may need to create a custom platform in platform_settings. + items: + type: str switch_ports: type: list description: | diff --git a/python-avd/pyavd/_eos_designs/structured_config/connected_endpoints/utils.py b/python-avd/pyavd/_eos_designs/structured_config/connected_endpoints/utils.py index 45251b79108..2b13bf82ca0 100644 --- a/python-avd/pyavd/_eos_designs/structured_config/connected_endpoints/utils.py +++ b/python-avd/pyavd/_eos_designs/structured_config/connected_endpoints/utils.py @@ -74,6 +74,9 @@ def _filtered_network_ports(self: AvdStructuredConfigConnectedEndpoints) -> list network_port_settings = self.shared_utils.get_merged_adapter_settings(network_port) if not self._match_regexes(network_port_settings.switches, self.shared_utils.hostname): continue + # TODO: Review + if network_port_settings.platforms and not self.shared_utils.platform in network_port_settings.platforms: + continue filtered_network_ports.append(network_port_settings) From cbed4475bcd8ec48fa0d22c8f0c47232d102ea85 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 9 Dec 2024 15:27:07 +0000 Subject: [PATCH 02/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../avd/roles/eos_designs/docs/tables/network-ports.md | 4 ++-- python-avd/pyavd/_eos_designs/schema/__init__.py | 10 ++++++---- .../pyavd/_eos_designs/schema/eos_designs.schema.yml | 3 ++- .../structured_config/connected_endpoints/utils.py | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/ansible_collections/arista/avd/roles/eos_designs/docs/tables/network-ports.md b/ansible_collections/arista/avd/roles/eos_designs/docs/tables/network-ports.md index a3fab294d08..c2d05c784d0 100644 --- a/ansible_collections/arista/avd/roles/eos_designs/docs/tables/network-ports.md +++ b/ansible_collections/arista/avd/roles/eos_designs/docs/tables/network-ports.md @@ -10,7 +10,7 @@ | [network_ports](## "network_ports") | List, items: Dictionary | | | | | | [  - switches](## "network_ports.[].switches") | List, items: String | | | | Regex matching the full hostname of one or more switches.
The regular expression must match the full hostname.
| | [      - <str>](## "network_ports.[].switches.[]") | String | | | | | - | [    platforms](## "network_ports.[].platforms") | List, items: String | | | | Match on platform type
| + | [    platforms](## "network_ports.[].platforms") | List, items: String | | | | Match on platform type, you may need to create a custom platform in platform_settings.
| | [      - <str>](## "network_ports.[].platforms.[]") | String | | | | | | [    switch_ports](## "network_ports.[].switch_ports") | List, items: String | | | | List of ranges using AVD range_expand syntax.
For example:

switch_ports:
- Ethernet1
- Ethernet2-48

All switch_ports ranges are expanded into individual port configurations.

For more details and examples of the `range_expand` syntax, see the [`arista.avd.range_expand` documentation](../../../docs/plugins/Filter_plugins/range_expand.md).
| | [      - <str>](## "network_ports.[].switch_ports.[]") | String | | | | | @@ -194,7 +194,7 @@ - switches: - - # Match on platform type + # Match on platform type, you may need to create a custom platform in platform_settings. platforms: - diff --git a/python-avd/pyavd/_eos_designs/schema/__init__.py b/python-avd/pyavd/_eos_designs/schema/__init__.py index 1c71da501d5..c3cc3430a19 100644 --- a/python-avd/pyavd/_eos_designs/schema/__init__.py +++ b/python-avd/pyavd/_eos_designs/schema/__init__.py @@ -7994,10 +7994,11 @@ class StructuredConfig(EosCliConfigGen.EthernetInterfacesItem): """ platforms: Platforms """ - Match on platform type + Match on platform type, you may need to create a custom platform in platform_settings. - Subclass of AvdList with `str` items. + Subclass of + AvdList with `str` items. """ switch_ports: SwitchPorts """ @@ -8242,10 +8243,11 @@ def __init__( Subclass of AvdList with `str` items. platforms: - Match on platform type + Match on platform type, you may need to create a custom platform in platform_settings. - Subclass of AvdList with `str` items. + Subclass of + AvdList with `str` items. switch_ports: List of ranges using AVD range_expand syntax. For example: 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 5cacf04478e..ed9d2944c52 100644 --- a/python-avd/pyavd/_eos_designs/schema/eos_designs.schema.yml +++ b/python-avd/pyavd/_eos_designs/schema/eos_designs.schema.yml @@ -2296,7 +2296,8 @@ keys: type: str platforms: type: list - description: 'Match on platform type + description: 'Match on platform type, you may need to create a custom platform + in platform_settings. ' items: diff --git a/python-avd/pyavd/_eos_designs/structured_config/connected_endpoints/utils.py b/python-avd/pyavd/_eos_designs/structured_config/connected_endpoints/utils.py index 2b13bf82ca0..b99948fd1c1 100644 --- a/python-avd/pyavd/_eos_designs/structured_config/connected_endpoints/utils.py +++ b/python-avd/pyavd/_eos_designs/structured_config/connected_endpoints/utils.py @@ -75,7 +75,7 @@ def _filtered_network_ports(self: AvdStructuredConfigConnectedEndpoints) -> list if not self._match_regexes(network_port_settings.switches, self.shared_utils.hostname): continue # TODO: Review - if network_port_settings.platforms and not self.shared_utils.platform in network_port_settings.platforms: + if network_port_settings.platforms and self.shared_utils.platform not in network_port_settings.platforms: continue filtered_network_ports.append(network_port_settings) From 380710cf786df43c36dc8d138ca5bf1a54cb2e63 Mon Sep 17 00:00:00 2001 From: kpbush30 Date: Mon, 9 Dec 2024 15:30:44 +0000 Subject: [PATCH 03/15] Make things happy again --- .../inventory/group_vars/NETWORK_PORTS_TESTS.yml | 6 ++---- .../avd/roles/eos_designs/docs/tables/network-ports.md | 4 ++-- python-avd/pyavd/_eos_designs/schema/__init__.py | 10 ++++++---- .../pyavd/_eos_designs/schema/eos_designs.schema.yml | 3 ++- .../structured_config/connected_endpoints/utils.py | 2 +- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml index aaed9118ab5..9bde009039c 100644 --- a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml +++ b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml @@ -141,8 +141,7 @@ network_ports: channel_id: 43 mode: "active" - # The next two switches are targeted using a like regex filtering on correct - # platform type + # The next two switches are targeted using a like regex filtering on correct platform type - switches: - network-ports-tests.* switch_ports: @@ -161,7 +160,6 @@ network_ports: profile: pc endpoint: PCs - servers: - name: CONNECTED_ENDPOINT_OVERWRITING_NETWORK_PORT adapters: @@ -210,4 +208,4 @@ custom_platform_settings: mlag: 300 non_mlag: 330 trident_forwarding_table_partition: flexible exact-match 16000 l2-shared 18000 l3-shared - 22000 \ No newline at end of file + 22000 diff --git a/ansible_collections/arista/avd/roles/eos_designs/docs/tables/network-ports.md b/ansible_collections/arista/avd/roles/eos_designs/docs/tables/network-ports.md index a3fab294d08..c2d05c784d0 100644 --- a/ansible_collections/arista/avd/roles/eos_designs/docs/tables/network-ports.md +++ b/ansible_collections/arista/avd/roles/eos_designs/docs/tables/network-ports.md @@ -10,7 +10,7 @@ | [network_ports](## "network_ports") | List, items: Dictionary | | | | | | [  - switches](## "network_ports.[].switches") | List, items: String | | | | Regex matching the full hostname of one or more switches.
The regular expression must match the full hostname.
| | [      - <str>](## "network_ports.[].switches.[]") | String | | | | | - | [    platforms](## "network_ports.[].platforms") | List, items: String | | | | Match on platform type
| + | [    platforms](## "network_ports.[].platforms") | List, items: String | | | | Match on platform type, you may need to create a custom platform in platform_settings.
| | [      - <str>](## "network_ports.[].platforms.[]") | String | | | | | | [    switch_ports](## "network_ports.[].switch_ports") | List, items: String | | | | List of ranges using AVD range_expand syntax.
For example:

switch_ports:
- Ethernet1
- Ethernet2-48

All switch_ports ranges are expanded into individual port configurations.

For more details and examples of the `range_expand` syntax, see the [`arista.avd.range_expand` documentation](../../../docs/plugins/Filter_plugins/range_expand.md).
| | [      - <str>](## "network_ports.[].switch_ports.[]") | String | | | | | @@ -194,7 +194,7 @@ - switches: - - # Match on platform type + # Match on platform type, you may need to create a custom platform in platform_settings. platforms: - diff --git a/python-avd/pyavd/_eos_designs/schema/__init__.py b/python-avd/pyavd/_eos_designs/schema/__init__.py index 1c71da501d5..c3cc3430a19 100644 --- a/python-avd/pyavd/_eos_designs/schema/__init__.py +++ b/python-avd/pyavd/_eos_designs/schema/__init__.py @@ -7994,10 +7994,11 @@ class StructuredConfig(EosCliConfigGen.EthernetInterfacesItem): """ platforms: Platforms """ - Match on platform type + Match on platform type, you may need to create a custom platform in platform_settings. - Subclass of AvdList with `str` items. + Subclass of + AvdList with `str` items. """ switch_ports: SwitchPorts """ @@ -8242,10 +8243,11 @@ def __init__( Subclass of AvdList with `str` items. platforms: - Match on platform type + Match on platform type, you may need to create a custom platform in platform_settings. - Subclass of AvdList with `str` items. + Subclass of + AvdList with `str` items. switch_ports: List of ranges using AVD range_expand syntax. For example: 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 5cacf04478e..ed9d2944c52 100644 --- a/python-avd/pyavd/_eos_designs/schema/eos_designs.schema.yml +++ b/python-avd/pyavd/_eos_designs/schema/eos_designs.schema.yml @@ -2296,7 +2296,8 @@ keys: type: str platforms: type: list - description: 'Match on platform type + description: 'Match on platform type, you may need to create a custom platform + in platform_settings. ' items: diff --git a/python-avd/pyavd/_eos_designs/structured_config/connected_endpoints/utils.py b/python-avd/pyavd/_eos_designs/structured_config/connected_endpoints/utils.py index 2b13bf82ca0..b99948fd1c1 100644 --- a/python-avd/pyavd/_eos_designs/structured_config/connected_endpoints/utils.py +++ b/python-avd/pyavd/_eos_designs/structured_config/connected_endpoints/utils.py @@ -75,7 +75,7 @@ def _filtered_network_ports(self: AvdStructuredConfigConnectedEndpoints) -> list if not self._match_regexes(network_port_settings.switches, self.shared_utils.hostname): continue # TODO: Review - if network_port_settings.platforms and not self.shared_utils.platform in network_port_settings.platforms: + if network_port_settings.platforms and self.shared_utils.platform not in network_port_settings.platforms: continue filtered_network_ports.append(network_port_settings) From 43847bdf085f492d06d89a722bae0756b8711f40 Mon Sep 17 00:00:00 2001 From: kpbush30 Date: Mon, 9 Dec 2024 16:35:42 +0000 Subject: [PATCH 04/15] Alter behavior to allow platform only criteria --- .../inventory/group_vars/NETWORK_PORTS_TESTS.yml | 7 ++++--- .../structured_config/connected_endpoints/utils.py | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml index 9bde009039c..c6692c49b3e 100644 --- a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml +++ b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml @@ -142,6 +142,7 @@ network_ports: mode: "active" # The next two switches are targeted using a like regex filtering on correct platform type + # Test regex and platform match criteria - switches: - network-ports-tests.* switch_ports: @@ -151,9 +152,8 @@ network_ports: profile: pc endpoint: PCs - - switches: - - network-ports-tests.* - switch_ports: + # Test only platform match + - switch_ports: - Ethernet23-24 # Fix ports platforms: - 720XPM-24Y6 @@ -197,6 +197,7 @@ l2leaf: id: 2 platform: 720XPM-24Y6 +# Used for platform filtering tests custom_platform_settings: - platforms: - 720XPM-48Y6 diff --git a/python-avd/pyavd/_eos_designs/structured_config/connected_endpoints/utils.py b/python-avd/pyavd/_eos_designs/structured_config/connected_endpoints/utils.py index b99948fd1c1..f06cd625a73 100644 --- a/python-avd/pyavd/_eos_designs/structured_config/connected_endpoints/utils.py +++ b/python-avd/pyavd/_eos_designs/structured_config/connected_endpoints/utils.py @@ -72,9 +72,8 @@ def _filtered_network_ports(self: AvdStructuredConfigConnectedEndpoints) -> list for index, network_port in enumerate(self.inputs.network_ports): network_port._context = f"network_ports[{index}]" network_port_settings = self.shared_utils.get_merged_adapter_settings(network_port) - if not self._match_regexes(network_port_settings.switches, self.shared_utils.hostname): + if network_port_settings.switches and not self._match_regexes(network_port_settings.switches, self.shared_utils.hostname): continue - # TODO: Review if network_port_settings.platforms and self.shared_utils.platform not in network_port_settings.platforms: continue From bed8213eaef7a6e8a8651a1c59507fc9aa1fed6b Mon Sep 17 00:00:00 2001 From: kpbush30 Date: Mon, 9 Dec 2024 16:39:01 +0000 Subject: [PATCH 05/15] Better comments for your eyes --- .../eos_designs/docs/tables/network-ports.md | 9 +++++++-- .../pyavd/_eos_designs/schema/__init__.py | 20 +++++++++++++------ .../schema/eos_designs.schema.yml | 8 ++++---- .../schema_fragments/network_ports.schema.yml | 8 ++++++-- 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/ansible_collections/arista/avd/roles/eos_designs/docs/tables/network-ports.md b/ansible_collections/arista/avd/roles/eos_designs/docs/tables/network-ports.md index c2d05c784d0..d13db95f950 100644 --- a/ansible_collections/arista/avd/roles/eos_designs/docs/tables/network-ports.md +++ b/ansible_collections/arista/avd/roles/eos_designs/docs/tables/network-ports.md @@ -10,7 +10,7 @@ | [network_ports](## "network_ports") | List, items: Dictionary | | | | | | [  - switches](## "network_ports.[].switches") | List, items: String | | | | Regex matching the full hostname of one or more switches.
The regular expression must match the full hostname.
| | [      - <str>](## "network_ports.[].switches.[]") | String | | | | | - | [    platforms](## "network_ports.[].platforms") | List, items: String | | | | Match on platform type, you may need to create a custom platform in platform_settings.
| + | [    platforms](## "network_ports.[].platforms") | List, items: String | | | | Matching the platform type of one or more switches, to match full platform names, create a custom platform in `platform_settings`.
For example, `720XP-48Y6` would require a custom platform type:

platforms:
- 720XP
- 720XP-48Y6
| | [      - <str>](## "network_ports.[].platforms.[]") | String | | | | | | [    switch_ports](## "network_ports.[].switch_ports") | List, items: String | | | | List of ranges using AVD range_expand syntax.
For example:

switch_ports:
- Ethernet1
- Ethernet2-48

All switch_ports ranges are expanded into individual port configurations.

For more details and examples of the `range_expand` syntax, see the [`arista.avd.range_expand` documentation](../../../docs/plugins/Filter_plugins/range_expand.md).
| | [      - <str>](## "network_ports.[].switch_ports.[]") | String | | | | | @@ -194,7 +194,12 @@ - switches: - - # Match on platform type, you may need to create a custom platform in platform_settings. + # Matching the platform type of one or more switches, to match full platform names, create a custom platform in `platform_settings`. + # For example, `720XP-48Y6` would require a custom platform type: + # + # platforms: + # - 720XP + # - 720XP-48Y6 platforms: - diff --git a/python-avd/pyavd/_eos_designs/schema/__init__.py b/python-avd/pyavd/_eos_designs/schema/__init__.py index c3cc3430a19..6a2bccf8f53 100644 --- a/python-avd/pyavd/_eos_designs/schema/__init__.py +++ b/python-avd/pyavd/_eos_designs/schema/__init__.py @@ -7994,11 +7994,15 @@ class StructuredConfig(EosCliConfigGen.EthernetInterfacesItem): """ platforms: Platforms """ - Match on platform type, you may need to create a custom platform in platform_settings. + Matching the platform type of one or more switches, to match full platform names, create a custom + platform in `platform_settings`. + For example, `720XP-48Y6` would require a custom platform type: + platforms: + - 720XP + - 720XP-48Y6 - Subclass of - AvdList with `str` items. + Subclass of AvdList with `str` items. """ switch_ports: SwitchPorts """ @@ -8243,11 +8247,15 @@ def __init__( Subclass of AvdList with `str` items. platforms: - Match on platform type, you may need to create a custom platform in platform_settings. + Matching the platform type of one or more switches, to match full platform names, create a custom + platform in `platform_settings`. + For example, `720XP-48Y6` would require a custom platform type: + platforms: + - 720XP + - 720XP-48Y6 - Subclass of - AvdList with `str` items. + Subclass of AvdList with `str` items. switch_ports: List of ranges using AVD range_expand syntax. For example: 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 ed9d2944c52..6b182c56247 100644 --- a/python-avd/pyavd/_eos_designs/schema/eos_designs.schema.yml +++ b/python-avd/pyavd/_eos_designs/schema/eos_designs.schema.yml @@ -2296,10 +2296,10 @@ keys: type: str platforms: type: list - description: 'Match on platform type, you may need to create a custom platform - in platform_settings. - - ' + description: "Matching the platform type of one or more switches, to match + full platform names, create a custom platform in `platform_settings`.\nFor + example, `720XP-48Y6` would require a custom platform type:\n\nplatforms:\n + \ - 720XP\n - 720XP-48Y6\n" items: type: str switch_ports: diff --git a/python-avd/pyavd/_eos_designs/schema/schema_fragments/network_ports.schema.yml b/python-avd/pyavd/_eos_designs/schema/schema_fragments/network_ports.schema.yml index 7e173060c2f..46c7cc75d45 100644 --- a/python-avd/pyavd/_eos_designs/schema/schema_fragments/network_ports.schema.yml +++ b/python-avd/pyavd/_eos_designs/schema/schema_fragments/network_ports.schema.yml @@ -20,11 +20,15 @@ keys: The regular expression must match the full hostname. items: type: str - #TODO: Update for review platforms: type: list description: | - Match on platform type, you may need to create a custom platform in platform_settings. + Matching the platform type of one or more switches, to match full platform names, create a custom platform in `platform_settings`. + For example, `720XP-48Y6` would require a custom platform type: + + platforms: + - 720XP + - 720XP-48Y6 items: type: str switch_ports: From 1ff40bc60959baf3f3080efa504b88b0ccc6010d Mon Sep 17 00:00:00 2001 From: kpbush30 Date: Mon, 9 Dec 2024 18:15:52 +0000 Subject: [PATCH 06/15] Remove extra comments --- .../inventory/group_vars/NETWORK_PORTS_TESTS.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml index c6692c49b3e..cb0325dd8a4 100644 --- a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml +++ b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml @@ -146,7 +146,7 @@ network_ports: - switches: - network-ports-tests.* switch_ports: - - Ethernet47-48 # Fix ports + - Ethernet47-48 platforms: - 720XPM-48Y6 profile: pc @@ -154,7 +154,7 @@ network_ports: # Test only platform match - switch_ports: - - Ethernet23-24 # Fix ports + - Ethernet23-24 platforms: - 720XPM-24Y6 profile: pc From 3bff360a93bdfe2c82dafc813561562a52ac56e6 Mon Sep 17 00:00:00 2001 From: kpbush30 Date: Tue, 10 Dec 2024 17:44:30 +0000 Subject: [PATCH 07/15] Add no match test and better desc --- .../group_vars/NETWORK_PORTS_TESTS.yml | 16 +++++++++--- .../eos_designs/docs/tables/network-ports.md | 5 ++-- .../pyavd/_eos_designs/schema/__init__.py | 26 +++++++++++++------ .../schema/eos_designs.schema.yml | 9 ++++--- .../schema_fragments/network_ports.schema.yml | 3 ++- 5 files changed, 41 insertions(+), 18 deletions(-) diff --git a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml index cb0325dd8a4..22f8c840a89 100644 --- a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml +++ b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml @@ -141,8 +141,8 @@ network_ports: channel_id: 43 mode: "active" - # The next two switches are targeted using a like regex filtering on correct platform type - # Test regex and platform match criteria + # Tests below test hostname and platform matching. + # Test regex match all switches and specific platform match criteria. - switches: - network-ports-tests.* switch_ports: @@ -152,7 +152,17 @@ network_ports: profile: pc endpoint: PCs - # Test only platform match + # Test regex match switch and no match on platform. + - switches: + - network-ports-tests.2 + switch_ports: + - Ethernet47-48 + platforms: + - 720XPM-48Y6 + profile: pc + endpoint: PCs + + # Test only platform match. - switch_ports: - Ethernet23-24 platforms: diff --git a/ansible_collections/arista/avd/roles/eos_designs/docs/tables/network-ports.md b/ansible_collections/arista/avd/roles/eos_designs/docs/tables/network-ports.md index d13db95f950..bee74e75a66 100644 --- a/ansible_collections/arista/avd/roles/eos_designs/docs/tables/network-ports.md +++ b/ansible_collections/arista/avd/roles/eos_designs/docs/tables/network-ports.md @@ -10,7 +10,7 @@ | [network_ports](## "network_ports") | List, items: Dictionary | | | | | | [  - switches](## "network_ports.[].switches") | List, items: String | | | | Regex matching the full hostname of one or more switches.
The regular expression must match the full hostname.
| | [      - <str>](## "network_ports.[].switches.[]") | String | | | | | - | [    platforms](## "network_ports.[].platforms") | List, items: String | | | | Matching the platform type of one or more switches, to match full platform names, create a custom platform in `platform_settings`.
For example, `720XP-48Y6` would require a custom platform type:

platforms:
- 720XP
- 720XP-48Y6
| + | [    platforms](## "network_ports.[].platforms") | List, items: String | | | | Matching the platform type of one or more switches. If you need to add custom platforms to match specific port quantities, create them under `custom_platform_settings`.
Entries under `custom_platform_settings` should match the platform match criteria.
For example, `720XP-48Y6` would require a custom platform type:

platforms:
- 720XP
- 720XP-48Y6
| | [      - <str>](## "network_ports.[].platforms.[]") | String | | | | | | [    switch_ports](## "network_ports.[].switch_ports") | List, items: String | | | | List of ranges using AVD range_expand syntax.
For example:

switch_ports:
- Ethernet1
- Ethernet2-48

All switch_ports ranges are expanded into individual port configurations.

For more details and examples of the `range_expand` syntax, see the [`arista.avd.range_expand` documentation](../../../docs/plugins/Filter_plugins/range_expand.md).
| | [      - <str>](## "network_ports.[].switch_ports.[]") | String | | | | | @@ -194,7 +194,8 @@ - switches: - - # Matching the platform type of one or more switches, to match full platform names, create a custom platform in `platform_settings`. + # Matching the platform type of one or more switches. If you need to add custom platforms to match specific port quantities, create them under `custom_platform_settings`. + # Entries under `custom_platform_settings` should match the platform match criteria. # For example, `720XP-48Y6` would require a custom platform type: # # platforms: diff --git a/python-avd/pyavd/_eos_designs/schema/__init__.py b/python-avd/pyavd/_eos_designs/schema/__init__.py index 6a2bccf8f53..f77c0641647 100644 --- a/python-avd/pyavd/_eos_designs/schema/__init__.py +++ b/python-avd/pyavd/_eos_designs/schema/__init__.py @@ -7994,15 +7994,20 @@ class StructuredConfig(EosCliConfigGen.EthernetInterfacesItem): """ platforms: Platforms """ - Matching the platform type of one or more switches, to match full platform names, create a custom - platform in `platform_settings`. - For example, `720XP-48Y6` would require a custom platform type: + Matching the platform type of one or more switches. If you need to add custom platforms to match + specific port quantities, create them under `custom_platform_settings`. + Entries under + `custom_platform_settings` should match the platform match criteria. + For example, `720XP-48Y6` would + require a custom platform type: + platforms: - 720XP - 720XP-48Y6 - Subclass of AvdList with `str` items. + Subclass of AvdList with + `str` items. """ switch_ports: SwitchPorts """ @@ -8247,15 +8252,20 @@ def __init__( Subclass of AvdList with `str` items. platforms: - Matching the platform type of one or more switches, to match full platform names, create a custom - platform in `platform_settings`. - For example, `720XP-48Y6` would require a custom platform type: + Matching the platform type of one or more switches. If you need to add custom platforms to match + specific port quantities, create them under `custom_platform_settings`. + Entries under + `custom_platform_settings` should match the platform match criteria. + For example, `720XP-48Y6` would + require a custom platform type: + platforms: - 720XP - 720XP-48Y6 - Subclass of AvdList with `str` items. + Subclass of AvdList with + `str` items. switch_ports: List of ranges using AVD range_expand syntax. For example: 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 6b182c56247..c4b5c4b4c7d 100644 --- a/python-avd/pyavd/_eos_designs/schema/eos_designs.schema.yml +++ b/python-avd/pyavd/_eos_designs/schema/eos_designs.schema.yml @@ -2296,10 +2296,11 @@ keys: type: str platforms: type: list - description: "Matching the platform type of one or more switches, to match - full platform names, create a custom platform in `platform_settings`.\nFor - example, `720XP-48Y6` would require a custom platform type:\n\nplatforms:\n - \ - 720XP\n - 720XP-48Y6\n" + description: "Matching the platform type of one or more switches. If you + need to add custom platforms to match specific port quantities, create + them under `custom_platform_settings`.\nEntries under `custom_platform_settings` + should match the platform match criteria.\nFor example, `720XP-48Y6` would + require a custom platform type:\n\nplatforms:\n - 720XP\n - 720XP-48Y6\n" items: type: str switch_ports: diff --git a/python-avd/pyavd/_eos_designs/schema/schema_fragments/network_ports.schema.yml b/python-avd/pyavd/_eos_designs/schema/schema_fragments/network_ports.schema.yml index 46c7cc75d45..bdadac0929e 100644 --- a/python-avd/pyavd/_eos_designs/schema/schema_fragments/network_ports.schema.yml +++ b/python-avd/pyavd/_eos_designs/schema/schema_fragments/network_ports.schema.yml @@ -23,7 +23,8 @@ keys: platforms: type: list description: | - Matching the platform type of one or more switches, to match full platform names, create a custom platform in `platform_settings`. + Matching the platform type of one or more switches. If you need to add custom platforms to match specific port quantities, create them under `custom_platform_settings`. + Entries under `custom_platform_settings` should match the platform match criteria. For example, `720XP-48Y6` would require a custom platform type: platforms: From ea076d1bd7d647bda2c9fed26f85b8c6ac1a07d1 Mon Sep 17 00:00:00 2001 From: kpbush30 Date: Wed, 11 Dec 2024 14:26:19 +0000 Subject: [PATCH 08/15] Update schema and docs with expected behavior --- .../roles/eos_designs/docs/input-variables.md | 50 +++++++++++++++++++ .../eos_designs/docs/tables/network-ports.md | 4 +- .../schema/eos_designs.schema.yml | 1 + .../schema_fragments/network_ports.schema.yml | 2 + 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/ansible_collections/arista/avd/roles/eos_designs/docs/input-variables.md b/ansible_collections/arista/avd/roles/eos_designs/docs/input-variables.md index e2b0f2da452..f461c9c3b92 100644 --- a/ansible_collections/arista/avd/roles/eos_designs/docs/input-variables.md +++ b/ansible_collections/arista/avd/roles/eos_designs/docs/input-variables.md @@ -1139,12 +1139,62 @@ roles/eos_designs/docs/tables/default-connected-endpoints-description.md The `network_ports` data model is intended to be used with `port_profiles` and `parent_profiles` to keep the configuration generic and compact, but all features and keys supported under `connected_endpoints.adapters` are also supported directly under `network_ports`. +Switches match criteria uses the list of `switches` hostname regex patterns or `platforms` list. When used in combination, the switch must match both criteria to generate the associated port configurations defined. + All ranges defined under `switch_ports` will be expanded to individual port configuration which leads to a some behavioral differences to `connected_endpoints`: - By default each port will be configured in a port-channel with one member when leveraging automatic channel-id generation. To configure multiple ports as member of the same port-channel set the channel-id key (see the example below). - Inconsistent configurations when used with `short_esi: auto` or `designated_forwarder_algorithm: auto`, since those rely on information from multiple switches and interfaces. +??? example "Example using match criteria" + + ```yaml + # Port Profiles + # Common settings inherited to network_ports + port_profiles: + - profile: common + mode: access + vlans: "999" + spanning_tree_portfast: edge + spanning_tree_bpdufilter: enabled + + # Network Ports + # Switches are matched with regex matching the full hostname and platform type. + network_ports: + - switches: + - network-ports-[est]{5}-.* + platforms: + - 720XPM-48Y6 + switch_ports: + - Ethernet1-48 + profile: common + + # Switches are matched on platform type, regardless of hostname. + - platforms: + - 720XPM-24Y6 + switch_ports: + - Ethernet1-24 + profile: common + + # Custom Platform Settings + # Copied default 720XP platform settings, adding more specific platform names for match. + # These platform types can be assigned to devices as part of nodes/node_group settings. + custom_platform_settings: + - platforms: + - 720XPM-48Y6 + - 720XPM-24Y6 + feature_support: + poe: true + queue_monitor_length_notify: false + reload_delay: + mlag: 300 + non_mlag: 330 + trident_forwarding_table_partition: flexible exact-match 16000 l2-shared 18000 l3-shared + 22000 + + ``` + ??? example "Example using network ports and profiles" ```yaml diff --git a/ansible_collections/arista/avd/roles/eos_designs/docs/tables/network-ports.md b/ansible_collections/arista/avd/roles/eos_designs/docs/tables/network-ports.md index bee74e75a66..042559d7443 100644 --- a/ansible_collections/arista/avd/roles/eos_designs/docs/tables/network-ports.md +++ b/ansible_collections/arista/avd/roles/eos_designs/docs/tables/network-ports.md @@ -10,7 +10,7 @@ | [network_ports](## "network_ports") | List, items: Dictionary | | | | | | [  - switches](## "network_ports.[].switches") | List, items: String | | | | Regex matching the full hostname of one or more switches.
The regular expression must match the full hostname.
| | [      - <str>](## "network_ports.[].switches.[]") | String | | | | | - | [    platforms](## "network_ports.[].platforms") | List, items: String | | | | Matching the platform type of one or more switches. If you need to add custom platforms to match specific port quantities, create them under `custom_platform_settings`.
Entries under `custom_platform_settings` should match the platform match criteria.
For example, `720XP-48Y6` would require a custom platform type:

platforms:
- 720XP
- 720XP-48Y6
| + | [    platforms](## "network_ports.[].platforms") | List, items: String | | | Min Length: 1 | Matching the platform type of one or more switches. If you need to add custom platforms to match specific port quantities, create them under `custom_platform_settings`.
Entries under `custom_platform_settings` should match the platform match criteria.
For example, `720XP-48Y6` would require a custom platform type:

platforms:
- 720XP
- 720XP-48Y6
| | [      - <str>](## "network_ports.[].platforms.[]") | String | | | | | | [    switch_ports](## "network_ports.[].switch_ports") | List, items: String | | | | List of ranges using AVD range_expand syntax.
For example:

switch_ports:
- Ethernet1
- Ethernet2-48

All switch_ports ranges are expanded into individual port configurations.

For more details and examples of the `range_expand` syntax, see the [`arista.avd.range_expand` documentation](../../../docs/plugins/Filter_plugins/range_expand.md).
| | [      - <str>](## "network_ports.[].switch_ports.[]") | String | | | | | @@ -201,7 +201,7 @@ # platforms: # - 720XP # - 720XP-48Y6 - platforms: + platforms: # >=1 items - # List of ranges using AVD range_expand syntax. 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 c4b5c4b4c7d..3f1eff801a7 100644 --- a/python-avd/pyavd/_eos_designs/schema/eos_designs.schema.yml +++ b/python-avd/pyavd/_eos_designs/schema/eos_designs.schema.yml @@ -2296,6 +2296,7 @@ keys: type: str platforms: type: list + min_length: 1 description: "Matching the platform type of one or more switches. If you need to add custom platforms to match specific port quantities, create them under `custom_platform_settings`.\nEntries under `custom_platform_settings` diff --git a/python-avd/pyavd/_eos_designs/schema/schema_fragments/network_ports.schema.yml b/python-avd/pyavd/_eos_designs/schema/schema_fragments/network_ports.schema.yml index bdadac0929e..ee7184e2bb2 100644 --- a/python-avd/pyavd/_eos_designs/schema/schema_fragments/network_ports.schema.yml +++ b/python-avd/pyavd/_eos_designs/schema/schema_fragments/network_ports.schema.yml @@ -22,6 +22,8 @@ keys: type: str platforms: type: list + # TODO: AVD 6.0.0 add min_length: 1 for switches + min_length: 1 description: | Matching the platform type of one or more switches. If you need to add custom platforms to match specific port quantities, create them under `custom_platform_settings`. Entries under `custom_platform_settings` should match the platform match criteria. From ba8b5e8d8fbc10746f064ce87073de7dc5278e2f Mon Sep 17 00:00:00 2001 From: kpbush30 Date: Wed, 11 Dec 2024 14:27:57 +0000 Subject: [PATCH 09/15] Fix behavior on match criteria to avoid bad time --- .../configs/network-ports-tests-2.cfg | 15 +------- .../configs/network-ports-tests.1.cfg | 15 +------- .../network-ports-tests-2.yml | 20 +---------- .../network-ports-tests.1.yml | 20 +---------- .../group_vars/NETWORK_PORTS_TESTS.yml | 34 ++++++++++--------- .../connected_endpoints/utils.py | 3 ++ 6 files changed, 25 insertions(+), 82 deletions(-) diff --git a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/configs/network-ports-tests-2.cfg b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/configs/network-ports-tests-2.cfg index 6b85975b97a..33fabba126f 100644 --- a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/configs/network-ports-tests-2.cfg +++ b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/configs/network-ports-tests-2.cfg @@ -597,23 +597,10 @@ interface Ethernet17 no shutdown switchport ! -interface Ethernet23 - description PCs - no shutdown - switchport access vlan 100 - switchport mode access - switchport - spanning-tree portfast - spanning-tree bpdufilter enable -! interface Ethernet24 - description PCs + description Matched on only 24 port platform no shutdown - switchport access vlan 100 - switchport mode access switchport - spanning-tree portfast - spanning-tree bpdufilter enable ! interface Ethernet51 no shutdown diff --git a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/configs/network-ports-tests.1.cfg b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/configs/network-ports-tests.1.cfg index a0044036aa1..525c57d4c48 100644 --- a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/configs/network-ports-tests.1.cfg +++ b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/configs/network-ports-tests.1.cfg @@ -544,23 +544,10 @@ interface Ethernet14 no shutdown switchport ! -interface Ethernet47 - description PCs - no shutdown - switchport access vlan 100 - switchport mode access - switchport - spanning-tree portfast - spanning-tree bpdufilter enable -! interface Ethernet48 - description PCs + description Matched on all hostnames and 48 port platform no shutdown - switchport access vlan 100 - switchport mode access switchport - spanning-tree portfast - spanning-tree bpdufilter enable ! interface Ethernet51 shutdown diff --git a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/structured_configs/network-ports-tests-2.yml b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/structured_configs/network-ports-tests-2.yml index cc820a07cdc..ed6e995672e 100644 --- a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/structured_configs/network-ports-tests-2.yml +++ b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/structured_configs/network-ports-tests-2.yml @@ -814,30 +814,12 @@ ethernet_interfaces: channel_group: id: 43 mode: active -- name: Ethernet23 - peer: PCs - peer_type: network_port - port_profile: pc - description: PCs - shutdown: false - switchport: - enabled: true - mode: access - access_vlan: 100 - spanning_tree_portfast: edge - spanning_tree_bpdufilter: enabled - name: Ethernet24 - peer: PCs peer_type: network_port - port_profile: pc - description: PCs + description: Matched on only 24 port platform shutdown: false switchport: enabled: true - mode: access - access_vlan: 100 - spanning_tree_portfast: edge - spanning_tree_bpdufilter: enabled mlag_configuration: domain_id: mlag local_interface: Vlan4094 diff --git a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/structured_configs/network-ports-tests.1.yml b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/structured_configs/network-ports-tests.1.yml index 8ec8a7f62c0..7d35eae0db7 100644 --- a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/structured_configs/network-ports-tests.1.yml +++ b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/intended/structured_configs/network-ports-tests.1.yml @@ -751,30 +751,12 @@ ethernet_interfaces: shutdown: true switchport: enabled: true -- name: Ethernet47 - peer: PCs - peer_type: network_port - port_profile: pc - description: PCs - shutdown: false - switchport: - enabled: true - mode: access - access_vlan: 100 - spanning_tree_portfast: edge - spanning_tree_bpdufilter: enabled - name: Ethernet48 - peer: PCs peer_type: network_port - port_profile: pc - description: PCs + description: Matched on all hostnames and 48 port platform shutdown: false switchport: enabled: true - mode: access - access_vlan: 100 - spanning_tree_portfast: edge - spanning_tree_bpdufilter: enabled mlag_configuration: domain_id: mlag local_interface: Vlan4094 diff --git a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml index 22f8c840a89..dc5c5a53634 100644 --- a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml +++ b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml @@ -141,34 +141,36 @@ network_ports: channel_id: 43 mode: "active" - # Tests below test hostname and platform matching. + # Tests for issue #4786 # Test regex match all switches and specific platform match criteria. - switches: - network-ports-tests.* - switch_ports: - - Ethernet47-48 platforms: - 720XPM-48Y6 - profile: pc - endpoint: PCs + switch_ports: + - Ethernet48 + description: Matched on all hostnames and 48 port platform - # Test regex match switch and no match on platform. - - switches: - - network-ports-tests.2 + # Test only platform match. + - platforms: + - 720XPM-24Y6 switch_ports: - - Ethernet47-48 + - Ethernet24 + description: Matched on only 24 port platform + + # Test criteria must match both hostname/platform. + - switches: + - network-ports-no-match platforms: - 720XPM-48Y6 - profile: pc - endpoint: PCs + switch_ports: + - Ethernet49 + description: Should not match hostname and platform # Test only platform match. - switch_ports: - - Ethernet23-24 - platforms: - - 720XPM-24Y6 - profile: pc - endpoint: PCs + - Ethernet25 + description: No criteria, no config servers: - name: CONNECTED_ENDPOINT_OVERWRITING_NETWORK_PORT diff --git a/python-avd/pyavd/_eos_designs/structured_config/connected_endpoints/utils.py b/python-avd/pyavd/_eos_designs/structured_config/connected_endpoints/utils.py index f06cd625a73..d036a078760 100644 --- a/python-avd/pyavd/_eos_designs/structured_config/connected_endpoints/utils.py +++ b/python-avd/pyavd/_eos_designs/structured_config/connected_endpoints/utils.py @@ -72,6 +72,9 @@ def _filtered_network_ports(self: AvdStructuredConfigConnectedEndpoints) -> list for index, network_port in enumerate(self.inputs.network_ports): network_port._context = f"network_ports[{index}]" network_port_settings = self.shared_utils.get_merged_adapter_settings(network_port) + + if not network_port_settings.switches and not network_port_settings.platforms: + continue if network_port_settings.switches and not self._match_regexes(network_port_settings.switches, self.shared_utils.hostname): continue if network_port_settings.platforms and self.shared_utils.platform not in network_port_settings.platforms: From 9dfb310e451caadcc8882c47a9a41b0e0fd83c67 Mon Sep 17 00:00:00 2001 From: kpbush30 Date: Wed, 11 Dec 2024 14:29:41 +0000 Subject: [PATCH 10/15] Fix comment --- .../inventory/group_vars/NETWORK_PORTS_TESTS.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml index dc5c5a53634..6843ddd7c41 100644 --- a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml +++ b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml @@ -167,7 +167,7 @@ network_ports: - Ethernet49 description: Should not match hostname and platform - # Test only platform match. + # Test no match criteria - switch_ports: - Ethernet25 description: No criteria, no config From acd34862beba3c6a0a850e7942984f2b8d8191af Mon Sep 17 00:00:00 2001 From: kpbush30 Date: Mon, 16 Dec 2024 14:07:44 +0000 Subject: [PATCH 11/15] Updates docs on maatch criteria usage. --- .../arista/avd/roles/eos_designs/docs/input-variables.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ansible_collections/arista/avd/roles/eos_designs/docs/input-variables.md b/ansible_collections/arista/avd/roles/eos_designs/docs/input-variables.md index f461c9c3b92..6eff35dc29d 100644 --- a/ansible_collections/arista/avd/roles/eos_designs/docs/input-variables.md +++ b/ansible_collections/arista/avd/roles/eos_designs/docs/input-variables.md @@ -1139,7 +1139,7 @@ roles/eos_designs/docs/tables/default-connected-endpoints-description.md The `network_ports` data model is intended to be used with `port_profiles` and `parent_profiles` to keep the configuration generic and compact, but all features and keys supported under `connected_endpoints.adapters` are also supported directly under `network_ports`. -Switches match criteria uses the list of `switches` hostname regex patterns or `platforms` list. When used in combination, the switch must match both criteria to generate the associated port configurations defined. +To filter what switches to configure, match on a switch's full hostname or platform type using regex patterns. When both criteria are used together, the switch must match both in order to generate the assigned port configuration. All ranges defined under `switch_ports` will be expanded to individual port configuration which leads to a some behavioral differences to `connected_endpoints`: From 5f931bcfd9ecd7cb5fad4e2a09c917550add63d1 Mon Sep 17 00:00:00 2001 From: kpbush30 Date: Mon, 16 Dec 2024 14:08:07 +0000 Subject: [PATCH 12/15] Update test to test on platform regex match --- .../inventory/group_vars/NETWORK_PORTS_TESTS.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml index 6843ddd7c41..04513ce6cdb 100644 --- a/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml +++ b/ansible_collections/arista/avd/molecule/eos_designs_unit_tests/inventory/group_vars/NETWORK_PORTS_TESTS.yml @@ -153,7 +153,7 @@ network_ports: # Test only platform match. - platforms: - - 720XPM-24Y6 + - 720\w+-24Y6 switch_ports: - Ethernet24 description: Matched on only 24 port platform From 2673c94af7f86459c108184592ecbe3dfdb1719a Mon Sep 17 00:00:00 2001 From: kpbush30 Date: Mon, 16 Dec 2024 14:33:39 +0000 Subject: [PATCH 13/15] Convert regex match to 'fullmatch' --- .../structured_config/connected_endpoints/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python-avd/pyavd/_eos_designs/structured_config/connected_endpoints/utils.py b/python-avd/pyavd/_eos_designs/structured_config/connected_endpoints/utils.py index d036a078760..724a095042a 100644 --- a/python-avd/pyavd/_eos_designs/structured_config/connected_endpoints/utils.py +++ b/python-avd/pyavd/_eos_designs/structured_config/connected_endpoints/utils.py @@ -77,7 +77,7 @@ def _filtered_network_ports(self: AvdStructuredConfigConnectedEndpoints) -> list continue if network_port_settings.switches and not self._match_regexes(network_port_settings.switches, self.shared_utils.hostname): continue - if network_port_settings.platforms and self.shared_utils.platform not in network_port_settings.platforms: + if network_port_settings.platforms and not self._match_regexes(network_port_settings.platforms, self.shared_utils.platform): continue filtered_network_ports.append(network_port_settings) @@ -90,7 +90,7 @@ def _match_regexes(self: AvdStructuredConfigConnectedEndpoints, regexes: list, v Regex must match the full value to pass, so regex is wrapped in ^$. """ - return any(re.match(rf"^{regex}$", value) for regex in regexes) + return any(re.fullmatch(regex, value) for regex in regexes) def _get_short_esi( self: AvdStructuredConfigConnectedEndpoints, From 80fe61b891dd7e7eccbe6e04ca2f2cda0712313b Mon Sep 17 00:00:00 2001 From: kpbush30 Date: Mon, 16 Dec 2024 14:42:37 +0000 Subject: [PATCH 14/15] Update platform match description --- .../eos_designs/docs/tables/network-ports.md | 8 ++-- .../pyavd/_eos_designs/schema/__init__.py | 38 +++++++++++-------- .../schema/eos_designs.schema.yml | 12 +++--- .../schema_fragments/network_ports.schema.yml | 6 ++- 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/ansible_collections/arista/avd/roles/eos_designs/docs/tables/network-ports.md b/ansible_collections/arista/avd/roles/eos_designs/docs/tables/network-ports.md index 042559d7443..7a0efeef118 100644 --- a/ansible_collections/arista/avd/roles/eos_designs/docs/tables/network-ports.md +++ b/ansible_collections/arista/avd/roles/eos_designs/docs/tables/network-ports.md @@ -10,7 +10,7 @@ | [network_ports](## "network_ports") | List, items: Dictionary | | | | | | [  - switches](## "network_ports.[].switches") | List, items: String | | | | Regex matching the full hostname of one or more switches.
The regular expression must match the full hostname.
| | [      - <str>](## "network_ports.[].switches.[]") | String | | | | | - | [    platforms](## "network_ports.[].platforms") | List, items: String | | | Min Length: 1 | Matching the platform type of one or more switches. If you need to add custom platforms to match specific port quantities, create them under `custom_platform_settings`.
Entries under `custom_platform_settings` should match the platform match criteria.
For example, `720XP-48Y6` would require a custom platform type:

platforms:
- 720XP
- 720XP-48Y6
| + | [    platforms](## "network_ports.[].platforms") | List, items: String | | | Min Length: 1 | Regex matching the full platform name of one or more switches. If used in combination with switch hostname matching, both criteria must match for configuration.
If you need to add custom platforms to match specific port quantities, create them under `custom_platform_settings`. Entries under `custom_platform_settings` should
match the platform match criteria.

For example, `720XP-48Y6` would require a custom platform type:

platforms:
- 720XP
- 720XP-48Y6
| | [      - <str>](## "network_ports.[].platforms.[]") | String | | | | | | [    switch_ports](## "network_ports.[].switch_ports") | List, items: String | | | | List of ranges using AVD range_expand syntax.
For example:

switch_ports:
- Ethernet1
- Ethernet2-48

All switch_ports ranges are expanded into individual port configurations.

For more details and examples of the `range_expand` syntax, see the [`arista.avd.range_expand` documentation](../../../docs/plugins/Filter_plugins/range_expand.md).
| | [      - <str>](## "network_ports.[].switch_ports.[]") | String | | | | | @@ -194,8 +194,10 @@ - switches: - - # Matching the platform type of one or more switches. If you need to add custom platforms to match specific port quantities, create them under `custom_platform_settings`. - # Entries under `custom_platform_settings` should match the platform match criteria. + # Regex matching the full platform name of one or more switches. If used in combination with switch hostname matching, both criteria must match for configuration. + # If you need to add custom platforms to match specific port quantities, create them under `custom_platform_settings`. Entries under `custom_platform_settings` should + # match the platform match criteria. + # # For example, `720XP-48Y6` would require a custom platform type: # # platforms: diff --git a/python-avd/pyavd/_eos_designs/schema/__init__.py b/python-avd/pyavd/_eos_designs/schema/__init__.py index f77c0641647..0a9a9cdd237 100644 --- a/python-avd/pyavd/_eos_designs/schema/__init__.py +++ b/python-avd/pyavd/_eos_designs/schema/__init__.py @@ -7994,20 +7994,23 @@ class StructuredConfig(EosCliConfigGen.EthernetInterfacesItem): """ platforms: Platforms """ - Matching the platform type of one or more switches. If you need to add custom platforms to match - specific port quantities, create them under `custom_platform_settings`. - Entries under - `custom_platform_settings` should match the platform match criteria. - For example, `720XP-48Y6` would - require a custom platform type: + Regex matching the full platform name of one or more switches. If used in combination with switch + hostname matching, both criteria must match for configuration. + If you need to add custom platforms + to match specific port quantities, create them under `custom_platform_settings`. Entries under + `custom_platform_settings` should + match the platform match criteria. + + For example, `720XP-48Y6` + would require a custom platform type: platforms: - 720XP - 720XP-48Y6 - Subclass of AvdList with - `str` items. + Subclass of AvdList + with `str` items. """ switch_ports: SwitchPorts """ @@ -8252,20 +8255,23 @@ def __init__( Subclass of AvdList with `str` items. platforms: - Matching the platform type of one or more switches. If you need to add custom platforms to match - specific port quantities, create them under `custom_platform_settings`. - Entries under - `custom_platform_settings` should match the platform match criteria. - For example, `720XP-48Y6` would - require a custom platform type: + Regex matching the full platform name of one or more switches. If used in combination with switch + hostname matching, both criteria must match for configuration. + If you need to add custom platforms + to match specific port quantities, create them under `custom_platform_settings`. Entries under + `custom_platform_settings` should + match the platform match criteria. + + For example, `720XP-48Y6` + would require a custom platform type: platforms: - 720XP - 720XP-48Y6 - Subclass of AvdList with - `str` items. + Subclass of AvdList + with `str` items. switch_ports: List of ranges using AVD range_expand syntax. For example: 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 3f1eff801a7..8fdf8faa2e4 100644 --- a/python-avd/pyavd/_eos_designs/schema/eos_designs.schema.yml +++ b/python-avd/pyavd/_eos_designs/schema/eos_designs.schema.yml @@ -2297,11 +2297,13 @@ keys: platforms: type: list min_length: 1 - description: "Matching the platform type of one or more switches. If you - need to add custom platforms to match specific port quantities, create - them under `custom_platform_settings`.\nEntries under `custom_platform_settings` - should match the platform match criteria.\nFor example, `720XP-48Y6` would - require a custom platform type:\n\nplatforms:\n - 720XP\n - 720XP-48Y6\n" + description: "Regex matching the full platform name of one or more switches. + If used in combination with switch hostname matching, both criteria must + match for configuration.\nIf you need to add custom platforms to match + specific port quantities, create them under `custom_platform_settings`. + Entries under `custom_platform_settings` should\nmatch the platform match + criteria.\n\nFor example, `720XP-48Y6` would require a custom platform + type:\n\nplatforms:\n - 720XP\n - 720XP-48Y6\n" items: type: str switch_ports: diff --git a/python-avd/pyavd/_eos_designs/schema/schema_fragments/network_ports.schema.yml b/python-avd/pyavd/_eos_designs/schema/schema_fragments/network_ports.schema.yml index ee7184e2bb2..7bd4d67353f 100644 --- a/python-avd/pyavd/_eos_designs/schema/schema_fragments/network_ports.schema.yml +++ b/python-avd/pyavd/_eos_designs/schema/schema_fragments/network_ports.schema.yml @@ -25,8 +25,10 @@ keys: # TODO: AVD 6.0.0 add min_length: 1 for switches min_length: 1 description: | - Matching the platform type of one or more switches. If you need to add custom platforms to match specific port quantities, create them under `custom_platform_settings`. - Entries under `custom_platform_settings` should match the platform match criteria. + Regex matching the full platform name of one or more switches. If used in combination with switch hostname matching, both criteria must match for configuration. + If you need to add custom platforms to match specific port quantities, create them under `custom_platform_settings`. Entries under `custom_platform_settings` should + match the platform match criteria. + For example, `720XP-48Y6` would require a custom platform type: platforms: From 5276f51d1ed9fdf76f16ab63d6f4a57ed5357a43 Mon Sep 17 00:00:00 2001 From: kpbush30 Date: Mon, 16 Dec 2024 14:45:26 +0000 Subject: [PATCH 15/15] Move TODO comment --- .../schema/schema_fragments/network_ports.schema.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python-avd/pyavd/_eos_designs/schema/schema_fragments/network_ports.schema.yml b/python-avd/pyavd/_eos_designs/schema/schema_fragments/network_ports.schema.yml index 7bd4d67353f..37e67026703 100644 --- a/python-avd/pyavd/_eos_designs/schema/schema_fragments/network_ports.schema.yml +++ b/python-avd/pyavd/_eos_designs/schema/schema_fragments/network_ports.schema.yml @@ -13,6 +13,7 @@ keys: $ref: "eos_designs#/$defs/adapter_config" # These keys will take precedence over $ref keys: + # TODO: AVD 6.0.0 add min_length: 1 for switches switches: type: list description: | @@ -22,7 +23,6 @@ keys: type: str platforms: type: list - # TODO: AVD 6.0.0 add min_length: 1 for switches min_length: 1 description: | Regex matching the full platform name of one or more switches. If used in combination with switch hostname matching, both criteria must match for configuration.