@@ -16,7 +16,9 @@ from .volume import command_volume_create, \ | |||||
import sys | import sys | ||||
from .zfs import zfs_init | from .zfs import zfs_init | ||||
from .jail import command_jail_run, \ | from .jail import command_jail_run, \ | ||||
command_jail_list | |||||
command_jail_list, \ | |||||
command_jail_tag, \ | |||||
command_jail_untag | |||||
def create_parser(): | def create_parser(): | ||||
@@ -64,6 +66,15 @@ def create_parser(): | |||||
parser.set_defaults(func=command_jail_list) | parser.set_defaults(func=command_jail_list) | ||||
parser.add_argument('--full-sha256', '-f', action='store_true') | 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 | # volume | ||||
subparsers = subparsers_top.add_parser('volume').add_subparsers() | subparsers = subparsers_top.add_parser('volume').add_subparsers() | ||||
parser = subparsers.add_parser('create') | parser = subparsers.add_parser('create') | ||||
@@ -85,3 +85,13 @@ def command_jail_list(args): | |||||
a[2], | a[2], | ||||
jails[a[2]]['jid'] if a[2] in jails else '-' ], lst)) | jails[a[2]]['jid'] if a[2] in jails else '-' ], lst)) | ||||
print(tabulate(lst, headers=['Tags', 'SHA256', 'mountpoint', 'JID'])) | 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') |
@@ -131,9 +131,10 @@ def zfs_tag(name, tags, replace=False): | |||||
zfs_run(['zfs', 'inherit', 'focker:tags', name]) | zfs_run(['zfs', 'inherit', 'focker:tags', name]) | ||||
def zfs_untag(tags): | |||||
def zfs_untag(tags, focker_type='image'): | |||||
# print('zfs_untag(), tags:', tags) | # 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) | lst = filter(lambda a: any([b in a[1].split(' ') for b in tags]), lst) | ||||
for row in lst: | for row in lst: | ||||
cur_tags = row[1].split(' ') | cur_tags = row[1].split(' ') | ||||