From 03c65b1e5bd43ae9b3c874a6cc22163a7918f00f Mon Sep 17 00:00:00 2001 From: Todd Gill Date: Tue, 5 Dec 2023 10:20:28 -0500 Subject: [PATCH] remove util.py currently the code is in the snapshot.py file. Issue opened: https://github.com/linux-system-roles/snapshot/issues/5 Signed-off-by: Todd Gill --- module_utils/snapshot/util.py | 101 ---------------------------------- 1 file changed, 101 deletions(-) delete mode 100644 module_utils/snapshot/util.py diff --git a/module_utils/snapshot/util.py b/module_utils/snapshot/util.py deleted file mode 100644 index dac1e13..0000000 --- a/module_utils/snapshot/util.py +++ /dev/null @@ -1,101 +0,0 @@ -import errno -import os -import subprocess -import logging - - -class LvmBug(RuntimeError): - """ - Things that are clearly a bug with lvm itself. - """ - - def __init__(self, msg): - super().__init__(msg) - - def __str__(self): - return "lvm bug encountered: %s" % " ".join(self.args) - - -class SnapshotStatus: - SNAPSHOT_OK = 0 - ERROR_INSUFFICENT_SPACE = 1 - ERROR_ALREADY_DONE = 2 - ERROR_SNAPSHOT_FAILED = 3 - ERROR_REMOVE_FAILED = 4 - ERROR_REMOVE_FAILED_NOT_SNAPSHOT = 5 - ERROR_LVS_FAILED = 6 - ERROR_NAME_TOO_LONG = 7 - ERROR_ALREADY_EXISTS = 8 - ERROR_NAME_CONFLICT = 9 - ERROR_VG_NOTFOUND = 10 - ERROR_LV_NOTFOUND = 11 - - -# what percentage is part of whole -def percentage(part, whole): - return 100 * float(part) / float(whole) - - -# what is number is percent of whole -def percentof(percent, whole): - return float(whole) / 100 * float(percent) - - -def set_up_logging(log_dir="/tmp", log_prefix="snapshot_role"): - logger.setLevel(logging.DEBUG) - - def make_handler(path, prefix, level): - log_file = "%s/%s.log" % (path, prefix) - log_file = os.path.realpath(log_file) - handler = logging.FileHandler(log_file) - handler.setLevel(level) - formatter = logging.Formatter( - "%(asctime)s %(levelname)s %(name)s/%(threadName)s: %(message)s" - ) - handler.setFormatter(formatter) - return handler - - handler = make_handler(log_dir, log_prefix, logging.DEBUG) - stdout_handler = logging.StreamHandler(stream=sys.stdout) - - logger.addHandler(handler) - logger.addHandler(stdout_handler) - - -def run_command(argv, stdin=None): - logger.info("Running... %s", " ".join(argv)) - - try: - proc = subprocess.Popen( - argv, stdin=stdin, stdout=subprocess.PIPE, close_fds=True - ) - - out, err = proc.communicate() - - out = out.decode("utf-8") - - except OSError as e: - print("Error running %s: %s", argv[0], e.strerror) - raise - - logger.info("Return code: %d", proc.returncode) - for line in out.splitlines(): - logger.info("%s", line) - - return (proc.returncode, out) - - -def check_positive(value): - try: - value = int(value) - if value <= 0: - raise argparse.ArgumentTypeError( - "{} is not a positive integer".format(value) - ) - except ValueError: - raise Exception("{} is not an integer".format(value)) - return value - - -def round_up(value, multiple): - return value + (multiple - (value % multiple))