iotests: fix 097 when run with qcow
[qemu/kevin.git] / scripts / qmp / qom-tree
blob906fcd2640b399a26d5109412c15b69f439f1506
1 #!/usr/bin/python
2 ##
3 # QEMU Object Model test tools
5 # Copyright IBM, Corp. 2011
6 # Copyright (c) 2013 SUSE LINUX Products GmbH
8 # Authors:
9 # Anthony Liguori <aliguori@amazon.com>
10 # Andreas Faerber <afaerber@suse.de>
12 # This work is licensed under the terms of the GNU GPL, version 2 or later. See
13 # the COPYING file in the top-level directory.
16 import sys
17 import os
18 from qmp import QEMUMonitorProtocol
20 cmd, args = sys.argv[0], sys.argv[1:]
21 socket_path = None
22 path = None
23 prop = None
25 def usage():
26 return '''environment variables:
27 QMP_SOCKET=<path | addr:port>
28 usage:
29 %s [-h] [-s <QMP socket path | addr:port>] [<path>]
30 ''' % cmd
32 def usage_error(error_msg = "unspecified error"):
33 sys.stderr.write('%s\nERROR: %s\n' % (usage(), error_msg))
34 exit(1)
36 if len(args) > 0:
37 if args[0] == "-h":
38 print usage()
39 exit(0);
40 elif args[0] == "-s":
41 try:
42 socket_path = args[1]
43 except:
44 usage_error("missing argument: QMP socket path or address");
45 args = args[2:]
47 if not socket_path:
48 if os.environ.has_key('QMP_SOCKET'):
49 socket_path = os.environ['QMP_SOCKET']
50 else:
51 usage_error("no QMP socket path or address given");
53 srv = QEMUMonitorProtocol(socket_path)
54 srv.connect()
56 def list_node(path):
57 print '%s' % path
58 items = srv.command('qom-list', path=path)
59 for item in items:
60 if not item['type'].startswith('child<'):
61 try:
62 print ' %s: %s (%s)' % (item['name'], srv.command('qom-get', path=path, property=item['name']), item['type'])
63 except:
64 print ' %s: <EXCEPTION> (%s)' % (item['name'], item['type'])
65 print ''
66 for item in items:
67 if item['type'].startswith('child<'):
68 list_node((path if (path != '/') else '') + '/' + item['name'])
70 if len(args) == 0:
71 path = '/'
72 else:
73 path = args[0]
75 list_node(path)