From e55b5308655aef467acba8754a4892a5459e5f5b Mon Sep 17 00:00:00 2001 From: GammaSQ Date: Mon, 3 Dec 2018 09:21:01 +0100 Subject: [PATCH 1/5] added --standalone and --disp shortcuts --- qubesadmin/tools/qvm_create.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/qubesadmin/tools/qvm_create.py b/qubesadmin/tools/qvm_create.py index 5bd47df..3516e39 100644 --- a/qubesadmin/tools/qvm_create.py +++ b/qubesadmin/tools/qvm_create.py @@ -43,6 +43,14 @@ parser.add_argument('--class', '-C', dest='cls', default='AppVM', help='specify the class of the new domain (default: %(default)s)') +parser.add_argument('--standalone', + action="store_true", + help=' shortcut for --class StandaloneVM') + +parser.add_argument('--disp' + action=qubesadmin.tools.SinglePropertyAction, + help='alias for --class DispVM --label red --template ') + parser.add_argument('--property', '--prop', action=qubesadmin.tools.PropertyAction, help='set domain\'s property, like "internal", "memory" or "vcpus"') @@ -113,6 +121,14 @@ def main(args=None, app=None): if args.one_pool: pool = args.one_pool + if 'disp' in args.properties: + args.properties.setdefault('label', 'red') + args.cls = 'DispVM' + args.properties.setdefault('template', args.properties['disp']) + + if 'standalone' in args.properties: + args.cls = 'StandaloneVM' + if 'label' not in args.properties: parser.error('--label option is mandatory') From ce2fb96a4baed54f861fa592f71c72fc8af8a1bb Mon Sep 17 00:00:00 2001 From: GammaSQ Date: Sat, 8 Dec 2018 12:29:48 +0100 Subject: [PATCH 2/5] diff doesn't set template --- qubesadmin/tools/qvm_create.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/qubesadmin/tools/qvm_create.py b/qubesadmin/tools/qvm_create.py index 3516e39..fa0b4d1 100644 --- a/qubesadmin/tools/qvm_create.py +++ b/qubesadmin/tools/qvm_create.py @@ -47,9 +47,9 @@ parser.add_argument('--standalone', action="store_true", help=' shortcut for --class StandaloneVM') -parser.add_argument('--disp' - action=qubesadmin.tools.SinglePropertyAction, - help='alias for --class DispVM --label red --template ') +parser.add_argument('--disp', + action="store_true", + help='alias for --class DispVM --label red') parser.add_argument('--property', '--prop', action=qubesadmin.tools.PropertyAction, @@ -121,12 +121,11 @@ def main(args=None, app=None): if args.one_pool: pool = args.one_pool - if 'disp' in args.properties: + if args.disp: args.properties.setdefault('label', 'red') args.cls = 'DispVM' - args.properties.setdefault('template', args.properties['disp']) - if 'standalone' in args.properties: + if args.standalone: args.cls = 'StandaloneVM' if 'label' not in args.properties: From b848625428c3ef21e13cc09c079b4a978aaa2e3a Mon Sep 17 00:00:00 2001 From: GammaSQ Date: Sat, 8 Dec 2018 12:38:26 +0100 Subject: [PATCH 3/5] added tests for shortcuts --- qubesadmin/tests/tools/qvm_create.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/qubesadmin/tests/tools/qvm_create.py b/qubesadmin/tests/tools/qvm_create.py index 70ff4ad..e758fa6 100644 --- a/qubesadmin/tests/tools/qvm_create.py +++ b/qubesadmin/tests/tools/qvm_create.py @@ -328,3 +328,25 @@ class TC_00_qvm_create(qubesadmin.tests.QubesTestCase): app=self.app) self.assertIn('red, blue', stderr.getvalue()) self.assertAllCalled() + + def test_014_standalone_shortcut(self): + self.app.expected_calls[('dom0', 'admin.vm.Create.StandaloneVM', + None, b'name=new-vm label=red')] = b'0\x00' + self.app.expected_calls[('dom0', 'admin.label.List', None, None)] = \ + b'0\x00red\nblue\n' + self.app.expected_calls[('dom0', 'admin.vm.List', None, None)] = \ + b'0\x00new-vm class=StandaloneVM state=Halted\n' + qubesadmin.tools.qvm_create.main(['-l', 'red', '--standalone', 'new-vm'], + app=self.app) + self.assertAllCalled() + + def test_015_disp_shortcut(self): + self.app.expected_calls[('dom0', 'admin.vm.Create.DispVM', + None, b'name=new-vm label=red')] = b'0\x00' + self.app.expected_calls[('dom0', 'admin.label.List', None, None)] = \ + b'0\x00red\nblue\n' + self.app.expected_calls[('dom0', 'admin.vm.List', None, None)] = \ + b'0\x00new-vm class=DispVM state=Halted\n' + qubesadmin.tools.qvm_create.main(['--disp', 'new-vm'], + app=self.app) + self.assertAllCalled() From b49f2b07689a38ac694cdce30cdd33c6a7a1eec5 Mon Sep 17 00:00:00 2001 From: GammaSQ Date: Sat, 8 Dec 2018 13:42:17 +0100 Subject: [PATCH 4/5] Documentation is important! Added shortcuts to manpages --- doc/manpages/qvm-create.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/manpages/qvm-create.rst b/doc/manpages/qvm-create.rst index f17607b..a3ed0e7 100644 --- a/doc/manpages/qvm-create.rst +++ b/doc/manpages/qvm-create.rst @@ -24,6 +24,14 @@ Options Decrease verbosity. +.. option:: --standalone + + shortcut for --class StandaloneVM, see below + +..option :: --disp + + shortcut for --class DispVM --label red, see below + .. option:: --help-classes List available qube classes and exit. See below for short description. From 4ae683054ff919a2e97f2096ddfb481f883e7bef Mon Sep 17 00:00:00 2001 From: GammaSQ Date: Sat, 8 Dec 2018 14:37:59 +0100 Subject: [PATCH 5/5] Fixed typo in documentation --- doc/manpages/qvm-create.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/manpages/qvm-create.rst b/doc/manpages/qvm-create.rst index a3ed0e7..44c8f8b 100644 --- a/doc/manpages/qvm-create.rst +++ b/doc/manpages/qvm-create.rst @@ -28,7 +28,7 @@ Options shortcut for --class StandaloneVM, see below -..option :: --disp +.. option:: --disp shortcut for --class DispVM --label red, see below