From: Maria Matejka Date: Wed, 26 Mar 2025 15:45:50 +0000 (+0100) Subject: Start and stop (without the actual machines) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a00bbbbdbefd8f4342d493ce3082c2fcf58d692d;p=thirdparty%2Fbird.git Start and stop (without the actual machines) --- diff --git a/.gitignore b/.gitignore index a50f1fceb..541bfd571 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ /sysdep/autoconf.h.in~ /cscope.* *.tar.gz +__pycache__ diff --git a/.gitmodules b/.gitmodules index 7a85997ee..223358a5e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "tools/flock"] path = tools/flock url = https://gitlab.nic.cz/labs/flock.git +[submodule "tools/bird-tools"] + path = tools/bird-tools + url = https://gitlab.nic.cz/labs/bird-tools.git diff --git a/tools/bird-tools b/tools/bird-tools new file mode 160000 index 000000000..f4b708f2c --- /dev/null +++ b/tools/bird-tools @@ -0,0 +1 @@ +Subproject commit f4b708f2c8c9fab328837461365965d8fdb388da diff --git a/tools/flock b/tools/flock index a40c980d2..b35153094 160000 --- a/tools/flock +++ b/tools/flock @@ -1 +1 @@ -Subproject commit a40c980d24edab795113b1a689f8413cf7432d77 +Subproject commit b351530942724676c3003043712cc9d2c9fd8121 diff --git a/tools/netlabflock/__init__.py b/tools/netlabflock/__init__.py new file mode 100644 index 000000000..2f58f634f --- /dev/null +++ b/tools/netlabflock/__init__.py @@ -0,0 +1,53 @@ +import os +import pathlib +from . import flock + +class NetlabFlock: + toolsdir = pathlib.Path(__file__).parent.parent + netlabdir = toolsdir / "bird-tools" / "netlab" + +if not NetlabFlock.netlabdir.exists(): + raise Exception(f"Netlab dir not found at {NetlabFlock.netlabdir.absolute()}, did you run git submodule update --init?") + +class Suite: + def __init__(self, name: str): + self.name = name + self.dir = NetlabFlock.netlabdir / name + if not self.dir.exists(): + raise Exception(f"Suite dir {self.dir} not found") + + self.rundir = pathlib.Path(os.environ['XDG_RUNTIME_DIR']) / "netlabflock" + + def help(self, *args: str): + print("Usage: python3 -m netlabflock (start|stop|save|check) suitename [targetdir]") + + async def start(self): + print("start", self.targetdir) + flock.create(self.targetdir) + + async def stop(self): + print("stop", self.targetdir) + flock.delete(self.targetdir) + + async def save(self): + ... + + async def check(self): + ... + + async def exec(self, cmd: str, targetdir: str = None): + if targetdir is None: + if not self.rundir.exists(): + self.rundir.mkdir() + + self.targetdir = self.rundir / self.name + else: + self.targetdir = pathlib.Path(targetdir) + + await { + "start": self.start, + "stop": self.stop, + "save": self.save, + "check": self.check, + }[cmd]() + diff --git a/tools/netlabflock/__main__.py b/tools/netlabflock/__main__.py new file mode 100644 index 000000000..d3788f4db --- /dev/null +++ b/tools/netlabflock/__main__.py @@ -0,0 +1,12 @@ +import asyncio +import sys + +from . import Suite + +if __name__ == "__main__": + try: + _, cmd, suite, *args = sys.argv + except ValueError as e: + Suite.help(*sys.argv[1:]) + + asyncio.run(Suite(suite).exec(cmd, *args)) diff --git a/tools/netlabflock/flock.py b/tools/netlabflock/flock.py new file mode 120000 index 000000000..db5577a8a --- /dev/null +++ b/tools/netlabflock/flock.py @@ -0,0 +1 @@ +../flock/cli/flock.py \ No newline at end of file