0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-09-19 11:55:21 +00:00

YANG: basic convertor JSON -> CBOR

This commit is contained in:
Maria Matejka 2023-11-15 12:31:42 +01:00
parent 1b9939b936
commit 815b1d4036
6 changed files with 43 additions and 2 deletions

View File

@ -1,2 +1,2 @@
python3 -m venv venv
pip3 install pyang cbor
pip3 install yangson cbor

3
yang/json-cbor-yang Executable file
View File

@ -0,0 +1,3 @@
. venv/bin/activate
python3 json-cbor-yang.py "$@"
#python3 json2cbor.py "$@"

24
yang/json-cbor-yang.py Normal file
View File

@ -0,0 +1,24 @@
from yangson import DataModel
import cbor
import json
import sys
class Message:
def __init__(self, filename):
self.filename = filename
with open(self.filename) as sf:
self.raw = json.load(sf)
self.dm = DataModel.from_file('yang-library.json')
self.data = self.dm.from_raw(self.raw)
self.data.validate()
#print(sys.argv[1])
msg = Message(sys.argv[1])
#print(msg, msg.raw)
#print(cbor.dumps(msg.raw))
with open(sys.argv[2], "wb") as of:
cbor.dump(msg.raw, of)
print("OK")

1
yang/show_memory.cbor Normal file
View File

@ -0,0 +1 @@
¡sshow_memory:message¢fheaderqBIRD memory usagedbody¦nrouting_tables¢ieffectiveDhoverhead0proute_attributes¢ieffectiveDhoverhead0iprotocols¢ieffectiveDhoverhead0ncurrent_config¢ieffectiveDhoverhead0nstandby_memory¢ieffectiveDhoverhead0etotal¢ieffectiveDhoverhead0

View File

@ -1,6 +1,6 @@
module show_memory {
namespace ".";
namespace "https://bird.nic.cz/yang/v2.15/cli-debug";
prefix "memory";

13
yang/yang-library.json Normal file
View File

@ -0,0 +1,13 @@
{
"ietf-yang-library:modules-state": {
"module-set-id": "12345678abcdef1cefd14622032c432fa598540e",
"module": [
{
"name": "show_memory",
"namespace": "https://bird.nic.cz/yang/v2.15/cli-debug",
"revision": "",
"conformance-type": "implement"
}
]
}
}