From a65932377961c5910032e6be4681edf5ccb8f5ba Mon Sep 17 00:00:00 2001 From: Mathieu Broillet Date: Tue, 20 Jun 2023 10:25:02 +0200 Subject: [PATCH] check if there is conditions for the creation or not and added support for running multiples commands at once --- src/lxc/creation_utils.py | 11 ++++++----- src/lxc/lxc.py | 7 +++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/lxc/creation_utils.py b/src/lxc/creation_utils.py index 6f7a657..1df181b 100644 --- a/src/lxc/creation_utils.py +++ b/src/lxc/creation_utils.py @@ -44,14 +44,15 @@ def are_all_conditions_met(lxc: LXC): # result.append(lxc.run_command("which " + program, return_status_code=True) == 0) creation = lxc.get_creation() - global_conditions = creation["conditions"] steps = creation["steps"] - result = [] - # Check the global conditions - for condition_type in global_conditions: - result = check_conditions(c_type=condition_type, parent=global_conditions, lxc=lxc, result=result) + if 'conditions' in creation: + global_conditions = creation["conditions"] + + # Check the global conditions + for condition_type in global_conditions: + result = check_conditions(c_type=condition_type, parent=global_conditions, lxc=lxc, result=result) # Check the specific conditions for each step for step in steps: diff --git a/src/lxc/lxc.py b/src/lxc/lxc.py index af1518c..5a9119c 100644 --- a/src/lxc/lxc.py +++ b/src/lxc/lxc.py @@ -386,6 +386,13 @@ class LXC(LinuxMachine): # logging.debug(f"Running command {command} on LXC {self.lxc_id}") + if type(command) == list: + for cmd in command: + self.run_command(command=cmd, return_status_code=return_status_code, + exception_on_exit=exception_on_exit, + exception_on_empty_stdout=exception_on_empty_stdout, + working_directory=working_directory, use_ssh=use_ssh) + if working_directory: command = f"cd {working_directory} && {command}"