You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+120-47
Original file line number
Diff line number
Diff line change
@@ -8,11 +8,11 @@ JSON Schema (for) Network as Code
8
8
9
9
The majority of Network and Infrastructure automation is done in YAML. Be it Ansible Host Variables, Network Device data to build a Jinja2 configuration with, or just a collection of data you want to run a script against to put into another product you have likely written a YAML file and have had to debug a typo or had to help another colleague build a new file for a new device.
10
10
11
-
In an ideal world you can (and should) put a lot of this data into a database or Network Source of Truth solution and pull from it so the validation is done for you. However, these solutions don't cover every case and generally don't play nice with a GIT CI/CD process so you still will likely end up creating some YAML files here and there.
11
+
In an ideal world you can (and should) put a lot of this data into a database or Network Source of Truth solution and pull from it so the validation is done for you. However, these solutions don't cover every use case so you will likely end up creating some YAML files here and there.
12
12
13
-
Using a JSON schema for validating your YAML is a good practice in a CI/CD world but is very cumbersome to create from scratch.
13
+
Using a JSON schema for validating & documenting your YAML is a good practice in a CI/CD world but is very cumbersome to create from scratch.
14
14
15
-
This project aims to simplify this whole process to help you build a decent JSON schema base from a YAML file with network and infrastructure data definitions in mind.
15
+
This project aims to simplify this whole process by helping you build a JSON schema using YAML syntax that has network and infrastructure templates (or sub-schemas) in mind.
16
16
17
17
Now you can hopefully catch those rare mistakes before you run that Playbook, create that configuration with a Jinja2 template or run a REST query to that Source of Truth or Telemetry solution :)
18
18
@@ -24,7 +24,7 @@ Take a basic Ansible host_vars YAML file for a host below:
24
24
chassis:
25
25
hostname: "ceos-spine1"
26
26
model: "ceos"
27
-
type: "router"
27
+
device_type: "router"
28
28
29
29
system:
30
30
domain_name: "example.com"
@@ -40,55 +40,128 @@ interfaces:
40
40
ipv4: "10.1.0.20/24"
41
41
```
42
42
43
-
You can simply write out how you would like to validate this data, and this program will write out a JSON schema you can use. You can just also keep your existing data if you just want some basic type validation (string, integer, float, array, etc.).
43
+
You can simply write out how you would like to document & validate this data in YAML using kinds, and this program will write out a JSON schema you can use.
Alternatively, you can also just use dictionaries inplace:
84
+
We also have full support for writing your own titles, descriptions, kinds (sub-schemas), objects that are required, etc. A more fleshed out example of the same schema is below:
"description": "Ansible host vars for my networking device. Requires the below objects:\n- chassis\n- system\n- interfaces\n"
7
+
},
8
+
"kinds": {
3
9
"hostname": {
4
-
"jsnac_type": "pattern",
5
-
"jsnac_pattern": "^ceos-[a-zA-Z]{1,16}[0-9]$"
6
-
},
7
-
"model": "ceos",
8
-
"type": {
9
-
"jsnac_type": "choice",
10
-
"jsnac_choices": [
11
-
"router",
12
-
"switch",
13
-
"spine",
14
-
"leaf"
15
-
]
10
+
"title": "Hostname",
11
+
"description": "Hostname of the device",
12
+
"type": "pattern",
13
+
"regex": "^[a-zA-Z0-9-]{1,63}$"
16
14
}
17
15
},
18
-
"system": {
19
-
"domain_name": {
20
-
"jsnac_type": "domain"
21
-
},
22
-
"ntp_servers": [
23
-
{
24
-
"jsnac_type": "ipv4"
25
-
}
26
-
]
27
-
},
28
-
"interfaces": [
29
-
{
30
-
"if": {
31
-
"jsnac_type": "string"
16
+
"schema": {
17
+
"chassis": {
18
+
"title": "Chassis",
19
+
"description": "Object containing Chassis information. Has the below properties: \nhostname [required]: hostname\nmodel [required]: string\ndevice_type [required]: choice (router, switch, firewall, load-balancer)\n",
20
+
"type": "object",
21
+
"properties": {
22
+
"hostname": {
23
+
"kind": {
24
+
"name": "hostname"
25
+
}
26
+
},
27
+
"model": {
28
+
"kind": {
29
+
"name": "string"
30
+
}
31
+
},
32
+
"device_type": {
33
+
"title": "Device Type",
34
+
"description": "Device Type options are:\nrouter, switch, firewall, load-balancer\n",
35
+
"kind": {
36
+
"name": "choice",
37
+
"choices": [
38
+
"router",
39
+
"switch",
40
+
"firewall",
41
+
"load-balancer"
42
+
]
43
+
}
44
+
}
32
45
},
33
-
"desc": {
34
-
"jsnac_type": "string"
35
-
},
36
-
"ipv4": {
37
-
"jsnac_type": "ipv4_cidr"
46
+
"required": [
47
+
"hostname",
48
+
"model",
49
+
"device_type"
50
+
]
51
+
},
52
+
"system": {
53
+
"title": "System",
54
+
"description": "Object containing System information. Has the below properties:\ndomain_name [required]: string\nntp_servers [required]: list of ipv4 addresses\n",
55
+
"type": "object",
56
+
"properties": {
57
+
"domain_name": {
58
+
"kind": {
59
+
"name": "string"
60
+
}
61
+
},
62
+
"ntp_servers": {
63
+
"title": "NTP Servers",
64
+
"description": "List of NTP servers",
65
+
"type": "array",
66
+
"items": {
67
+
"kind": {
68
+
"name": "ipv4"
69
+
}
70
+
}
71
+
}
38
72
},
39
-
"ipv6": {
40
-
"jsnac_type": "ipv6_cidr"
73
+
"required": [
74
+
"domain_name",
75
+
"ntp_servers"
76
+
]
77
+
},
78
+
"interfaces": {
79
+
"title": "Device Interfaces",
80
+
"description": "List of device interfaces. Each interface has the below properties:\nif [required]: string\ndesc: string\nipv4: ipv4_cidr\nipv6: ipv6_cidr\n",
0 commit comments