PyAVD¶
PyAVD is a python package providing some of the features from the arista.avd
Ansible collection without requiring Ansible. PyAVD leverages the same logic as the Ansible collection, so the generated outputs should be exactly the same based on the same inputs.
PyAVD does not provide any inventory or variable management, so PyAVD cannot replace a full Ansible based solution by itself. PyAVD could serve as an element in larger framework.
Supported features:
- Validation of inputs based on the
eos_designs
input schema. - Generation of “avd_facts” and “structured config” to be used in other PyAVD functions.
- Validation of “structured config” based on the
eos_cli_config_gen
input schema. - Generation of device configuration.
- Generation of device documentation.
Feedback is very welcome. Please use GitHub discussions.
Functions overview¶
Known limitations¶
Warning
Input data and “structured_configs” will be in-place updated by various PyAVD functions. Make sure to deep copy the data first if modifications are not allowed.
Warning
get_device_structured_config()
, get_device_config()
and get_device_doc()
are not thread-safe, so avoid running them for the same device across multiple threads.
Note
- No support for inline Jinja2 or custom Jinja2 templates.
- The logic uses the hostname as the unique identifier for each device, so overlapping hostnames will not work.
- For
get_avd_facts()
,fabric_name
is not used or verified and may differ between devices. All devices in the given inputs will be treated as one fabric. hostname
must be set in “structured_config” for each device.hostname
will be set correctly when usingget_structured_config()
.
Roadmap¶
Note
Subject to change. No commitments implied.
- Add examples
- Add more tests (current coverage is 85%)
- Add network state validation similar to
eos_validate_state
. - Add CloudVision tag integrations
- Make PyAVD the source of AVD logic and use as a dependency for the
arista.avd
Ansible collection. - Explore support for custom Jinja2 templates.
Installation¶
Install the pyavd
Python package:
Requirements (automatically installed with above command):
Optional requirements¶
To install Ansible AVD collection additional Python requirements install with extra ansible
:
Reference¶
validate_inputs(inputs)
¶
Validate input variables according to the eos_designs
schema as documented on avd.arista.com.
Where supported by the schema, types will be auto type-converted like from “int” to “str”.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs |
dict
|
Dictionary with inputs for “eos_designs”. |
required |
Returns:
Type | Description |
---|---|
ValidationResult
|
Validation result object with any validation errors or deprecation warnings. |
Source code in python-avd/pyavd/validate_inputs.py
get_avd_facts(all_inputs)
¶
Build avd_facts using the AVD eos_designs_facts logic.
Variables should be converted and validated according to AVD eos_designs
schema first using pyavd.validate_inputs
.
Note! No support for inline templating or jinja templates for descriptions or ip addressing
Parameters:
Returns:
Source code in python-avd/pyavd/get_avd_facts.py
get_device_structured_config(hostname, inputs, avd_facts)
¶
Build and return the AVD structured configuration for one device.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hostname |
str
|
Hostname of device. |
required |
inputs |
dict
|
Dictionary with inputs for “eos_designs”.
Variables should be converted and validated according to AVD |
required |
avd_facts |
dict
|
Dictionary of avd_facts as returned from |
required |
Returns:
Type | Description |
---|---|
dict
|
Device Structured Configuration as a dictionary |
Source code in python-avd/pyavd/get_device_structured_config.py
validate_structured_config(structured_config)
¶
Validate structured config according the eos_cli_config_gen
schema as documented on avd.arista.com.
Where supported by the schema, types will be auto type-converted like from “int” to “str”.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
structured_config |
dict
|
Dictionary with structured configuration. |
required |
Returns:
Type | Description |
---|---|
ValidationResult
|
Validation result object with any validation errors or deprecation warnings. |
Source code in python-avd/pyavd/validate_structured_config.py
get_device_config(structured_config)
¶
Render and return the device configuration using AVD eos_cli_config_gen templates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
structured_config |
dict
|
Dictionary with structured configuration.
Variables should be converted and validated according to AVD |
required |
Returns:
Type | Description |
---|---|
str
|
Device configuration in EOS CLI format. |
Source code in python-avd/pyavd/get_device_config.py
get_device_doc(structured_config, add_md_toc=False)
¶
Render and return the device documentation using AVD eos_cli_config_gen templates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
structured_config |
dict
|
Dictionary with structured configuration.
Variables should be converted and validated according to AVD |
required |
add_md_toc |
bool
|
Add a table of contents for markdown headings. |
False
|
Returns:
Type | Description |
---|---|
str
|
Device documentation in Markdown format. |
Source code in python-avd/pyavd/get_device_doc.py
ValidationResult
¶
Object containing result of data validation
Attributes:
Name | Type | Description |
---|---|---|
failed |
bool
|
True if data is not valid according to the schema. Otherwise False. |
validation_errors |
list[AvdValidationError]
|
List of AvdValidationErrors containing schema violations. |
deprecation_warnings |
list[AvdDeprecationWarning]
|
List of AvdDeprecationWarnings containing warning for deprecated inputs. |