]>
git.proxmox.com Git - mirror_qemu.git/blob - scripts/qmp/qmp
3 # QMP command line tool
5 # Copyright IBM, Corp. 2011
8 # Anthony Liguori <aliguori@us.ibm.com>
10 # This work is licensed under the terms of the GNU GPLv2 or later.
11 # See the COPYING file in the top-level directory.
13 from __future__
import print_function
15 from qmp
import QEMUMonitorProtocol
17 def print_response(rsp
, prefix
=[]):
23 print_response(item
, prefix
[:-1] + ['%s[%d]' % (prefix
[-1], i
)])
25 elif type(rsp
) == dict:
26 for key
in rsp
.keys():
27 print_response(rsp
[key
], prefix
+ [key
])
30 print('%s: %s' % ('.'.join(prefix
), rsp
))
37 # Use QMP_PATH if it's set
38 if 'QMP_PATH' in os
.environ
:
39 path
= os
.environ
['QMP_PATH']
44 if arg
.startswith('--'):
46 if arg
.find('=') == -1:
49 arg
, value
= arg
.split('=', 1)
52 if type(value
) == str:
55 os
.execlp('man', 'man', 'qmp')
57 print('Unknown argument "%s"' % arg
)
64 print("QMP path isn't set, use --path=qmp-monitor-address or set QMP_PATH")
68 command
, args
= args
[0], args
[1:]
70 print('No command found')
71 print('Usage: "qmp [--path=qmp-monitor-address] qmp-cmd arguments"')
74 if command
in ['help']:
75 os
.execlp('man', 'man', 'qmp')
77 srv
= QEMUMonitorProtocol(path
)
80 def do_command(srv
, cmd
, **kwds
):
81 rsp
= srv
.cmd(cmd
, kwds
)
83 raise Exception(rsp
['error']['desc'])
86 commands
= map(lambda x
: x
['name'], do_command(srv
, 'query-commands'))
90 if command
not in commands
:
91 fullcmd
= 'qmp-%s' % command
93 os
.environ
['QMP_PATH'] = path
94 os
.execvp(fullcmd
, [fullcmd
] + args
)
95 except OSError as exc
:
97 print('Command "%s" not found.' % (fullcmd
))
102 srv
= QEMUMonitorProtocol(path
)
107 if not arg
.startswith('--'):
108 print('Unknown argument "%s"' % arg
)
112 if arg
.find('=') == -1:
115 arg
, value
= arg
.split('=', 1)
118 os
.execlp('man', 'man', 'qmp-%s' % command
)
121 arguments
[arg
] = value
123 rsp
= do_command(srv
, command
, **arguments
)
126 if __name__
== '__main__':
127 sys
.exit(main(sys
.argv
[1:]))