QMP Messages
QMP Message Format
This module provides the Message
class, which represents a single QMP
message sent to or from the server.
- class qemu.qmp.message.Message(value: bytes | Mapping[str, object] = b'{}', *, eager: bool = True)[source]
Bases:
MutableMapping
[str
,object
]Represents a single QMP protocol message.
QMP uses JSON objects as its basic communicative unit; so this Python object is a
MutableMapping
. It may be instantiated from either another mapping (like adict
), or from rawbytes
that still need to be deserialized.Once instantiated, it may be treated like any other
MutableMapping
:>>> msg = Message(b'{"hello": "world"}') >>> assert msg['hello'] == 'world' >>> msg['id'] = 'foobar' >>> print(msg) { "hello": "world", "id": "foobar" }
It can be converted to
bytes
:>>> msg = Message({"hello": "world"}) >>> print(bytes(msg)) b'{"hello":"world","id":"foobar"}'
Or back into a garden-variety
dict
:>>> dict(msg) {'hello': 'world'}
Or pretty-printed:
>>> print(str(msg)) { "hello": "world" }
- Parameters:
value – Initial value, if any.
eager – When
True
, attempt to serialize or deserialize the initial value immediately, so that conversion exceptions are raised during the call to__init__()
.
- exception qemu.qmp.message.DeserializationError(error_message: str, raw: bytes)[source]
Bases:
ProtocolError
A QMP message was not understood as JSON.
When this Exception is raised,
__cause__
will be set to thejson.JSONDecodeError
Exception, which can be interrogated for further details.- Parameters:
error_message – Human-readable string describing the error.
raw – The raw
bytes
that prompted the failure.
- exception qemu.qmp.message.UnexpectedTypeError(error_message: str, value: object)[source]
Bases:
ProtocolError
A QMP message was JSON, but not a JSON object.
- Parameters:
error_message – Human-readable string describing the error.
value – The deserialized JSON value that wasn’t an object.
QMP Data Models
QMP Data Models
This module provides simplistic data classes that represent the few structures that the QMP spec mandates; they are used to verify incoming data to make sure it conforms to spec.
- class qemu.qmp.models.Model(raw: Mapping[str, Any])[source]
Bases:
object
Abstract data model, representing some QMP object of some kind.
- class qemu.qmp.models.Greeting(raw: Mapping[str, Any])[source]
Bases:
Model
Defined in qmp-spec.txt, section 2.2, “Server Greeting”.
See 2.2 Server Greeting for details.
- Parameters:
raw – The raw Greeting object.
- Raises:
- QMP: QMPGreeting
‘QMP’ member
- class qemu.qmp.models.QMPGreeting(raw: Mapping[str, Any])[source]
Bases:
Model
Defined in qmp-spec.txt, section 2.2, “Server Greeting”.
- Parameters:
raw – The raw QMPGreeting object.
- Raises:
- class qemu.qmp.models.ErrorResponse(raw: Mapping[str, Any])[source]
Bases:
Model
Defined in qmp-spec.txt, section 2.4.2, “error”.
- Parameters:
raw – The raw ErrorResponse object.
- Raises: