|
@@ -61,6 +61,19 @@ class QMPTimeoutError(QMPError):
|
|
"""
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
+class QMPResponseError(QMPError):
|
|
|
|
+ """
|
|
|
|
+ Represents erroneous QMP monitor reply
|
|
|
|
+ """
|
|
|
|
+ def __init__(self, reply: QMPMessage):
|
|
|
|
+ try:
|
|
|
|
+ desc = reply['error']['desc']
|
|
|
|
+ except KeyError:
|
|
|
|
+ desc = reply
|
|
|
|
+ super().__init__(desc)
|
|
|
|
+ self.reply = reply
|
|
|
|
+
|
|
|
|
+
|
|
class QEMUMonitorProtocol:
|
|
class QEMUMonitorProtocol:
|
|
"""
|
|
"""
|
|
Provide an API to connect to QEMU via QEMU Monitor Protocol (QMP) and then
|
|
Provide an API to connect to QEMU via QEMU Monitor Protocol (QMP) and then
|
|
@@ -251,8 +264,8 @@ def command(self, cmd, **kwds):
|
|
Build and send a QMP command to the monitor, report errors if any
|
|
Build and send a QMP command to the monitor, report errors if any
|
|
"""
|
|
"""
|
|
ret = self.cmd(cmd, kwds)
|
|
ret = self.cmd(cmd, kwds)
|
|
- if "error" in ret:
|
|
|
|
- raise Exception(ret['error']['desc'])
|
|
|
|
|
|
+ if 'error' in ret:
|
|
|
|
+ raise QMPResponseError(ret)
|
|
return ret['return']
|
|
return ret['return']
|
|
|
|
|
|
def pull_event(self, wait=False):
|
|
def pull_event(self, wait=False):
|