mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2025-01-03 07:31:54 +00:00
YANG: basic convertor JSON -> CBOR
This commit is contained in:
parent
1b9939b936
commit
815b1d4036
@ -1,2 +1,2 @@
|
|||||||
python3 -m venv venv
|
python3 -m venv venv
|
||||||
pip3 install pyang cbor
|
pip3 install yangson cbor
|
||||||
|
3
yang/json-cbor-yang
Executable file
3
yang/json-cbor-yang
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
. venv/bin/activate
|
||||||
|
python3 json-cbor-yang.py "$@"
|
||||||
|
#python3 json2cbor.py "$@"
|
24
yang/json-cbor-yang.py
Normal file
24
yang/json-cbor-yang.py
Normal 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
1
yang/show_memory.cbor
Normal file
@ -0,0 +1 @@
|
|||||||
|
¡sshow_memory:message¢fheaderqBIRD memory usagedbody¦nrouting_tables¢ieffectiveDhoverhead0proute_attributes¢ieffectiveDhoverhead0iprotocols¢ieffectiveDhoverhead0ncurrent_config¢ieffectiveDhoverhead0nstandby_memory¢ieffectiveDhoverhead0etotal¢ieffectiveDhoverhead0
|
@ -1,6 +1,6 @@
|
|||||||
module show_memory {
|
module show_memory {
|
||||||
|
|
||||||
namespace ".";
|
namespace "https://bird.nic.cz/yang/v2.15/cli-debug";
|
||||||
|
|
||||||
prefix "memory";
|
prefix "memory";
|
||||||
|
|
||||||
|
13
yang/yang-library.json
Normal file
13
yang/yang-library.json
Normal 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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user