tools/qvm-pool: add --set to modify pool properties
Fixes QubesOS/qubes-issues#3256
This commit is contained in:
parent
471523167e
commit
90df051f4f
@ -51,6 +51,11 @@ Options
|
||||
qubes.xml, but does not delete any content (FIXME: is it really true for
|
||||
all pool drivers?).
|
||||
|
||||
.. option:: --set NAME, -s NAME
|
||||
|
||||
Modify a pool. This set options of a pool. Use ``--o`` to specify actual modifications.
|
||||
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
|
@ -92,3 +92,25 @@ class TC_00_qvm_pool(qubesadmin.tests.QubesTestCase):
|
||||
'volume_group qubes_dom0\n'
|
||||
)
|
||||
self.assertAllCalled()
|
||||
|
||||
def test_050_set(self):
|
||||
self.app.expected_calls[('dom0', 'admin.pool.List', None, None)] = \
|
||||
b'0\x00pool-file\npool-lvm\n'
|
||||
self.app.expected_calls[
|
||||
('dom0', 'admin.pool.Set.revisions_to_keep', 'pool-lvm', b'2')] = \
|
||||
b'0\x00'
|
||||
self.assertEqual(0,
|
||||
qubesadmin.tools.qvm_pool.main(['-s', 'pool-lvm', '-o',
|
||||
'revisions_to_keep=2'],
|
||||
app=self.app))
|
||||
self.assertAllCalled()
|
||||
|
||||
def test_051_set_invalid(self):
|
||||
self.app.expected_calls[('dom0', 'admin.pool.List', None, None)] = \
|
||||
b'0\x00pool-file\npool-lvm\n'
|
||||
with self.assertRaises(SystemExit) as e:
|
||||
qubesadmin.tools.qvm_pool.main(
|
||||
['-s', 'pool-lvm', '-o', 'prop=1'],
|
||||
app=self.app)
|
||||
self.assertEqual(e.exception.code, 2)
|
||||
self.assertAllCalled()
|
||||
|
@ -92,6 +92,23 @@ class _Add(argparse.Action):
|
||||
setattr(namespace, 'driver', driver)
|
||||
|
||||
|
||||
class _Set(qubesadmin.tools.PoolsAction):
|
||||
''' Action for argument parser that sets pool options. '''
|
||||
|
||||
def __init__(self, option_strings, dest=None, default=None, metavar=None):
|
||||
super(_Set, self).__init__(option_strings=option_strings,
|
||||
dest=dest,
|
||||
metavar=metavar,
|
||||
default=default,
|
||||
help='modify pool (use -o to specify '
|
||||
'modifications)')
|
||||
|
||||
def __call__(self, parser, namespace, name, option_string=None):
|
||||
print('dupa')
|
||||
setattr(namespace, 'command', 'set')
|
||||
super(_Set, self).__call__(parser, namespace, name, option_string)
|
||||
|
||||
|
||||
class _Options(argparse.Action):
|
||||
''' Action for argument parser that parsers options. '''
|
||||
|
||||
@ -127,6 +144,8 @@ def get_parser():
|
||||
dest='command',
|
||||
metavar=('NAME', 'DRIVER'))
|
||||
group.add_argument('-r', '--remove', metavar='NAME', action=_Remove)
|
||||
group.add_argument('-s', '--set', metavar='POOLNAME', dest='pool',
|
||||
action=_Set, default=[])
|
||||
group.add_argument('--help-drivers',
|
||||
dest='command',
|
||||
const='list-drivers',
|
||||
@ -173,6 +192,17 @@ def main(args=None, app=None):
|
||||
elif args.command == 'info':
|
||||
for pool in args.pools:
|
||||
pool_info(pool)
|
||||
elif args.command == 'set':
|
||||
pool = args.pool[0]
|
||||
for opt, value in args.options.items():
|
||||
if not hasattr(type(pool), opt):
|
||||
parser.error('setting pool option %s is not supported' % (
|
||||
pool.name))
|
||||
try:
|
||||
setattr(pool, opt, value)
|
||||
except qubesadmin.exc.QubesException as e:
|
||||
parser.error('failed to set pool %s option %s: %s\n' % (
|
||||
pool.name, opt, str(e)))
|
||||
return 0
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user