From 609cc0ef246d0eddf18ed397f4145e25881b17e2 Mon Sep 17 00:00:00 2001 From: Mathieu Broillet Date: Thu, 15 Jun 2023 17:13:34 +0200 Subject: [PATCH] started new script running system --- src/lxc/creation_utils.py | 6 +++--- src/lxc/lxc_utils.py | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/lxc/creation_utils.py b/src/lxc/creation_utils.py index 051950a..28442b1 100644 --- a/src/lxc/creation_utils.py +++ b/src/lxc/creation_utils.py @@ -4,7 +4,7 @@ import logging from pathlib import Path from typing import TYPE_CHECKING -from ..utils import commands_utils +from . import lxc_utils from ..utils.resources_utils import get_path if TYPE_CHECKING: @@ -174,9 +174,9 @@ def run_steps(lxc: LXC): # Support for scripts case "script": - commands_utils.run_script(lxc, step) + lxc_utils.run_script_parser(lxc, step) case "file_create": - commands_utils.create_file_in_lxc(lxc, step["path"], optional(step["permission"], 644)) + lxc.create_file(step["path"], optional(step["permission"], 644)) case "file_copy": commands_utils.copy_local_file_to_lxc(lxc, get_path(lxc, step["path"]), step["destination"]) case "folder": diff --git a/src/lxc/lxc_utils.py b/src/lxc/lxc_utils.py index 797feff..a9fd7da 100644 --- a/src/lxc/lxc_utils.py +++ b/src/lxc/lxc_utils.py @@ -117,3 +117,24 @@ def generate_pct_command_for_lxc(lxc: LXC, create: bool = True): # TODO: add gateway4 # f"ip6={self.ipv6},gw6={self.gateway6},trunks={self.vlan} " \ # TODO return pct_command + + +def run_script_parser(lxc: LXC, step: dict): + # Install bash if not installed + # Sometimes only ash or sh are installed, which doesn't work for some scripts + if not lxc.has_program("bash"): + lxc.install_package("bash") + + # # Run local script + # if "path" in step: + # path = get_path(lxc, step["local_path"]) + # _run_local_script_on_lxc(lxc, path) + # + # # Run remote script + # elif "url" in step: + # _run_remote_script_on_lxc(lxc, step["url"]) + # + # # Run script in LXC + # elif "lxc_path" in step: + # path = get_path(lxc, step["lxc_path"]) + # _run_script_on_lxc(lxc, path)