From 080b563ae27ea7b1249f22ed60bbfcc3edd3c144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Fri, 22 Dec 2017 23:11:33 +0100 Subject: [PATCH] tools/qvm-ls: add --raw-list option for compatibility with R3.2 There was an option to list just VM names, useful for scripting. Preserve that for compatibility. --- doc/manpages/qvm-ls.rst | 14 ++++++++++++++ qubesadmin/tests/tools/qvm_ls.py | 8 ++++++++ qubesadmin/tools/qvm_ls.py | 8 ++++++++ 3 files changed, 30 insertions(+) diff --git a/doc/manpages/qvm-ls.rst b/doc/manpages/qvm-ls.rst index 02c4272..5a39eb2 100644 --- a/doc/manpages/qvm-ls.rst +++ b/doc/manpages/qvm-ls.rst @@ -23,6 +23,15 @@ Options List all available formats with their definitions and exit. +.. option:: --all + + List all qubes, this is default. + +.. option:: --exclude + + Exclude the qube from --all. You need to use --all option explicitly to use + --exclude. + .. option:: --format=FORMAT, -o FORMAT Sets format to a list of columns defined by preset. All formats along with @@ -39,6 +48,11 @@ Options Output data in easy to parse format. Table header is skipped and columns are separated by `|` character. +.. option:: --raw-list + + Give plain list of VM names, without header or separator. Useful in scripts. + Same as --raw-data --fields=name + .. option:: --verbose, -v Increase verbosity. diff --git a/qubesadmin/tests/tools/qvm_ls.py b/qubesadmin/tests/tools/qvm_ls.py index 2d16c5e..cb9f6fc 100644 --- a/qubesadmin/tests/tools/qvm_ls.py +++ b/qubesadmin/tests/tools/qvm_ls.py @@ -112,6 +112,14 @@ class TC_50_List(qubesadmin.tests.QubesTestCase): 'NAME STATE CLASS LABEL TEMPLATE NETVM\n' 'test-vm Running TestVM green template sys-net\n') + def test_102_raw_list(self): + app = TestApp() + with qubesadmin.tests.tools.StdoutBuffer() as stdout: + qubesadmin.tools.qvm_ls.main(['--raw-list'], app=app) + self.assertEqual(stdout.getvalue(), + 'dom0\n' + 'test-vm\n') + class TC_90_List_with_qubesd_calls(qubesadmin.tests.QubesTestCase): def test_100_list_with_status(self): diff --git a/qubesadmin/tools/qvm_ls.py b/qubesadmin/tools/qvm_ls.py index c490d86..0bacc13 100644 --- a/qubesadmin/tools/qvm_ls.py +++ b/qubesadmin/tools/qvm_ls.py @@ -539,6 +539,10 @@ def get_parser(): action='store_false', dest='spinner', help='disable spinner') + # shortcuts, compatibility with Qubes 3.2 + parser.add_argument('--raw-list', action='store_true', + help='Same as --raw-data --fields=name') + parser.set_defaults(spinner=True) # parser.add_argument('--conf', '-c', @@ -563,6 +567,10 @@ def main(args=None, app=None): parser.print_error(str(e)) return 1 + if args.raw_list: + args.raw_data = True + args.fields = 'name' + if args.fields: columns = [col.strip() for col in args.fields.split(',')] else: