summaryrefslogtreecommitdiffstats
path: root/qemu/scripts/qmp/qmp-shell
diff options
context:
space:
mode:
authorDon Dugger <n0ano@n0ano.com>2016-06-03 03:33:22 +0000
committerGerrit Code Review <gerrit@172.30.200.206>2016-06-03 03:33:23 +0000
commitda27230f80795d0028333713f036d44c53cb0e68 (patch)
treeb3d379eaf000adf72b36cb01cdf4d79c3e3f064c /qemu/scripts/qmp/qmp-shell
parent0e68cb048bb8aadb14675f5d4286d8ab2fc35449 (diff)
parent437fd90c0250dee670290f9b714253671a990160 (diff)
Merge "These changes are the raw update to qemu-2.6."
Diffstat (limited to 'qemu/scripts/qmp/qmp-shell')
-rwxr-xr-xqemu/scripts/qmp/qmp-shell60
1 files changed, 46 insertions, 14 deletions
diff --git a/qemu/scripts/qmp/qmp-shell b/qemu/scripts/qmp/qmp-shell
index 65280d29d..0373b24b2 100755
--- a/qemu/scripts/qmp/qmp-shell
+++ b/qemu/scripts/qmp/qmp-shell
@@ -29,13 +29,47 @@
# (QEMU) device_add driver=e1000 id=net1
# {u'return': {}}
# (QEMU)
+#
+# key=value pairs also support Python or JSON object literal subset notations,
+# without spaces. Dictionaries/objects {} are supported as are arrays [].
+#
+# example-command arg-name1={'key':'value','obj'={'prop':"value"}}
+#
+# Both JSON and Python formatting should work, including both styles of
+# string literal quotes. Both paradigms of literal values should work,
+# including null/true/false for JSON and None/True/False for Python.
+#
+#
+# Transactions have the following multi-line format:
+#
+# transaction(
+# action-name1 [ arg-name1=arg1 ] ... [arg-nameN=argN ]
+# ...
+# action-nameN [ arg-name1=arg1 ] ... [arg-nameN=argN ]
+# )
+#
+# One line transactions are also supported:
+#
+# transaction( action-name1 ... )
+#
+# For example:
+#
+# (QEMU) transaction(
+# TRANS> block-dirty-bitmap-add node=drive0 name=bitmap1
+# TRANS> block-dirty-bitmap-clear node=drive0 name=bitmap0
+# TRANS> )
+# {"return": {}}
+# (QEMU)
+#
+# Use the -v and -p options to activate the verbose and pretty-print options,
+# which will echo back the properly formatted JSON-compliant QMP that is being
+# sent to QEMU, which is useful for debugging and documentation generation.
import qmp
import json
import ast
import readline
import sys
-import pprint
class QMPCompleter(list):
def complete(self, text, state):
@@ -68,11 +102,11 @@ class FuzzyJSON(ast.NodeTransformer):
# TODO: QMPShell's interface is a bit ugly (eg. _fill_completion() and
# _execute_cmd()). Let's design a better one.
class QMPShell(qmp.QEMUMonitorProtocol):
- def __init__(self, address, pp=None):
+ def __init__(self, address, pretty=False):
qmp.QEMUMonitorProtocol.__init__(self, self.__get_address(address))
self._greeting = None
self._completer = None
- self._pp = pp
+ self._pretty = pretty
self._transmode = False
self._actions = list()
@@ -196,16 +230,16 @@ class QMPShell(qmp.QEMUMonitorProtocol):
return qmpcmd
def _print(self, qmp):
- jsobj = json.dumps(qmp)
- if self._pp is not None:
- self._pp.pprint(jsobj)
- else:
- print str(jsobj)
+ indent = None
+ if self._pretty:
+ indent = 4
+ jsobj = json.dumps(qmp, indent=indent)
+ print str(jsobj)
def _execute_cmd(self, cmdline):
try:
qmpcmd = self.__build_cmd(cmdline)
- except Exception, e:
+ except Exception as e:
print 'Error while parsing command line: %s' % e
print 'command format: <command-name> ',
print '[arg-name1=arg1] ... [arg-nameN=argN]'
@@ -342,7 +376,7 @@ def main():
addr = ''
qemu = None
hmp = False
- pp = None
+ pretty = False
verbose = False
try:
@@ -352,9 +386,7 @@ def main():
fail_cmdline(arg)
hmp = True
elif arg == "-p":
- if pp is not None:
- fail_cmdline(arg)
- pp = pprint.PrettyPrinter(indent=4)
+ pretty = True
elif arg == "-v":
verbose = True
else:
@@ -363,7 +395,7 @@ def main():
if hmp:
qemu = HMPShell(arg)
else:
- qemu = QMPShell(arg, pp)
+ qemu = QMPShell(arg, pretty)
addr = arg
if qemu is None: