2023-04-03 15:52:03 +00:00
|
|
|
import asyncio
|
2023-05-20 09:12:00 +00:00
|
|
|
from BIRD.Basic import Basic, Code
|
2023-04-03 15:52:03 +00:00
|
|
|
|
|
|
|
class StatusException(Exception):
|
|
|
|
def __init__(self, msg):
|
|
|
|
Exception.__init__(self, "Failed to parse status: " + msg)
|
|
|
|
|
|
|
|
class Status(Basic):
|
|
|
|
async def update(self):
|
|
|
|
self.data = {}
|
|
|
|
|
|
|
|
await self.bird.cli.open()
|
|
|
|
data = await self.bird.cli.socket.command("show status")
|
|
|
|
|
2023-05-20 09:12:00 +00:00
|
|
|
if data[0]["code"] != Code.Version:
|
2023-04-03 15:52:03 +00:00
|
|
|
raise StatusException(f"BIRD version not on the first line, got {data[0]['code']}")
|
2023-05-20 13:16:34 +00:00
|
|
|
|
2023-04-03 15:52:03 +00:00
|
|
|
self.data["version"] = data[0]["data"]
|
|
|
|
|
2023-05-20 09:12:00 +00:00
|
|
|
if data[-1]["code"] != Code.Status:
|
2023-04-03 15:52:03 +00:00
|
|
|
raise StatusException(f"BIRD status not on the last line, got {data[-1]['code']}")
|
|
|
|
|
|
|
|
self.data["status"] = data[-1]["data"]
|
|
|
|
|
|
|
|
# for d in data[1:-1]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class VersionException(Exception):
|
|
|
|
def __init__(self, msg):
|
|
|
|
Exception.__init__(self, "Failed to parse version from socket hello: " + msg)
|
|
|
|
|
|
|
|
class Version(Basic):
|
|
|
|
async def update(self):
|
|
|
|
await self.bird.cli.open()
|
|
|
|
hello = self.bird.cli.hello
|
|
|
|
|
2023-05-20 09:12:00 +00:00
|
|
|
if hello["code"] != Code.Welcome:
|
2023-04-03 15:52:03 +00:00
|
|
|
raise VersionException(f"code is {hello['code']}, should be 1")
|
|
|
|
|
|
|
|
s = hello["data"].split(" ")
|
|
|
|
if len(s) != 3 or s[2] != "ready.":
|
|
|
|
raise VersionException(f"malformed hello: {hello['data']}")
|
|
|
|
|
|
|
|
self.data = {
|
|
|
|
"name": s[0],
|
|
|
|
"version": s[1],
|
|
|
|
}
|