From 66e835e5ddcd8f58fbdf9fd62e41ea8f5d725ddb Mon Sep 17 00:00:00 2001 From: Stanislaw Adaszewski Date: Mon, 25 May 2020 14:25:23 +0200 Subject: [PATCH] Add focker volume get|set. --- focker/focker.py | 14 +++++++++++++- focker/volume.py | 16 ++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/focker/focker.py b/focker/focker.py index e8c161b..aacbf09 100644 --- a/focker/focker.py +++ b/focker/focker.py @@ -22,7 +22,9 @@ from .volume import command_volume_create, \ command_volume_list, \ command_volume_tag, \ command_volume_untag, \ - command_volume_remove + command_volume_remove, \ + command_volume_set, \ + command_volume_get import sys from .zfs import zfs_init from .jail import command_jail_create, \ @@ -193,6 +195,16 @@ def create_parser(): parser.add_argument('references', type=str, nargs='+') parser.add_argument('--force', '-f', action='store_true') + parser = ListForwarder([subparsers.add_parser(cmd) for cmd in ['set', 's']]) + parser.set_defaults(func=command_volume_set) + parser.add_argument('reference', type=str) + parser.add_argument('properties', type=str, nargs=argparse.REMAINDER) + + parser = ListForwarder([subparsers.add_parser(cmd) for cmd in ['get', 'g']]) + parser.set_defaults(func=command_volume_get) + parser.add_argument('reference', type=str) + parser.add_argument('properties', type=str, nargs=argparse.REMAINDER) + # compose subparsers = ListForwarder([ subparsers_top.add_parser(cmd).add_subparsers(dest='L2_command') \ for cmd in ['compose', 'comp', 'c'] ]) diff --git a/focker/volume.py b/focker/volume.py index 5930325..bcf0b93 100644 --- a/focker/volume.py +++ b/focker/volume.py @@ -55,3 +55,19 @@ def command_volume_remove(args): except: if not args.force: raise + + +def command_volume_set(args): + name, _ = zfs_find(args.reference, focker_type='volume') + if not args.properties: + raise ValueError('You must specify some properties') + zfs_run(['zfs', 'set'] + args.properties + [name]) + + +def command_volume_get(args): + name, _ = zfs_find(args.reference, focker_type='volume') + if not args.properties: + raise ValueError('You must specify some properties') + res = zfs_parse_output(['zfs', 'get', '-H', ','.join(args.properties), name]) + res = map(lambda a: a[2], res) + print('\n'.join(res))