From e692c4df184c660e8b71cd21224db4e0a271cc77 Mon Sep 17 00:00:00 2001 From: Mathieu Broillet Date: Fri, 23 Jun 2023 10:17:29 +0200 Subject: [PATCH] add move step support and fix some steps names --- src/machine/machine.py | 24 ++++++++++++++++++++++++ src/utils/steps_utils.py | 8 ++++++++ 2 files changed, 32 insertions(+) diff --git a/src/machine/machine.py b/src/machine/machine.py index b5c2996..cdddf27 100644 --- a/src/machine/machine.py +++ b/src/machine/machine.py @@ -344,3 +344,27 @@ class LinuxMachine: def disable_service(self, service: str): self.run_command(machine_utils.get_services_command(self.get_os_name(), "disable", service), return_status_code=True) + + def move(self, source, destination, permission: int = None, owner: str = "root"): + self.run_command(f"mv {source} {destination}", return_status_code=True) + + if permission is not None: + if "LXC" in str(self.__class__): + if self.pve.connection.sftp().is_remote_dir(source): + permission = 755 + self.run_command(f"chmod -R {permission} {destination}", return_status_code=True) + else: + permission = 644 + self.run_command(f"chmod {permission} {destination}", return_status_code=True) + else: + raise NotImplementedError("Permission setting is only supported for LXC machines") + + if owner != "root": + if "LXC" in str(self.__class__): + if self.pve.connection.sftp().is_remote_dir(source): + self.run_command(f"chown -R {owner} {destination}", return_status_code=True) + else: + self.run_command(f"chown {owner} {destination}", return_status_code=True) + else: + raise NotImplementedError("Owner setting is only supported for LXC machines") + diff --git a/src/utils/steps_utils.py b/src/utils/steps_utils.py index 4d06fe2..a2fbd26 100644 --- a/src/utils/steps_utils.py +++ b/src/utils/steps_utils.py @@ -47,6 +47,10 @@ def _run_folder_copy_step(linux_machine, step): logging.warning(f"Folder copy step only supported on LXCs") +def _run_move_step(linux_machine, step): + linux_machine.move(step["source"], step["destination"], step.get("permission", None), step.get("owner", "root")) + + def _run_command_step(linux_machine, step): linux_machine.run_command(command=step["command"], working_directory=step.get("workdir"), return_status_code=True) @@ -148,6 +152,8 @@ def run_steps(linux_machine: LinuxMachine, steps: dict): _run_folder_create_step(linux_machine, step) case "folder_copy": _run_folder_copy_step(linux_machine, step) + case "move": + _run_move_step(linux_machine, step) case "command": _run_command_step(linux_machine, step) case "docker": @@ -186,3 +192,5 @@ def run_steps(linux_machine: LinuxMachine, steps: dict): _run_unzip_step(linux_machine, step) case "wait": _run_wait_step(step) + case _: + logging.warning(f"Unknown step type {step['type']}")