From ee2fcd0eb1812368407df22c0b3cf000a8c6a940 Mon Sep 17 00:00:00 2001 From: Stanislaw Adaszewski Date: Mon, 27 Apr 2020 10:30:08 +0200 Subject: [PATCH] Added -f switch in focker jail prune --- focker.py | 2 ++ jail.py | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/focker.py b/focker.py index ac98c38..6ee936f 100644 --- a/focker.py +++ b/focker.py @@ -65,6 +65,7 @@ def create_parser(): parser.add_argument('--tags', '-t', type=str, nargs='+', default=[]) parser.add_argument('--env', '-e', type=str, nargs='+', default=[]) parser.add_argument('--mounts', '-m', type=str, nargs='+', default=[]) + parser.add_argument('--hostname', '-n', type=str) parser = subparsers.add_parser('run') parser.set_defaults(func=command_jail_run) @@ -87,6 +88,7 @@ def create_parser(): parser = subparsers.add_parser('prune') parser.set_defaults(func=command_jail_prune) + parser.add_argument('--force', '-f', action='store_true') # volume subparsers = subparsers_top.add_parser('volume').add_subparsers() diff --git a/jail.py b/jail.py index fc1f40a..cec9ee4 100644 --- a/jail.py +++ b/jail.py @@ -17,7 +17,7 @@ def gen_env_command(command, env): return command -def jail_create(path, command, env, mounts, hostname): +def jail_create(path, command, env, mounts, hostname=None): name = os.path.split(path)[-1] if os.path.exists('/etc/jail.conf'): conf = jailconf.load('/etc/jail.conf') @@ -159,7 +159,8 @@ def command_jail_create(args): { a.split(':')[0]: ':'.join(a.split(':')[1:]) \ for a in args.env }, [ [a.split(':')[0], ':'.join(a.split(':')[1:])] \ - for a in args.mounts ] ) + for a in args.mounts ], + args.hostname ) print(sha256) print(path) @@ -213,5 +214,5 @@ def command_jail_prune(args): used.add(j['path']) lst = zfs_list(fields=['focker:sha256,focker:tags,mountpoint,name'], focker_type='jail') for j in lst: - if j[1] == '-' and j[2] not in used: + if j[1] == '-' and (j[2] not in used or args.force): jail_remove(j[2])