]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Python CLI Package: Use CLI code names instead of numbers
authorMaria Matejka <mq@ucw.cz>
Sat, 20 May 2023 09:12:00 +0000 (11:12 +0200)
committerMaria Matejka <mq@ucw.cz>
Tue, 23 May 2023 11:44:48 +0000 (13:44 +0200)
python/BIRD/Basic.py
python/BIRD/Status.py

index 73cbd03f29d59d5691139fcabc5889cf880e4a23..413da117eefb640a65c61f0872980834f0082f8b 100644 (file)
@@ -23,3 +23,9 @@ class Basic:
     async def load(self):
         if self.data is None:
             await self.update()
+
+class Code:
+    OK = 0
+    Welcome = 1
+    Status = 13
+    Version = 1000
index 5d24da1ddadbe27c8419d7f75986822d50fb5a6e..0ee8d8d6819b854395d2cc1ac7f86ca77d8eaa51 100644 (file)
@@ -1,5 +1,5 @@
 import asyncio
-from BIRD.Basic import Basic
+from BIRD.Basic import Basic, Code
 
 class StatusException(Exception):
     def __init__(self, msg):
@@ -12,12 +12,12 @@ class Status(Basic):
         await self.bird.cli.open()
         data = await self.bird.cli.socket.command("show status")
 
-        if data[0]["code"] != 1000:
+        if data[0]["code"] != Code.Version:
             raise StatusException(f"BIRD version not on the first line, got {data[0]['code']}")
         
         self.data["version"] = data[0]["data"]
 
-        if data[-1]["code"] != 13:
+        if data[-1]["code"] != Code.Status:
             raise StatusException(f"BIRD status not on the last line, got {data[-1]['code']}")
 
         self.data["status"] = data[-1]["data"]
@@ -35,7 +35,7 @@ class Version(Basic):
         await self.bird.cli.open()
         hello = self.bird.cli.hello
 
-        if hello["code"] != 1:
+        if hello["code"] != Code.Welcome:
             raise VersionException(f"code is {hello['code']}, should be 1")
 
         s = hello["data"].split(" ")