import subprocess def execute(action, node, spec): exec_type = spec.execution # ----------------------------- # DISTCC PATH # ----------------------------- if exec_type == "distcc": return run_distcc(action, node, spec) # ----------------------------- # LXC PATH # ----------------------------- if exec_type == "lxc": return run_lxc(action, node, spec) # ----------------------------- # LIBVIRT PATH # ----------------------------- if exec_type == "libvirt": return run_libvirt(action, node, spec) # ----------------------------- # PODMAN PATH # ----------------------------- if exec_type == "podman": return run_podman(action, node, spec) # ----------------------------- # FIRECRACKER PATH # ----------------------------- if exec_type == "firecracker": return run_firecracker(action, node, spec) # ----------------------------- # TMUX LOCAL PATH # ----------------------------- if exec_type == "tmux": return run_tmux(action, node, spec) raise ValueError(f"Unknown execution type: {exec_type}") def run_distcc(action, node, spec): return subprocess.call(["distcc", action["cmd"]]) def run_lxc(action, node, spec): return subprocess.call(["lxc", "exec", node["container"], "--", action["cmd"]]) def run_libvirt(action, node, spec): return subprocess.call(["virsh", "domexec", node["vm"], action["cmd"]]) def run_podman(action, node, spec): container = node.get("container", "default") return subprocess.call(["podman", "exec", container, "--", "bash", "-c", action["cmd"]]) def run_firecracker(action, node, spec): host = node.get("host", "127.0.0.1") ssh_key = node.get("firecracker", {}).get("ssh_key", "/root/.ssh/fc_builder") ssh_port = node.get("firecracker", {}).get("ssh_port", 2222) cmd = ( f"ssh -i {ssh_key} -p {ssh_port} " f"-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null " f"root@{host} '{action['cmd']}'" ) return subprocess.call(cmd, shell=True) def run_tmux(action, node, spec): return subprocess.call(["tmux", "new", "-d", action["cmd"]])