diff --git a/focker.py b/focker.py index a97a760..68a8c32 100644 --- a/focker.py +++ b/focker.py @@ -2,7 +2,8 @@ from argparse import ArgumentParser import yaml import os # from weir import zfs, process -from .image import command_image_build +from .image import command_image_build, \ + command_image_untag import sys from .zfs import zfs_init @@ -17,6 +18,10 @@ def create_parser(): parser.add_argument('focker_dir', type=str) parser.add_argument('--tag', '-t', type=str, nargs='+', default=[]) + parser = subparsers.add_parser('untag') + parser.set_defaults(func=command_image_untag) + parser.add_argument('tags', type=str, nargs='+', default=[]) + return parser_top diff --git a/image.py b/image.py index 2bb2c1c..7eeb4b3 100644 --- a/image.py +++ b/image.py @@ -70,3 +70,6 @@ def command_image_build(args): image, image_sha256 = build(spec) zfs_untag(args.tag) zfs_tag(image.split('@')[0], args.tag) + +def command_image_untag(args): + zfs_untag(args.tags) diff --git a/zfs.py b/zfs.py index f459072..0e38deb 100644 --- a/zfs.py +++ b/zfs.py @@ -72,11 +72,12 @@ def zfs_snapshot_by_sha256(sha256): return lst[0][1] -def zfs_tag(name, tags): +def zfs_tag(name, tags, replace=False): lst = zfs_parse_output(['zfs', 'list', '-o', 'focker:tags', '-H', name]) - tags = list(tags) - tags.extend(lst[0][0].split(' ')) - tags = list(set(tags)) + if not replace: + tags = list(tags) + tags.extend(lst[0][0].split(' ')) + tags = list(set(tags)) if len(tags) > 0: zfs_run(['zfs', 'set', 'focker:tags=' + ' '.join(tags), name]) else: @@ -84,6 +85,7 @@ def zfs_tag(name, tags): def zfs_untag(tags): + # print('zfs_untag(), tags:', tags) lst = zfs_parse_output(['zfs', 'list', '-o', 'name,focker:tags', '-H']) lst = filter(lambda a: any([b in a[1].split(' ') for b in tags]), lst) for row in lst: @@ -91,7 +93,7 @@ def zfs_untag(tags): for t in tags: if t in cur_tags: cur_tags.remove(t) - zfs_tag(row[0], cur_tags) + zfs_tag(row[0], cur_tags, replace=True) def zfs_init():