From 5b34b99c9e70931147ce2d2fd604f7c6f4a22f0c Mon Sep 17 00:00:00 2001 From: Stanislaw Adaszewski Date: Fri, 24 Apr 2020 21:39:48 +0200 Subject: [PATCH] Added focker volume create. --- focker.py | 4 ++-- image.py | 4 ++-- misc.py | 4 ++++ volume.py | 13 ++++++++++++- 4 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 misc.py diff --git a/focker.py b/focker.py index 9b645ee..767f5af 100644 --- a/focker.py +++ b/focker.py @@ -27,7 +27,7 @@ def create_parser(): parser = subparsers.add_parser('build') parser.set_defaults(func=command_image_build) parser.add_argument('focker_dir', type=str) - parser.add_argument('--tag', '-t', type=str, nargs='+', default=[]) + parser.add_argument('--tags', '-t', type=str, nargs='+', default=[]) parser = subparsers.add_parser('tag') parser.set_defaults(func=command_image_tag) @@ -62,7 +62,7 @@ def create_parser(): subparsers = subparsers_top.add_parser('volume').add_subparsers() parser = subparsers.add_parser('create') parser.set_defaults(func=command_volume_create) - parser.add_argument('--tag', '-t', type=str, nargs='+', default=[]) + parser.add_argument('--tags', '-t', type=str, nargs='+', default=[]) parser = subparsers.add_parser('prune') parser.set_defaults(func=command_volume_prune) diff --git a/image.py b/image.py index b3067c9..2de9353 100644 --- a/image.py +++ b/image.py @@ -74,8 +74,8 @@ def command_image_build(args): spec = yaml.safe_load(f) print('spec:', spec) image, image_sha256 = build(spec, args) - zfs_untag(args.tag) - zfs_tag(image.split('@')[0], args.tag) + zfs_untag(args.tags) + zfs_tag(image.split('@')[0], args.tags) def command_image_tag(args): diff --git a/misc.py b/misc.py new file mode 100644 index 0000000..f789ad7 --- /dev/null +++ b/misc.py @@ -0,0 +1,4 @@ +import random + +def random_sha256_hexdigest(): + return bytes([ random.randint(0, 255) for _ in range(32) ]).hex() diff --git a/volume.py b/volume.py index ca0c93b..1a447e2 100644 --- a/volume.py +++ b/volume.py @@ -1,5 +1,16 @@ +from .misc import random_sha256_hexdigest +from .zfs import * + + def command_volume_create(args): - raise NotImplementedError + sha256 = random_sha256_hexdigest() + poolname = zfs_poolname() + for pre in range(7, 64): + name = poolname + '/focker/volumes/' + sha256[:pre] + if not zfs_exists(name): + break + zfs_run(['zfs', 'create', '-o', 'focker:sha256=' + sha256, name]) + zfs_tag(name, args.tags) def command_volume_prune(args):