Skip to content

Commit

Permalink
Refactor(eos_designs): Move default platform_settings. network_servic…
Browse files Browse the repository at this point in the history
…es_keys and connected_endpoints_keys to schema (#4395)
  • Loading branch information
gmuloc authored Sep 2, 2024
1 parent 6e7d8ad commit ef902de
Show file tree
Hide file tree
Showing 19 changed files with 250 additions and 262 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def create_avd_switch_facts_instances(self, fabric_hosts: list, hostvars: object
host_hostvars = dict(hostvars.get(host))

# Initialize SharedUtils class to be passed to EosDesignsFacts below.
shared_utils = SharedUtils(hostvars=host_hostvars, templar=self.templar)
shared_utils = SharedUtils(hostvars=host_hostvars, templar=self.templar, schema=avdschematools.avdschema)

# Insert dynamic keys into the input data if not set.
# These keys are required by the schema, but the default values are set inside shared_utils.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 49 additions & 12 deletions python-avd/pyavd/_eos_designs/schema/eos_designs.schema.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,42 @@ dynamic_keys:
display_name: Connected Endpoints
documentation_options:
table: connected-endpoints
default:
# NOTE: there is a static list of default endpoint keys in the
# fabric connected endpoints documentation templates.
- key: servers
type: server
description: Server
- key: firewalls
type: firewall
description: Firewall
- key: routers
type: router
description: Router
- key: load_balancers
type: load_balancer
description: Load Balancer
- key: storage_arrays
type: storage_array
description: Storage Array
- key: cpes
type: cpe
description: CPE
- key: workstations
type: workstation
description: Workstation
- key: access_points
type: access_point
description: Access Point
- key: phones
type: phone
description: Phone
- key: printers
type: printer
description: Printer
- key: cameras
type: camera
description: Camera
- key: generic_devices
type: generic_device
description: Generic Device
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,37 @@ keys:
default:
- key: servers
type: server
description: Server.
description: Server
- key: firewalls
type: firewall
description: Firewall.
description: Firewall
- key: routers
type: router
description: Router.
description: Router
- key: load_balancers
type: load_balancer
description: Load Balancer.
description: Load Balancer
- key: storage_arrays
type: storage_array
description: Storage Array.
description: Storage Array
- key: cpes
type: cpe
description: CPE.
description: CPE
- key: workstations
type: workstation
description: Workstation.
description: Workstation
- key: access_points
type: access_point
description: Access Point.
description: Access Point
- key: phones
type: phone
description: Phone.
description: Phone
- key: printers
type: printer
description: Printer.
description: Printer
- key: cameras
type: camera
description: Camera.
description: Camera
- key: generic_devices
type: generic_device
description: Generic Device.
description: Generic Device
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ keys:
name:
type: str
default:
- "name": "tenants"
- name: tenants
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ keys:
type: str
description: EOS CLI rendered directly on the root level of the final EOS configuration.
default:
# 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.
# This command is not supported on 710P or 722XP platforms. 720D range has some devices that support this
# and others that don't, but they are all grouped together as none of them support EVPN multicast.
# TODO: This needs to be revisited as some 720 platforms now support EVPN multicast.
- platforms:
- default
feature_support:
Expand Down
5 changes: 4 additions & 1 deletion python-avd/pyavd/_eos_designs/shared_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# 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 pyavd._schema.avdschema import AvdSchema

from .bgp_peer_groups import BgpPeerGroupsMixin
from .connected_endpoints_keys import ConnectedEndpointsKeysMixin
from .cv_topology import CvTopology
Expand Down Expand Up @@ -65,6 +67,7 @@ class SharedUtils(
The class cannot be overridden.
"""

def __init__(self, hostvars: dict, templar: object) -> None:
def __init__(self, hostvars: dict, templar: object, schema: AvdSchema) -> None:
self.hostvars = hostvars
self.templar = templar
self.schema = schema
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,6 @@
if TYPE_CHECKING:
from . import SharedUtils

# NOTE: there is a static list of default endpoint keys in the fabric connected endpoints documentation templates.
DEFAULT_CONNECTED_ENDPOINTS_KEYS = [
{"key": "servers", "type": "server", "description": "Server"},
{"key": "firewalls", "type": "firewall", "description": "Firewall"},
{"key": "routers", "type": "router", "description": "Router"},
{"key": "load_balancers", "type": "load_balancer", "description": "Load Balancer"},
{"key": "storage_arrays", "type": "storage_array", "description": "Storage Array"},
{"key": "cpes", "type": "cpe", "description": "CPE"},
{"key": "workstations", "type": "workstation", "description": "Workstation"},
{"key": "access_points", "type": "access_point", "description": "Access Point"},
{"key": "phones", "type": "phone", "description": "Phone"},
{"key": "printers", "type": "printer", "description": "Printer"},
{"key": "cameras", "type": "camera", "description": "Camera"},
{"key": "generic_devices", "type": "generic_device", "description": "Generic Device"},
]


class ConnectedEndpointsKeysMixin:
"""
Expand All @@ -44,6 +28,7 @@ def connected_endpoints_keys(self: SharedUtils) -> list:
NOTE: This method is called _before_ any schema validation, since we need to resolve connected_endpoints_keys dynamically
"""
connected_endpoints_keys = []
# Support legacy data model by converting nested dict to list of dict
connected_endpoints_keys = get(self.hostvars, "connected_endpoints_keys", default=DEFAULT_CONNECTED_ENDPOINTS_KEYS)
# Reading default value from schema
default_connected_endpoint_keys = self.schema.get_default_value(["connected_endpoints_keys"])
connected_endpoints_keys = get(self.hostvars, "connected_endpoints_keys", default=default_connected_endpoint_keys)
return [entry for entry in connected_endpoints_keys if entry.get("key") is not None and self.hostvars.get(entry["key"]) is not None]
3 changes: 2 additions & 1 deletion python-avd/pyavd/_eos_designs/shared_utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ def network_services_keys(self: SharedUtils) -> list[dict]:
NOTE: This method is called _before_ any schema validation, since we need to resolve network_services_keys dynamically
"""
default_network_services_keys = [{"name": "tenants"}]
# Reading default value from schema
default_network_services_keys = self.schema.get_default_value(["network_services_keys"])
network_services_keys = get(self.hostvars, "network_services_keys", default=default_network_services_keys)
network_services_keys = [entry for entry in network_services_keys if entry.get("name") is not None and self.hostvars.get(entry["name"]) is not None]
return natural_sort(network_services_keys, "name")
Expand Down
Loading

0 comments on commit ef902de

Please sign in to comment.