From 58e8b10553062a8ec26bd27464c1a909aeebb414 Mon Sep 17 00:00:00 2001 From: jonct <2807816+jonct@users.noreply.github.com> Date: Mon, 15 Jul 2024 03:43:47 -0400 Subject: [PATCH] Extract remove action --- src/jlmkr/actions/remove.py | 39 +++++++++++++++++++++++++++++++++++++ src/jlmkr/donor/jlmkr.py | 33 +------------------------------ 2 files changed, 40 insertions(+), 32 deletions(-) create mode 100644 src/jlmkr/actions/remove.py diff --git a/src/jlmkr/actions/remove.py b/src/jlmkr/actions/remove.py new file mode 100644 index 0000000..0cf2673 --- /dev/null +++ b/src/jlmkr/actions/remove.py @@ -0,0 +1,39 @@ +# SPDX-FileCopyrightText: © 2024 Jip-Hop and the Jailmakers +# +# SPDX-License-Identifier: LGPL-3.0-only + +from actions.stop import stop_jail +from utils.jail_dataset import check_jail_name_valid, check_jail_name_available +from utils.jail_dataset import get_jail_path, cleanup +from utils.console import eprint + + +def remove_jail(jail_name): + """ + Remove jail with given name. + """ + + if not check_jail_name_valid(jail_name): + return 1 + + if check_jail_name_available(jail_name, False): + eprint(f"A jail with name {jail_name} does not exist.") + return 1 + + # TODO: print which dataset is about to be removed before the user confirmation + # TODO: print that all zfs snapshots will be removed if jail has it's own zfs dataset + check = input(f'\nCAUTION: Type "{jail_name}" to confirm jail deletion!\n\n') + + if check == jail_name: + print() + jail_path = get_jail_path(jail_name) + returncode = stop_jail(jail_name) + if returncode != 0: + return returncode + + print() + cleanup(jail_path) + return 0 + else: + eprint("Wrong name, nothing happened.") + return 1 diff --git a/src/jlmkr/donor/jlmkr.py b/src/jlmkr/donor/jlmkr.py index 7d419df..ff6163f 100755 --- a/src/jlmkr/donor/jlmkr.py +++ b/src/jlmkr/donor/jlmkr.py @@ -131,38 +131,7 @@ def edit_jail(jail_name): from actions.stop import stop_jail - - -def remove_jail(jail_name): - """ - Remove jail with given name. - """ - - if not check_jail_name_valid(jail_name): - return 1 - - if check_jail_name_available(jail_name, False): - eprint(f"A jail with name {jail_name} does not exist.") - return 1 - - # TODO: print which dataset is about to be removed before the user confirmation - # TODO: print that all zfs snapshots will be removed if jail has it's own zfs dataset - check = input(f'\nCAUTION: Type "{jail_name}" to confirm jail deletion!\n\n') - - if check == jail_name: - print() - jail_path = get_jail_path(jail_name) - returncode = stop_jail(jail_name) - if returncode != 0: - return returncode - - print() - cleanup(jail_path) - return 0 - else: - eprint("Wrong name, nothing happened.") - return 1 - +from actions.remove import remove_jail from utils.jail_dataset import get_all_jail_names, parse_os_release from actions.list import list_jails