Skip to main content

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

[!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-keys option.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

net_schema-0.1.1.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

net_schema-0.1.1-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file net_schema-0.1.1.tar.gz.

File metadata

  • Download URL: net_schema-0.1.1.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.8.10 Linux/5.15.133.1-microsoft-standard-WSL2

File hashes

Hashes for net_schema-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7baf7449532c8fb765db5f90404aab01a11ba44d1210076d26600ce22ec2fc86
MD5 561d2042e51ba2497bca6efe21b9e292
BLAKE2b-256 1eb3fc626ce7e11ccaa29f11512e821abe33031adaf40e56029ad7f0020d8035

See more details on using hashes here.

File details

Details for the file net_schema-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: net_schema-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.8.10 Linux/5.15.133.1-microsoft-standard-WSL2

File hashes

Hashes for net_schema-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bb1cf2ffb91f4b3a7d3ea9a1c7adea2ee1bb16ec8180edb33cf746bcf74383ab
MD5 52c3163ef0c01afb6abeafd08821b7b9
BLAKE2b-256 eac227fcc3ddc39147fc3a1a8e74a704130cd0127735e3cb936e9f3d5645e412

See more details on using hashes here.

Supported by

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