]> git.proxmox.com Git - mirror_qemu.git/blame - QMP/qmp-spec.txt
QMP: Introduce specification
[mirror_qemu.git] / QMP / qmp-spec.txt
CommitLineData
f544d174
LC
1 QEMU Monitor Protocol Draft Specification - Version 0.1
2
31. Introduction
4===============
5
6This document specifies the QEMU Monitor Protocol (QMP), a JSON-based protocol
7which is available for applications to control QEMU at the machine-level.
8
9To enable QMP support, QEMU has to be run in "control mode". This is done by
10starting QEMU with the appropriate command-line options. Please, refer to the
11QEMU manual page for more information.
12
132. Protocol Specification
14=========================
15
16This section details the protocol format. For the purpose of this document
17"Client" is any application which is communicating with QEMU in control mode,
18and "Server" is QEMU itself.
19
20JSON data structures, when mentioned in this document, are always in the
21following format:
22
23 json-DATA-STRUCTURE-NAME
24
25Where DATA-STRUCTURE-NAME is any valid JSON data structure, as defined by
26the JSON standard:
27
28http://www.ietf.org/rfc/rfc4627.txt
29
30For convenience, json-objects mentioned in this document will have its members
31in a certain order. However, in real protocol usage json-objects members can
32be in ANY order, thus no particular order should be assumed.
33
342.1 General Definitions
35-----------------------
36
372.1.1 All interactions transmitted by the Server are json-objects, always
38 terminating with CRLF
39
402.1.2 All json-objects members are mandatory when not specified otherwise
41
422.2 Server Greeting
43-------------------
44
45Right when connected the Server will issue a greeting message, which signals
46that the connection has been successfully established and that the Server is
47waiting for commands.
48
49The format is:
50
51{ "QMP": { "capabilities": json-array } }
52
53 Where,
54
55- The "capabilities" member specify the availability of features beyond the
56 baseline specification
57
582.3 Issuing Commands
59--------------------
60
61The format for command execution is:
62
63{ "execute": json-string, "arguments": json-object, "id": json-value }
64
65 Where,
66
67- The "execute" member identifies the command to be executed by the Server
68- The "arguments" member is used to pass any arguments required for the
69 execution of the command, it is optional when no arguments are required
70- The "id" member is a transaction identification associated with the
71 command execution, it is optional and will be part of the response if
72 provided
73
742.4 Commands Responses
75----------------------
76
77There are two possible responses which the Server will issue as the result
78of a command execution: success or error.
79
802.4.1 success
81-------------
82
83The success response is issued when the command execution has finished
84without errors.
85
86The format is:
87
88{ "return": json-value, "id": json-value }
89
90 Where,
91
92- The "return" member contains the command returned data, which is defined
93 in a per-command basis or "OK" if the command does not return data
94- The "id" member contains the transaction identification associated
95 with the command execution (if issued by the Client)
96
972.4.2 error
98-----------
99
100The error response is issued when the command execution could not be
101completed because of an error condition.
102
103The format is:
104
105{ "error": { "class": json-string, "data": json-value }, "id": json-value }
106
107 Where,
108
109- The "class" member contains the error class name (eg. "ServiceUnavailable")
110- The "data" member contains specific error data and is defined in a
111 per-command basis, it will be an empty json-object if the error has no data
112- The "id" member contains the transaction identification associated with
113 the command execution (if issued by the Client)
114
115NOTE: Some errors can occur before the Server is able to read the "id" member,
116in these cases the "id" member will not be part of the error response, even
117if provided by the client.
118
1192.5 Asynchronous events
120-----------------------
121
122As a result of state changes, the Server may send messages unilaterally
123to the Client at any time. They are called 'asynchronous events'.
124
125The format is:
126
127{ "event": json-string, "data": json-value,
128 "timestamp": { "seconds": json-number, "microseconds": json-number } }
129
130 Where,
131
132- The "event" member contains the event's name
133- The "data" member contains event specific data, which is defined in a
134 per-event basis, it is optional
135- The "timestamp" member contains the exact time of when the event ocurred
136 in the Server. It is a fixed json-object with time in seconds and
137 microseconds
138
139For a listing of supported asynchronous events, please, refer to the
140qmp-events.txt file.
141
1423. QMP Examples
143===============
144
145This section provides some examples of real QMP usage, in all of them
146'C' stands for 'Client' and 'S' stands for 'Server'.
147
1483.1 Server greeting
149-------------------
150
151S: {"QMP": {"capabilities": []}}
152
1533.2 Simple 'stop' execution
154---------------------------
155
156C: { "execute": "stop" }
157S: {"return": "OK"}
158
1593.3 KVM information
160-------------------
161
162C: {"execute": "query-kvm", "id": "example"}
163S: {"return": "enabled", "id": "example"}
164
1653.4 Parsing error
166------------------
167
168C: { "execute": }
169S: {"error": {"class": "JSONParsing", "data": {}}}
170
1713.5 Powerdown event
172-------------------
173
174S: {"timestamp": {"seconds": 1258551470, "microseconds": 802384}, "event":
175"POWERDOWN"}
176
1774. Notes to Client implementors
178-------------------------------
179
1804.1 It is recommended to always start the Server in pause mode, thus the
181 Client is able to perform any setup procedure without the risk of
182 race conditions and related problems
183
1844.2 It is recommended to always check the capabilities json-array, issued
185 with the greeting message, at connection time
186
1874.3 Json-objects or json-arrays mentioned in this document are not fixed
188 and no particular size or number of members/elements should be assumed.
189 New members/elements can be added at any time.
190
1914.4 No particular order of json-objects members should be assumed, they
192 can change at any time