fester/backend/executor/router.py

49 lines
1.2 KiB
Python

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)
# -----------------------------
# 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", "qemu-agent-command", node["vm"], action["cmd"]])
def run_tmux(action, node, spec):
return subprocess.call(["tmux", "new", "-d", action["cmd"]])