Restructured code

This commit is contained in:
Kevin Veen-Birkenbach 2024-01-09 18:25:18 +01:00
parent 4820f2468c
commit 678f0fa999

View File

@ -6,13 +6,6 @@ def run_command(command):
""" Run a shell command and return its output """ """ Run a shell command and return its output """
return subprocess.check_output(command, shell=True).decode('utf-8').strip() return subprocess.check_output(command, shell=True).decode('utf-8').strip()
# Path on the SSD where data will be moved
ssd_path = "/path/to/ssd"
hdd_path = "/path/to/hdd"
# List all Docker volumes
volumes = run_command("docker volume ls -q").splitlines()
def stop_containers(containers): def stop_containers(containers):
"""Stop a list of containers.""" """Stop a list of containers."""
container_list = ' '.join(containers) container_list = ' '.join(containers)
@ -52,6 +45,13 @@ def pause_and_move(storage_path,volume):
start_containers(containers) start_containers(containers)
# Path on the SSD where data will be moved
ssd_path = "/path/to/ssd"
hdd_path = "/path/to/hdd"
# List all Docker volumes
volumes = run_command("docker volume ls -q").splitlines()
for volume in volumes: for volume in volumes:
# List all containers using this volume # List all containers using this volume
containers = run_command(f"docker ps -q --filter volume={volume}").splitlines() containers = run_command(f"docker ps -q --filter volume={volume}").splitlines()