From 7971d367d6f8444052aeb152db8202ac90fa167b Mon Sep 17 00:00:00 2001 From: mariam1br Date: Mon, 10 Feb 2025 14:19:54 -0700 Subject: [PATCH] Added diskspace task to check remaining disk space on host system --- src/tasks.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/tasks.py b/src/tasks.py index b993590..9332273 100644 --- a/src/tasks.py +++ b/src/tasks.py @@ -189,3 +189,24 @@ def dockertest(c, verbose=0): pprint(client.swarm.attrs) client.close() + +@task(incrementable=["verbose"]) +def diskspace(c, verbose=0): + """Check disk space on host system""" + _set_log_level(verbose) + + logger.debug("Checking disk space...") + + # Use invoke to run df command + result = c.run("df -h /", hide=True) + + # Parse and print the output + lines = result.stdout.strip().split("\n") + headers = lines[0].split() + values = lines[1].split() + + print("-" * 40) + for header, value in zip(headers, values): + print(f"{header:<15}: {value}") + print("-" * 40) +