Nornir plugin to validate network state on a per-device basis
Project description
Nornir Validate
A Nornir plugin for validating network state (actual state) against YAML-based specifications (desired state). This project extends napalm-validate to perform command-based validation rather than relying solely on getters, providing greater flexibility in validating arbitrary command outputs. It leverages Nornir with nornir-netmiko to collect and format device data, then compares actual state against desired state to generate a compliance report.
For a complete list of supported validations, see the validation reference.
How It Works
- Validation File: The expected desired state specified in YAML format (can be automatically generated) is provided at runtime
- Desired State: The validation file is rendered by Jinja adding validation commands to the desired state and storing this as a Nornir host variable
- Data Collection: Nornir (netmiko plugin) executes commands against target devices parsing the outputs through
ntc-templatesto construct the actual state - Compliance Report: The desired state and actual state are fed into napalm_validate generating a compliance report of the differences
Installation
pip install nornir-validate
or
uv add nornir-validate
Due to the fact I am using a customised version on nornir-rich you must install that branch manually as PyPi will only default PyPI version (see issue #5)
uv add "nornir_rich @ git+https://github.com/sjhloco/nornir_rich" --branch per_panel_var
Usage
Below is just the bare minimum to get started, see the documentation for more detailed information.
Generating a Compliance Report
The compliance report is generated based on a YAML formatted validation file describing the desired state of the network. Comprehensive validation file examples for all supported operating systems and features can be found in the example_validation_files directory.
import yaml
from nornir import InitNornir
from nornir_validate import validate, print_result_val
nr = InitNornir(config_file="config.yml")
with open("input_val_data.yml") as tmp_data:
input_data = yaml.load(tmp_data, Loader=yaml.Loader)
result = nr.run(task=validate, input_data=input_data)
print_result_val(result)
By default the full compliance report will be printed to the screen if the validation fails, add the save_report="" argument to also save it to file.
Auto-generation of Validation Files
Rather than defining validation files manually from scratch they can be automatically generated from a devices actual state based of an index of sub-features. If no index file is specified (omit the input_data= argument), validations will be generated for all enabled sub-features on the device.
from nornir import InitNornir
from nornir_validate import generate_val_file, print_result_gvf
nr = InitNornir(config_file="config.yml")
with open("CORE_index.yml") as tmp_data:
input_idx = yaml.load(tmp_data, Loader=yaml.Loader)
result = nr.run(task=generate_val_file, input_data=input_idx)
print_result_gvf(result, nr)
Validations that have environment-specific elements (such as VRF route table) must be manually defined in the index file, if not it will only generate validations for the global elements (the global routing table).
Example projects
Below are few projects that use nornir-validate:
- nr-val: A basic no-frills script to generate validation files and create compliance reports
- nornir-ppcheck: Tool for running pre and post change check as well as validation of network state
- update-mgmt-acl: Tool to update management and SNMP ACLs on Cisco IOS-XE, NXOS and ASA
Contributing
If you want to help add any validations to the project the Contribution Guidelines walk through the steps.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nornir_validate-0.3.2.tar.gz.
File metadata
- Download URL: nornir_validate-0.3.2.tar.gz
- Upload date:
- Size: 35.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b2815a4d3620563755fb37324e7009d6f7c2681cd053b9b8b660f4e2779723c
|
|
| MD5 |
efd1119c563895db9b51d0c1441d6bc5
|
|
| BLAKE2b-256 |
5e62ae8eded2c4c559619db16809268ca105b7fc9f0b28bfd5ac5f7d15ed29ab
|
Provenance
The following attestation bundles were made for nornir_validate-0.3.2.tar.gz:
Publisher:
publish.yml on sjhloco/nornir-validate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nornir_validate-0.3.2.tar.gz -
Subject digest:
7b2815a4d3620563755fb37324e7009d6f7c2681cd053b9b8b660f4e2779723c - Sigstore transparency entry: 894873393
- Sigstore integration time:
-
Permalink:
sjhloco/nornir-validate@2464c2a0ad7a67a75c36feb801bd04be648292f7 -
Branch / Tag:
refs/tags/v0.3.2 - Owner: https://github.com/sjhloco
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2464c2a0ad7a67a75c36feb801bd04be648292f7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file nornir_validate-0.3.2-py3-none-any.whl.
File metadata
- Download URL: nornir_validate-0.3.2-py3-none-any.whl
- Upload date:
- Size: 71.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15b3d5be037263f795c37308413d39867c2da52f08833a425d8aed1a6a878630
|
|
| MD5 |
84bf1e9ed5115919ade62714100a5e6c
|
|
| BLAKE2b-256 |
4c35d4b570604fc648c6f42ce6319d24a5e1a8b14e6ed42bcc91f6627e570b52
|
Provenance
The following attestation bundles were made for nornir_validate-0.3.2-py3-none-any.whl:
Publisher:
publish.yml on sjhloco/nornir-validate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nornir_validate-0.3.2-py3-none-any.whl -
Subject digest:
15b3d5be037263f795c37308413d39867c2da52f08833a425d8aed1a6a878630 - Sigstore transparency entry: 894873423
- Sigstore integration time:
-
Permalink:
sjhloco/nornir-validate@2464c2a0ad7a67a75c36feb801bd04be648292f7 -
Branch / Tag:
refs/tags/v0.3.2 - Owner: https://github.com/sjhloco
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2464c2a0ad7a67a75c36feb801bd04be648292f7 -
Trigger Event:
release
-
Statement type: