]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
YANG: basic convertor JSON -> CBOR
authorMaria Matejka <mq@ucw.cz>
Wed, 15 Nov 2023 11:31:42 +0000 (12:31 +0100)
committerMaria Matejka <mq@ucw.cz>
Wed, 15 Nov 2023 11:31:42 +0000 (12:31 +0100)
yang/create-venv.sh
yang/json-cbor-yang [new file with mode: 0755]
yang/json-cbor-yang.py [new file with mode: 0644]
yang/show_memory.cbor [new file with mode: 0644]
yang/show_memory.yang
yang/yang-library.json [new file with mode: 0644]

index 07428c59df59cb65b2b805fe42e78dcee00ab748..13f092f9a650b054997180b10c8680d4fb5bc9b6 100755 (executable)
@@ -1,2 +1,2 @@
 python3 -m venv venv
-pip3 install pyang cbor
+pip3 install yangson cbor
diff --git a/yang/json-cbor-yang b/yang/json-cbor-yang
new file mode 100755 (executable)
index 0000000..d34e7e7
--- /dev/null
@@ -0,0 +1,3 @@
+. venv/bin/activate
+python3 json-cbor-yang.py "$@"
+#python3 json2cbor.py "$@"
diff --git a/yang/json-cbor-yang.py b/yang/json-cbor-yang.py
new file mode 100644 (file)
index 0000000..14b0a1b
--- /dev/null
@@ -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")
diff --git a/yang/show_memory.cbor b/yang/show_memory.cbor
new file mode 100644 (file)
index 0000000..f1cfe02
--- /dev/null
@@ -0,0 +1 @@
+¡sshow_memory:message¢fheaderqBIRD memory usagedbody¦nrouting_tables¢ieffective\19\ 1Dhoverhead\180proute_attributes¢ieffective\19\ 1Dhoverhead\180iprotocols¢ieffective\19\ 1Dhoverhead\180ncurrent_config¢ieffective\19\ 1Dhoverhead\180nstandby_memory¢ieffective\19\ 1Dhoverhead\180etotal¢ieffective\19\ 1Dhoverhead\180
\ No newline at end of file
index 93f4e1db92190f3357dce8045935a397f9b2c5a0..fc454ba5f532c93a1b1341ed2da9e9cc1a04e778 100644 (file)
@@ -1,6 +1,6 @@
 module show_memory {
 
-  namespace ".";
+  namespace "https://bird.nic.cz/yang/v2.15/cli-debug";
   
   prefix "memory";
 
diff --git a/yang/yang-library.json b/yang/yang-library.json
new file mode 100644 (file)
index 0000000..fcf43be
--- /dev/null
@@ -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"
+      }
+    ]
+  }
+}