2024-07-18 21:34:07 +00:00
|
|
|
from . import ShowRoute
|
|
|
|
|
2024-07-10 13:41:20 +00:00
|
|
|
class Transport:
|
|
|
|
pass
|
|
|
|
|
|
|
|
class CLI:
|
|
|
|
def __init__(self, transport: Transport):
|
|
|
|
self.transport = transport
|
|
|
|
|
|
|
|
async def down(self):
|
|
|
|
return await self.transport.send_cmd("down")
|
2024-07-11 13:29:28 +00:00
|
|
|
|
|
|
|
async def enable(self, proto: str):
|
|
|
|
return await self.transport.send_cmd("enable", proto)
|
|
|
|
|
|
|
|
async def disable(self, proto: str):
|
|
|
|
return await self.transport.send_cmd("disable", proto)
|
|
|
|
|
2024-07-19 17:28:19 +00:00
|
|
|
async def show_route(self, table=["all"], args=[]):
|
2024-07-11 13:29:28 +00:00
|
|
|
cmd = [ "show", "route" ]
|
|
|
|
for t in table:
|
|
|
|
cmd.append("table")
|
|
|
|
cmd.append(t)
|
|
|
|
|
2024-07-19 17:28:19 +00:00
|
|
|
cmd += args
|
|
|
|
|
2024-07-18 21:34:07 +00:00
|
|
|
result = await self.transport.send_cmd(*cmd)
|
|
|
|
if len(result["err"]):
|
|
|
|
raise Exception(f"Command {cmd} returned {result['err'].decode()}, stdout={result['out'].decode()}")
|
|
|
|
|
|
|
|
return ShowRoute.parse(result["out"].decode())
|