32 lines
671 B
Python
32 lines
671 B
Python
from executor.adapters import run_host, run_lxc, run_libvirt
|
|
|
|
|
|
def pick_runtime(action, node_role):
|
|
"""
|
|
Decide execution backend based on action + node role
|
|
"""
|
|
|
|
runtime = action.get("runtime", "host")
|
|
|
|
if runtime == "lxc":
|
|
return "lxc"
|
|
|
|
if runtime == "vm":
|
|
return "libvirt"
|
|
|
|
return "host"
|
|
|
|
|
|
def execute_action(action, workspace, node):
|
|
runtime = pick_runtime(action, node.get("role", {}))
|
|
|
|
command = action["command"]
|
|
|
|
if runtime == "lxc":
|
|
return run_lxc(node["container"], command)
|
|
|
|
if runtime == "libvirt":
|
|
return run_libvirt(node["vm"], command)
|
|
|
|
return run_host(command, workspace, {})
|