Skip to main content

Nornir plugin to validate network state on a per-device basis

Project description

Ruff Checked with mypy Documentation Status

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

  1. Validation File: The expected desired state specified in YAML format (can be automatically generated) is provided at runtime
  2. Desired State: The validation file is rendered by Jinja adding validation commands to the desired state and storing this as a Nornir host variable
  3. Data Collection: Nornir (netmiko plugin) executes commands against target devices parsing the outputs through ntc-templates to construct the actual state
  4. Compliance Report: The desired state and actual state are fed into napalm_validate generating a compliance report of the differences

Image

Installation

pip install nornir-validate

or

uv add nornir-validate

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_val_result

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_val_result(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 val_file_builder, print_build_result

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=val_file_builder, input_data=input_idx)
print_build_result(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).

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

nornir_validate-0.2.3.tar.gz (34.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nornir_validate-0.2.3-py3-none-any.whl (70.6 kB view details)

Uploaded Python 3

File details

Details for the file nornir_validate-0.2.3.tar.gz.

File metadata

  • Download URL: nornir_validate-0.2.3.tar.gz
  • Upload date:
  • Size: 34.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nornir_validate-0.2.3.tar.gz
Algorithm Hash digest
SHA256 66a704937be2888a600f2d67caa4e503b3a9dd93781da0a143a789df69cdd041
MD5 078c8a2810fadb7ccc4f62bb536546c9
BLAKE2b-256 3c82f1ccdca49a4b55a76cf805527b7ea2c1c3efd2704b180d7e55a25f3c5b95

See more details on using hashes here.

Provenance

The following attestation bundles were made for nornir_validate-0.2.3.tar.gz:

Publisher: publish.yml on sjhloco/nornir-validate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nornir_validate-0.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for nornir_validate-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a4bb47b4433e73b4c6268ed3efc80a2334f805b00855d8956a6aea7e7679aae7
MD5 e703212d5426e87ce8b7d4657167a5e2
BLAKE2b-256 da07c920cd469aab595c47663cf5a6a0ee21349aebfd58180f595b0d278c96d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for nornir_validate-0.2.3-py3-none-any.whl:

Publisher: publish.yml on sjhloco/nornir-validate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page