From 43114d8c1fa0a6f342e8e72d2e6a2ba28ae7247b Mon Sep 17 00:00:00 2001 From: jmsgrogan Date: Fri, 29 Mar 2024 12:18:29 +0000 Subject: [PATCH] Fix container and add dry run ability. --- .gitignore | 0 Containerfile | 2 +- machine_admin/util.py | 11 ++++++++++- machine_setup.py | 3 +++ 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/Containerfile b/Containerfile index 550a199..417485d 100644 --- a/Containerfile +++ b/Containerfile @@ -1,4 +1,4 @@ FROM debian -COPY machine_admin / +COPY machine_admin /machine_admin COPY machine_setup.py / diff --git a/machine_admin/util.py b/machine_admin/util.py index 2fef7c7..7ae006e 100644 --- a/machine_admin/util.py +++ b/machine_admin/util.py @@ -1,4 +1,13 @@ import subprocess +import logging + +_DRY_RUN = False + +def set_is_dry_run(is_dry_run: bool): + _DRY_RUN = is_dry_run def run_op(op: str): - return subprocess.run(op, shell=True) \ No newline at end of file + if _DRY_RUN: + return subprocess.run(op, shell=True) + else: + logging.info(f"Dry Run | {op}") \ No newline at end of file diff --git a/machine_setup.py b/machine_setup.py index 57e2071..50bbbd4 100644 --- a/machine_setup.py +++ b/machine_setup.py @@ -12,6 +12,9 @@ if __name__ == "__main__": parser.add_argument('--username', help="Name of the default non-root user") + parser.add_argument('--dry_run', + help="If set then don't change the system state - used for testing.", + default = False) args = parser.parse_args()