Commit bb439d22 authored by Apollon Oikonomopoulos's avatar Apollon Oikonomopoulos Committed by Thomas Thrainer
Browse files

QMP: fetch supported commands on connect

Store the set of supported QMP commands in
QmpConnection.supported_commands. This allows selective error handling
to give the caller a chance to downgrade to HMP when unsupported
commands are encountered.

The `query-commands` QMP command used to implement this, appeared in
QEMU 0.14.0 together with QMP itself, so it is supported by all
instances featuring a QMP monitor.
Signed-off-by: default avatarApollon Oikonomopoulos <>
Signed-off-by: default avatarThomas Thrainer <>
Reviewed-by: default avatarThomas Thrainer <>
parent 6e684281
......@@ -183,11 +183,13 @@ class QmpConnection(MonitorSocket):
_EXECUTE_KEY = "execute"
_ARGUMENTS_KEY = "arguments"
_CAPABILITIES_COMMAND = "qmp_capabilities"
_QUERY_COMMANDS = "query-commands"
def __init__(self, monitor_filename):
super(QmpConnection, self).__init__(monitor_filename)
self._buf = ""
self.supported_commands = frozenset()
def connect(self):
"""Connects to the QMP monitor.
......@@ -216,6 +218,7 @@ class QmpConnection(MonitorSocket):
# command, or else no command will be executable.
# (As per the QEMU Protocol Specification 0.1 - section 4)
self.supported_commands = self._GetSupportedCommands()
def _ParseMessage(self, buf):
"""Extract and parse a QMP message from the given buffer.
......@@ -300,6 +303,13 @@ class QmpConnection(MonitorSocket):
raise errors.HypervisorError("Unable to send data from KVM using the"
" QMP protocol: %s" % err)
def _GetSupportedCommands(self):
"""Update the list of supported commands.
result = self.Execute(self._QUERY_COMMANDS)
return frozenset(com["name"] for com in result[self._RETURN_KEY])
def Execute(self, command, arguments=None):
"""Executes a QMP command and returns the response of the server.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment