add move step support and fix some steps names
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Mathieu Broillet 2023-06-23 10:17:29 +02:00
parent 6ae2d4ded1
commit e692c4df18
No known key found for this signature in database
GPG Key ID: 7D4F25BC50A0AA32
2 changed files with 32 additions and 0 deletions

View File

@ -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")

View File

@ -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']}")