Net Schema is a library that allows you to validate the schema of your YAML documents. For example your Ansible host vars or group vars.
Project description
Net Schema
About this Project
Net Schema is a library that validates JSON and YAML documents against a defined schema, utilizing JSON Schema. This ensures that data adheres to specified formats and rules.
Additionally, this project is designed for schema validation of network-specific data, providing a range of network-related custom validators.
Installation
To install Net Schema:
pip install net-schema
uv add net-schema
Usage
Net Schema provides a CLI. You pass in the path to your documents, along with your schema path. Then Net Schema validates your data against the schema.
net-schema --help
Usage: net-schema [OPTIONS]
Validate a directory of YAML and JSON files against a schema.
Options:
-p, --document_path PATH Path to the documents directory [required]
-s, --schema PATH Path to the schema file [required]
-k, --check-dup-keys Check for duplicate keys in JSON or YAML documents
--help Show this message and exit.
[!NOTE] Net Schema also provides an additional option to check for the presence of duplicate keys within your YAML or JSON data via the
--check-dup-keysoption.
Custom Validators
Net Schema provides various custom validators that can be used within your schema.
Usage
To utilize custom validators within your schema, provide the name of the validator as a key, and then provide True as its value.
Below is an example of using the vlan custom validator to ensure the vlans array consist of vlan values (i.e. integers between 1 and 4094).
type: object
properties:
vlans:
type: array
items:
vlan: True
ASN Validators
| Validator Name | Checks |
|---|---|
asn |
Validates whether the ASN is valid in general. |
asn_public |
Checks if the ASN is a public/global ASN. |
asn_private |
Determines if the ASN is a private ASN. |
asn_reserved |
Identifies if the ASN is reserved. |
asn_documentation |
Validates if the ASN is meant for documentation. |
asn_2byte |
Checks if the ASN falls within the 2-byte ASN range. |
asn_4byte |
Checks if the ASN falls within the 4-byte ASN range. |
asn_notation_dot |
Validates ASN format in dot notation. |
asn_notation_int |
Validates ASN format in integer notation. |
IP Validators
| Validator Name | Checks |
|---|---|
ip |
Validates if the instance is a valid IP address. |
ip_ipv4 |
Checks if the instance is a valid IPv4 address. |
ip_ipv6 |
Checks if the instance is a valid IPv6 address. |
ip_multicast |
Determines if the instance is a multicast IP address. |
ip_private |
Validates if the instance is a private IP address. |
ip_reserved |
Identifies if the instance is a reserved IP address. |
ip_linklocal |
Checks if the instance is a link-local IP address. |
ip_network |
Validates if the instance represents a valid IP network. |
VLAN Validators
| Validator Name | Checks |
|---|---|
vlan |
Validates if the instance is a valid VLAN ID (between 1 and 4094). |
vlan_standard |
Checks if the instance is a standard VLAN ID (between 1 and 1001). |
vlan_extended |
Determines if the instance is an extended VLAN ID (between 1006 and 4094). |
Example
document
interfaces:
- name: eth0
ip: 10.1.1.1
netmask: 255.255.255.0
- name: eth1
ip: 10.1.2.1
netmask: 255.255.255.0
- name: eth2
ip: 10.1.3.1
netmask: 255.255.255.0
- name: eth3
ip: 10.1.4.1000
netmask: 255.255.255.0
- name: eth4
ip: 10.1.5.1
netmask: 255.255.255.0
schema
type: object
properties:
interfaces:
type: array
items:
type: object
properties:
name:
type: string
pattern: '^eth[0-9]+$'
ip:
ip_ipv4: true
netmask:
type: string
pattern: '^255\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$'
❯ net-schema --document_path examples/host_vars/ --schema examples/schema.yaml --check-dup-keys
───────────────────────────────────────────────────────────────────────────────────────────────────
Result Filename Location Msg
───────────────────────────────────────────────────────────────────────────────────────────────────
❌ examples/host_vars/rtr001.yml ['interfaces', 3, 'ip'] '10.1.4.1000' is not a 'ipv4'
✅ examples/host_vars/rtr002.yml -- --
✅ examples/host_vars/rtr003.yml -- --
Project details
Release history Release notifications | RSS feed
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 net_schema-1.0.0.tar.gz.
File metadata
- Download URL: net_schema-1.0.0.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a78aa0f6a07c1d017a84c3a922ef6d8106b8627b9c8dbd9c90136d3dd52735a
|
|
| MD5 |
fc789952eb1d7493dde4f64f4274ba71
|
|
| BLAKE2b-256 |
5aba83e3bf633bc12e79654371aeddb2e403e48d58dc4f5f4393375975c253ea
|
File details
Details for the file net_schema-1.0.0-py3-none-any.whl.
File metadata
- Download URL: net_schema-1.0.0-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c7fb34c45d7c53a73dc434a05e794c3c61931a95044871d9069f7e93a69827f
|
|
| MD5 |
c3607b218a317d210c741b3f42f2c0bd
|
|
| BLAKE2b-256 |
fa41540aa634a30a71582aa8332d1f4be7ff93e9f60aa697cdc50917ee949462
|