Extract remove action
This commit is contained in:
parent
1c0a7a46d4
commit
58e8b10553
|
@ -0,0 +1,39 @@
|
||||||
|
# SPDX-FileCopyrightText: © 2024 Jip-Hop and the Jailmakers <https://github.com/Jip-Hop/jailmaker>
|
||||||
|
#
|
||||||
|
# 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
|
|
@ -131,38 +131,7 @@ def edit_jail(jail_name):
|
||||||
|
|
||||||
|
|
||||||
from actions.stop import stop_jail
|
from actions.stop import stop_jail
|
||||||
|
from actions.remove import remove_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 utils.jail_dataset import get_all_jail_names, parse_os_release
|
from utils.jail_dataset import get_all_jail_names, parse_os_release
|
||||||
from actions.list import list_jails
|
from actions.list import list_jails
|
||||||
|
|
Loading…
Reference in New Issue