]> xenbits.xensource.com Git - qemu-upstream-4.5-testing.git/commitdiff
QMP: allow JSON dict arguments in qmp-shell
authorStefan Hajnoczi <stefanha@redhat.com>
Wed, 29 Jan 2014 11:17:31 +0000 (12:17 +0100)
committerLuiz Capitulino <lcapitulino@redhat.com>
Mon, 17 Feb 2014 16:57:23 +0000 (11:57 -0500)
qmp-shell hides the QMP wire protocol JSON encoding from the user.  Most
of the time this is helpful and makes the command-line human-friendly.

Some QMP commands take a dict as an argument.  In order to express this
we need to revert back to JSON notation.

This patch allows JSON dict arguments in qmp-shell so commands like
blockdev-add and nbd-server-start can be invoked:

  (QEMU) blockdev-add options={"driver":"file","id":"drive1",...}

Note that spaces are not allowed since str.split() is used to break up
the command-line arguments first.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Benoit Canet <benoit@irqsave.net>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
scripts/qmp/qmp-shell

index d6b420f18a9ac919b8dab6923f5ea8985b5fce8b..d374b357aa359d5be6d0b8e0958f08038a583908 100755 (executable)
@@ -31,6 +31,7 @@
 # (QEMU)
 
 import qmp
+import json
 import readline
 import sys
 import pprint
@@ -107,6 +108,8 @@ class QMPShell(qmp.QEMUMonitorProtocol):
                     value = True
                 elif opt[1] == 'false':
                     value = False
+                elif opt[1].startswith('{'):
+                    value = json.loads(opt[1])
                 else:
                     value = opt[1]
             qmpcmd['arguments'][opt[0]] = value