From a503ad16c0e39b0ce05ff621c90ce5302f238941 Mon Sep 17 00:00:00 2001 From: Mathieu Broillet Date: Thu, 22 Jun 2023 16:15:52 +0200 Subject: [PATCH] configured mutli-threading and fixed lxc detection for steps --- src/main.py | 13 +++++++++---- src/utils/steps_utils.py | 8 ++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main.py b/src/main.py index 3da7653..1e52987 100644 --- a/src/main.py +++ b/src/main.py @@ -1,4 +1,5 @@ import logging +import threading from pathlib import Path from .lxc.lxc_utils import load_lxc, get_all_lxcs @@ -44,7 +45,11 @@ def run(args): load_lxc(content=lxc_file_content, lxc_id=int(lxc_folder), pve=pve) for lxc in get_all_lxcs(): - logging.info(f"Loading LXC {lxc.id}") - lxc.create() - lxc.start() - lxc.run_creation() + threading.Thread(target=launch_lxc, args=(lxc,)).start() + + +def launch_lxc(lxc): + logging.info(f"Loading LXC {lxc.id}") + lxc.create() + lxc.start() + lxc.run_creation() diff --git a/src/utils/steps_utils.py b/src/utils/steps_utils.py index 6a34723..2aa25f6 100644 --- a/src/utils/steps_utils.py +++ b/src/utils/steps_utils.py @@ -11,14 +11,14 @@ from ..machine.machine import LinuxMachine from ..utils import conditions_utils if TYPE_CHECKING: - from ..lxc.lxc import LXC + pass def _run_script_step(linux_machine, step): - if isinstance(linux_machine, LXC): + if "LXC" in str(linux_machine.__class__): lxc_utils.run_script_step_parser(linux_machine, step) else: - logging.warning(f"Script step only supported on LXCs") + logging.warning("Script step only supported on LXCs") pass @@ -27,7 +27,7 @@ def _run_file_create_step(linux_machine, step): def _run_file_copy_step(linux_machine, step): - if isinstance(linux_machine, LXC): + if "LXC" in str(linux_machine.__class__): linux_machine.pve.copy_file_to_lxc(linux_machine, get_path(linux_machine, step["path"]), step["destination"], step.get("permission", 644), step.get("owner", "root")) else: