diff --git a/focker.py b/focker.py index c9c477c..3d31467 100644 --- a/focker.py +++ b/focker.py @@ -16,7 +16,9 @@ from .volume import command_volume_create, \ import sys from .zfs import zfs_init from .jail import command_jail_run, \ - command_jail_list + command_jail_list, \ + command_jail_tag, \ + command_jail_untag def create_parser(): @@ -64,6 +66,15 @@ def create_parser(): parser.set_defaults(func=command_jail_list) parser.add_argument('--full-sha256', '-f', action='store_true') + parser = subparsers.add_parser('tag') + parser.set_defaults(func=command_jail_tag) + parser.add_argument('reference', type=str) + parser.add_argument('tags', type=str, nargs='+') + + parser = subparsers.add_parser('untag') + parser.set_defaults(func=command_jail_untag) + parser.add_argument('tags', type=str, nargs='+') + # volume subparsers = subparsers_top.add_parser('volume').add_subparsers() parser = subparsers.add_parser('create') diff --git a/jail.py b/jail.py index 77a89d0..153bddd 100644 --- a/jail.py +++ b/jail.py @@ -85,3 +85,13 @@ def command_jail_list(args): a[2], jails[a[2]]['jid'] if a[2] in jails else '-' ], lst)) print(tabulate(lst, headers=['Tags', 'SHA256', 'mountpoint', 'JID'])) + + +def command_jail_tag(args): + name, _ = zfs_find(args.reference, focker_type='jail') + zfs_untag(args.tags, focker_type='jail') + zfs_tag(name, args.tags) + + +def command_jail_untag(args): + zfs_untag(args.tags, focker_type='jail') diff --git a/zfs.py b/zfs.py index a34401c..edec7d0 100644 --- a/zfs.py +++ b/zfs.py @@ -131,9 +131,10 @@ def zfs_tag(name, tags, replace=False): zfs_run(['zfs', 'inherit', 'focker:tags', name]) -def zfs_untag(tags): +def zfs_untag(tags, focker_type='image'): # print('zfs_untag(), tags:', tags) - lst = zfs_parse_output(['zfs', 'list', '-o', 'name,focker:tags', '-H']) + poolname = zfs_poolname() + lst = zfs_parse_output(['zfs', 'list', '-o', 'name,focker:tags', '-H', '-r', poolname + '/focker/' + focker_type + 's']) lst = filter(lambda a: any([b in a[1].split(' ') for b in tags]), lst) for row in lst: cur_tags = row[1].split(' ')