fester/backend/targets/router.py

29 lines
707 B
Python

from integrations.lxc import LXCManager
from integrations.libvirt import LibvirtManager
class TargetRouter:
def __init__(self):
self.lxc = LXCManager()
self.libvirt = LibvirtManager()
# -----------------------------
# EXECUTION DISPATCH
# -----------------------------
def run(self, target, command):
if target.runtime == "lxc":
return self.lxc.execute(target, command)
if target.runtime == "libvirt":
return self.libvirt.execute(target, command)
# default: host
return self._run_host(command)
def _run_host(self, command):
import subprocess
return subprocess.call(command, shell=True)