tools: add qvm-create --help-classes

List available VM classes

QubesOS/qubes-issues#3017
This commit is contained in:
Marek Marczykowski-Górecki 2017-08-14 10:14:07 +02:00
parent 0464a3ebfc
commit 0fa374264f
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
3 changed files with 25 additions and 0 deletions

View File

@ -7,6 +7,7 @@ Synopsis
--------
:command:`qvm-create` [-h] [--verbose] [--quiet] [--force-root] [--class *CLS*] [--property *NAME*=*VALUE*] [--pool *POOL_NAME:VOLUME_NAME*] [--template *VALUE*] --label *VALUE* [--root-copy-from *FILENAME* | --root-move-from *FILENAME*] *VMNAME*
:command:`qvm-create` --help-classes
Options
-------
@ -23,6 +24,10 @@ Options
Decrease verbosity.
.. option:: --help-classes
List available qube classes and exit. See below for short description.
.. option:: --class, -C
The new domain class name (default: **AppVM** for

View File

@ -156,3 +156,13 @@ class TC_00_qvm_create(qubesadmin.tests.QubesTestCase):
'--root-copy-from=/invalid', 'new-vm'],
app=self.app)
self.assertAllCalled()
def test_009_help_classes(self):
self.app.expected_calls[('dom0', 'admin.vmclass.List',
None, None)] = b'0\x00StandaloneVM\nAppVM\nTemplateVM\nDispVM\n'
with qubesadmin.tests.tools.StdoutBuffer() as stdout:
qubesadmin.tools.qvm_create.main(['--help-classes'],
app=self.app)
self.assertEqual(stdout.getvalue(),
'AppVM\nDispVM\nStandaloneVM\nTemplateVM\n')
self.assertAllCalled()

View File

@ -67,6 +67,10 @@ parser.add_argument('--label', '-l',
help='specify the label to use for the new domain'
' (e.g. red, yellow, green, ...)')
parser.add_argument('--help-classes',
action='store_true',
help='List available classes and exit')
parser_root = parser.add_mutually_exclusive_group()
parser_root.add_argument('--root-copy-from', '-r', metavar='FILENAME',
help='use provided root.img instead of default/empty one'
@ -90,6 +94,12 @@ def main(args=None, app=None):
'''Main function of qvm-create tool'''
args = parser.parse_args(args, app=app)
if args.help_classes:
vm_classes = args.app.qubesd_call('dom0', 'admin.vmclass.List').decode()
vm_classes = vm_classes.splitlines()
print('\n'.join(sorted(vm_classes)))
return 0
pools = {}
pool = None
if hasattr(args, 'pool') and args.pool: