]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Start and stop (without the actual machines)
authorMaria Matejka <mq@ucw.cz>
Wed, 26 Mar 2025 15:45:50 +0000 (16:45 +0100)
committerMaria Matejka <mq@ucw.cz>
Wed, 26 Mar 2025 15:45:50 +0000 (16:45 +0100)
.gitignore
.gitmodules
tools/bird-tools [new submodule]
tools/flock
tools/netlabflock/__init__.py [new file with mode: 0644]
tools/netlabflock/__main__.py [new file with mode: 0644]
tools/netlabflock/flock.py [new symlink]

index a50f1fceb2ab049f37e02da89cfa171472f4c55f..541bfd571c3d9900feac394cde50e2c1eb58ab3f 100644 (file)
@@ -14,3 +14,4 @@
 /sysdep/autoconf.h.in~
 /cscope.*
 *.tar.gz
+__pycache__
index 7a85997ee6d43c28c11e67bd7bf06ed9806aa7fc..223358a5eb0ceb665201798ca8542a563ec3cdc8 100644 (file)
@@ -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 (submodule)
index 0000000..f4b708f
--- /dev/null
@@ -0,0 +1 @@
+Subproject commit f4b708f2c8c9fab328837461365965d8fdb388da
index a40c980d24edab795113b1a689f8413cf7432d77..b351530942724676c3003043712cc9d2c9fd8121 160000 (submodule)
@@ -1 +1 @@
-Subproject commit a40c980d24edab795113b1a689f8413cf7432d77
+Subproject commit b351530942724676c3003043712cc9d2c9fd8121
diff --git a/tools/netlabflock/__init__.py b/tools/netlabflock/__init__.py
new file mode 100644 (file)
index 0000000..2f58f63
--- /dev/null
@@ -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 (file)
index 0000000..d3788f4
--- /dev/null
@@ -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 (symlink)
index 0000000..db5577a
--- /dev/null
@@ -0,0 +1 @@
+../flock/cli/flock.py
\ No newline at end of file