Models
Inventory Models¶
inventory ¶
Data models for AVD inventory structures.
This module defines the core data models for representing AVD inventories, including devices, fabrics, and complete inventory structures.
DeviceDefinition
dataclass
¶
DeviceDefinition(
hostname: str,
platform: str,
mgmt_ip: Union[str, IPv4Address, IPv6Address],
device_type: str,
fabric: str,
groups: List[str] = list(),
pod: Optional[str] = None,
rack: Optional[str] = None,
mgmt_gateway: Optional[
Union[str, IPv4Address, IPv6Address]
] = None,
serial_number: Optional[str] = None,
system_mac_address: Optional[str] = None,
structured_config: Dict[str, Any] = dict(),
custom_variables: Dict[str, Any] = dict(),
)
Core device definition data model.
Represents a single network device in the AVD inventory with all its properties and configuration data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hostname
|
str
|
Device hostname (must be valid DNS name) |
required |
platform
|
str
|
EOS platform type (validated against supported platforms) |
required |
mgmt_ip
|
Union[IPv4Address, IPv6Address]
|
Management IP address |
required |
device_type
|
str
|
Device role type (validated against supported types) |
required |
fabric
|
str
|
Fabric name this device belongs to |
required |
groups
|
List[str]
|
List of inventory groups this device belongs to, by default empty list |
list()
|
pod
|
Optional[str]
|
Pod identifier, by default None |
None
|
rack
|
Optional[str]
|
Rack identifier, by default None |
None
|
mgmt_gateway
|
Optional[Union[IPv4Address, IPv6Address]]
|
Management gateway IP, by default None |
None
|
serial_number
|
Optional[str]
|
Device serial number, by default None |
None
|
system_mac_address
|
Optional[str]
|
System MAC address, by default None |
None
|
structured_config
|
Dict[str, Any]
|
AVD structured configuration, by default empty dict |
dict()
|
custom_variables
|
Dict[str, Any]
|
Custom variables for this device, by default empty dict |
dict()
|
__post_init__ ¶
Validate device definition after initialization.
FabricDefinition
dataclass
¶
FabricDefinition(
name: str,
design_type: str,
devices_by_type: Dict[
str, List[DeviceDefinition]
] = dict(),
bgp_asn_range: Optional[str] = None,
mlag_peer_l3_vlan: int = 4093,
mlag_peer_vlan: int = 4094,
)
Fabric topology definition.
Represents a complete fabric with all its devices organized by type. Uses flexible device dictionary to support any AVD design type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Fabric name |
required |
design_type
|
str
|
Design type (e.g., ‘l3ls-evpn’, ‘mpls’, ‘l2ls’) |
required |
devices_by_type
|
Dict[str, List[DeviceDefinition]]
|
Dictionary mapping device type to list of devices, by default empty dict |
dict()
|
bgp_asn_range
|
Optional[str]
|
BGP ASN range for the fabric, by default None |
None
|
mlag_peer_l3_vlan
|
int
|
MLAG peer L3 VLAN ID, by default 4093 |
4093
|
mlag_peer_vlan
|
int
|
MLAG peer VLAN ID, by default 4094 |
4094
|
border_leaf_devices
property
¶
Get border leaf devices (backward compatibility).
Returns:
| Type | Description |
|---|---|
List[DeviceDefinition]
|
List of border leaf devices |
leaf_devices
property
¶
Get leaf devices (backward compatibility).
Returns:
| Type | Description |
|---|---|
List[DeviceDefinition]
|
List of leaf devices |
spine_devices
property
¶
Get spine devices (backward compatibility).
Returns:
| Type | Description |
|---|---|
List[DeviceDefinition]
|
List of spine devices |
get_all_devices ¶
Get all devices in fabric across all types.
Returns:
| Type | Description |
|---|---|
List[DeviceDefinition]
|
Combined list of all devices in the fabric |
Source code in avd_cli/models/inventory.py
get_devices_by_type ¶
Get devices filtered by type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device_type
|
str
|
Device type to filter by |
required |
Returns:
| Type | Description |
|---|---|
List[DeviceDefinition]
|
List of devices matching the specified type |
Source code in avd_cli/models/inventory.py
InventoryData
dataclass
¶
InventoryData(
root_path: Path,
fabrics: List[FabricDefinition] = list(),
global_vars: Dict[str, Any] = dict(),
group_vars: Dict[str, Dict[str, Any]] = dict(),
host_vars: Dict[str, Dict[str, Any]] = dict(),
)
Complete inventory data structure.
Represents the entire AVD inventory with all fabrics and global variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root_path
|
Path
|
Root path to the inventory directory |
required |
fabrics
|
List[FabricDefinition]
|
List of fabric definitions, by default empty list |
list()
|
global_vars
|
Dict[str, Any]
|
Global variables applicable to all devices, by default empty dict |
dict()
|
group_vars
|
Dict[str, Dict[str, Any]]
|
Group variables (resolved from group_vars/), by default empty dict |
dict()
|
host_vars
|
Dict[str, Dict[str, Any]]
|
Host variables (resolved from host_vars/), by default empty dict |
dict()
|
filter_devices ¶
Filter devices in inventory based on patterns.
This method applies device filtering in-place, modifying the inventory to contain only devices that match the filter patterns. Devices are matched by hostname OR group membership (union logic).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device_filter
|
Optional[DeviceFilter]
|
Filter to apply. If None, no filtering is performed. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no devices match the filter patterns |
Examples:
>>> from avd_cli.utils.device_filter import DeviceFilter
>>> filter = DeviceFilter(patterns=["leaf-*"])
>>> inventory.filter_devices(filter)
>>> # inventory now contains only devices matching "leaf-*"
Source code in avd_cli/models/inventory.py
get_all_devices ¶
Get all devices across all fabrics.
Returns:
| Type | Description |
|---|---|
List[DeviceDefinition]
|
Combined list of all devices from all fabrics |
Source code in avd_cli/models/inventory.py
get_device_by_hostname ¶
Find device by hostname.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hostname
|
str
|
Hostname to search for |
required |
Returns:
| Type | Description |
|---|---|
Optional[DeviceDefinition]
|
Device if found, None otherwise |
Source code in avd_cli/models/inventory.py
validate ¶
Validate complete inventory structure.
Checks for common issues like duplicate hostnames, duplicate IPs, etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skip_topology_validation
|
bool
|
Skip topology-specific validations (e.g., spine presence). Useful for cli-config workflow where structured configs are used directly, by default False |
False
|
Returns:
| Type | Description |
|---|---|
List[str]
|
List of validation error messages (empty if valid) |