From 0fa374264f98740e15a7bc2e1b3966630b874fb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Mon, 14 Aug 2017 10:14:07 +0200 Subject: [PATCH] tools: add qvm-create --help-classes List available VM classes QubesOS/qubes-issues#3017 --- doc/manpages/qvm-create.rst | 5 +++++ qubesadmin/tests/tools/qvm_create.py | 10 ++++++++++ qubesadmin/tools/qvm_create.py | 10 ++++++++++ 3 files changed, 25 insertions(+) diff --git a/doc/manpages/qvm-create.rst b/doc/manpages/qvm-create.rst index e22eb74..f17607b 100644 --- a/doc/manpages/qvm-create.rst +++ b/doc/manpages/qvm-create.rst @@ -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 diff --git a/qubesadmin/tests/tools/qvm_create.py b/qubesadmin/tests/tools/qvm_create.py index 1723e26..e05e6d9 100644 --- a/qubesadmin/tests/tools/qvm_create.py +++ b/qubesadmin/tests/tools/qvm_create.py @@ -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() diff --git a/qubesadmin/tools/qvm_create.py b/qubesadmin/tools/qvm_create.py index 10bebcb..fb26d32 100644 --- a/qubesadmin/tools/qvm_create.py +++ b/qubesadmin/tools/qvm_create.py @@ -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: