[!IMPORTANT] Please note that Net Schema is currently in beta.
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 the Net Schema library, perform the following:
Pip
pip install net-schema
Poetry
poetry 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 -- --
Metadata
Release files for net-schema 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| net_schema-0.1.0.tar.gz | 13.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| net_schema-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.9 kB
Release files / net_schema-0.1.0.tar.gz
| Download URL | net_schema-0.1.0.tar.gz |
|---|---|
| Size | 13.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f92a15356ec85cd021fdb971352ce8712a472f5c9b1f6932f4cedfb569d03645
|
|
BLAKE2b-256 checksum How to use checksums |
b7657929e0363599e88bcedb232dc2e3f3d9ec0c8241c0f8e51aa546a8d79c48
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.2 CPython/3.8.10 Linux/5.15.133.1-microsoft-standard-WSL2
|
Release files / net_schema-0.1.0-py3-none-any.whl
| Download URL | net_schema-0.1.0-py3-none-any.whl |
|---|---|
| Size | 12.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e9baf6e986d944d2750f2d29e1e908198ecc272039b41cd2a0af12219414c762
|
|
BLAKE2b-256 checksum How to use checksums |
eccba35a50ba7d7cd9b48f2902730623eb7e15be672d8304e9935a3777baf466
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.2 CPython/3.8.10 Linux/5.15.133.1-microsoft-standard-WSL2
|