Halo, Habr! Untuk mengantisipasi dimulainya kursus "Arsitek Jaringan", kami sarankan membaca terjemahan dari artikel yang bermanfaat.
Mengoptimalkan model data dan menghapus duplikat itu bagus, tetapi bagaimana kita bisa memastikan bahwa kita bekerja dengan model data yang valid ?
IPAM/CMDB , REST API, , . , , , .
, ( source-of-truth), , , . , , :
;
;
.
per-link , Ansible host_vars network.yml , :
YAML ( ,
yamllint);
hostnamebgp_as;
links, core edge ;
Core
prefix;
Edge , ( , JSON) .
( ), YANG, JSON Schema XML Schema, . YAML JSON, jsonschema.
. , , , , , .
Ansible. Β« Β» Ansible. , β ansible-inventory, JSON (external inventory script).
$ ansible-inventory -i ../hosts --list
{
"_meta": {
"hostvars": {
"S1": {
"bgp_as": 65001,
"description": "Unexpected",
"hostname": "S1"
},
"S2": {
"bgp_as": 65002,
"hostname": "S2"
}
}
},
"all": {
"children": [
"ungrouped"
]
},
... JSON , jq :
$ ansible-inventory -i ../hosts --list|jq ._meta.hostvars
{
"S1": {
"bgp_as": 65001,
"description": "Unexpected",
"hostname": "S1"
},
"S2": {
"bgp_as": 65002,
"hostname": "S2"
}
} jsonschema, , jsonschema JSON Schema, .
$ jsonschema -i /tmp/hosts.json hosts.schema.json
{'bgp_as': 65001, 'description': 'Unexpected', 'hostname': 'S1'}:
Additional properties are not allowed ('description' was unexpected) network.yml :
Convert YAML file into JSON format with
yq
YAML JSON
yq
Run
jsonschemaon the resulting JSON file
jsonschemaJSON
yq <network.yml . >/tmp/$$.network.json
jsonschema -i /tmp/$$.network.json network.schema.json, JSON Schema , β . :
, , core edge .
, , , , , .
JSON Schema
, JSON Schema . ( ISO IEEE). , - JSON Schema .
, JSON Schema: JSON, , Ansible:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://www.ipSpace.net/hosts.schema.json",
"title": "Ansible inventory data",
"definitions": {
...
},
"type": "object",
"patternProperties": {
".*" : { "$ref" : "#/definitions/router" }
},
"minProperties": 1
}:
Ansible (Ansible inventory data);
(. ).
β () ( , ), router
β ( ).
router definitions:
"router" : {
"type" : "object",
"properties": {
"bgp_as": {
"type": "number",
"minimum": 1,
"maximum": 65535
},
"hostname": {
"type": "string"
}
},
"required": [ "bgp_as","hostname" ],
"additionalProperties": false
}( , Ansible, ) β :
bgpas, 1 65535;
hostname
, .
JSON , GitHub. , host_vars .
JSON Schema , :
, JSON
network;
description;
bgp_as, 4- AS .
:
CI/CD Validation, Error Handling and Unit Tests - Building Network Automation Solutions.
Data Model Hierarchy