From 7e9a5a44af605619f66ab537f02220ffc87aeedf Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Thu, 11 Jul 2024 15:29:28 +0200 Subject: [PATCH] CLI module: sending enable, disable and show route No parsing yet --- flock/bgp-secondary/test.py | 14 +++++++------- flock/lib/BIRD/CLI.py | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/flock/bgp-secondary/test.py b/flock/bgp-secondary/test.py index 1979d98e..ba97b1d4 100644 --- a/flock/bgp-secondary/test.py +++ b/flock/bgp-secondary/test.py @@ -97,19 +97,19 @@ async def main(): dest_cli = CLI(MinimalistTransport(h.control_socket, "dest")) print(await asyncio.gather(*[ - h.control_socket.send_cmd("run_in", where, "./birdc", "-l", "show", "route", "table", "all") - for where in ("src", "dest") + where.show_route() + for where in (src_cli, dest_cli) ])) await asyncio.sleep(1) for p in ("p170", "p180", "p190", "p200"): - print(await h.control_socket.send_cmd("run_in", "src", "./birdc", "-l", "enable", p)) + await src_cli.enable(p) await asyncio.sleep(1) shr = await asyncio.gather(*[ - h.control_socket.send_cmd("run_in", where, "./birdc", "-l", "show", "route", "table", "all") - for where in ("src", "dest") + where.show_route() + for where in (src_cli, dest_cli) ]) print(shr[0]["out"].decode(), shr[1]["out"].decode()) @@ -117,8 +117,8 @@ async def main(): await asyncio.sleep(1) print(await asyncio.gather(*[ - h.control_socket.send_cmd("run_in", where, "./birdc", "-l", "show", "route", "table", "all") - for where in ("src", "dest") + where.show_route() + for where in (src_cli, dest_cli) ])) print(await asyncio.gather(*[ diff --git a/flock/lib/BIRD/CLI.py b/flock/lib/BIRD/CLI.py index dce64c6d..d4695391 100644 --- a/flock/lib/BIRD/CLI.py +++ b/flock/lib/BIRD/CLI.py @@ -7,3 +7,17 @@ class CLI: async def down(self): return await self.transport.send_cmd("down") + + 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) + + async def show_route(self, table=["all"]): + cmd = [ "show", "route" ] + for t in table: + cmd.append("table") + cmd.append(t) + + return await self.transport.send_cmd(*cmd)