@@ -4,7 +4,7 @@ Interfaces to the QEMU monitor.
@copyright: 2008-2010 Red Hat Inc.
"""
-import socket, time, threading, logging
+import socket, time, threading, logging, re
import kvm_utils
try:
import json
@@ -188,6 +188,7 @@ class HumanMonitor(Monitor):
try:
try:
+ logging.debug("Send command: %s" % command)
self._socket.sendall(command + "\n")
except socket.error:
raise MonitorSendError("Could not send monitor command '%s'" %
@@ -256,13 +257,14 @@ class HumanMonitor(Monitor):
# - A command wrapper should use self._help_str if it requires information
# about the monitor's capabilities.
- def cmd(self, command, timeout=20):
+ def cmd(self, cmdline, timeout=20):
"""
- Send a simple command with no parameters and return its output.
- Should only be used for commands that take no parameters and are
- implemented under the same name for both the human and QMP monitors.
-
- @param command: Command to send
+ Send a simple command with/without parameters and return its output.
+ Implemented under the same name for both the human and QMP monitors.
+ Command with parameters should in following format e.g.:
+ 'memsave val=0 size=10240 filename=memsave'
+ Command without parameter: 'memsave'
+ @param comline: Command to send
@param timeout: Time duration to wait for (qemu) prompt after command
@return: The output of the command
@raise MonitorLockError: Raised if the lock cannot be acquired
@@ -270,6 +272,10 @@ class HumanMonitor(Monitor):
@raise MonitorProtocolError: Raised if the (qemu) prompt cannot be
found after sending the command
"""
+ command = cmdline.split()[0]
+ re_str = "(?<=\=)\w*"
+ command += " " + ' '.join(re.findall(re_str, cmdline))
+
return self._get_command_output(command, timeout)
@@ -486,6 +492,7 @@ class QMPMonitor(Monitor):
try:
cmdobj = self._build_cmd(cmd, args, id)
try:
+ logging.debug("Send command: %s" % cmdobj)
self._socket.sendall(json.dumps(cmdobj) + "\n")
except socket.error:
raise MonitorSendError("Could not send QMP command '%s'" % cmd)
@@ -601,11 +608,13 @@ class QMPMonitor(Monitor):
# Note: all of the following functions raise exceptions in a similar manner
# to cmd() and _get_command_output().
- def cmd(self, command, timeout=20):
+ def cmd(self, cmdline, timeout=20):
"""
- Send a simple command with no parameters and return its output.
- Should only be used for commands that take no parameters and are
- implemented under the same name for both the human and QMP monitors.
+ Send a simple command with/without parameters and return its output.
+ Implemented under the same name for both the human and QMP monitors.
+ Command with parameters should in following format e.g.:
+ 'memsave val=0 size=10240 filename=memsave'
+ Command without parameter: 'memsave'
@param command: Command to send
@param timeout: Time duration to wait for response
@@ -614,7 +623,20 @@ class QMPMonitor(Monitor):
@raise MonitorSendError: Raised if the command cannot be sent
@raise MonitorProtocolError: Raised if no response is received
"""
- return self._get_command_output(command, timeout=timeout)
+ cmdargs = cmdline.split()
+ command = cmdargs[0]
+ args = {}
+ for arg in cmdargs[1:]:
+ opt = arg.split('=')
+ try:
+ try:
+ value = int(opt[1])
+ except ValueError:
+ value = opt[1]
+ args[opt[0]] = value
+ except:
+ logging.debug("Fail to create args, please check command")
+ return self._get_command_output(command, args, timeout=timeout)
def quit(self):