]>
Commit | Line | Data |
---|---|---|
eb60aa57 AF |
1 | #!/usr/bin/python |
2 | ## | |
3 | # QEMU Object Model test tools | |
4 | # | |
5 | # Copyright IBM, Corp. 2011 | |
6 | # Copyright (c) 2013 SUSE LINUX Products GmbH | |
7 | # | |
8 | # Authors: | |
9 | # Anthony Liguori <aliguori@amazon.com> | |
10 | # Andreas Faerber <afaerber@suse.de> | |
11 | # | |
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. | |
14 | ## | |
15 | ||
f03868bd | 16 | from __future__ import print_function |
eb60aa57 AF |
17 | import sys |
18 | import os | |
bf20b675 | 19 | from qmp import QEMUMonitorProtocol |
eb60aa57 AF |
20 | |
21 | cmd, args = sys.argv[0], sys.argv[1:] | |
22 | socket_path = None | |
23 | path = None | |
24 | prop = None | |
25 | ||
26 | def usage(): | |
27 | return '''environment variables: | |
28 | QMP_SOCKET=<path | addr:port> | |
29 | usage: | |
30 | %s [-h] [-s <QMP socket path | addr:port>] [<path>] | |
31 | ''' % cmd | |
32 | ||
33 | def usage_error(error_msg = "unspecified error"): | |
34 | sys.stderr.write('%s\nERROR: %s\n' % (usage(), error_msg)) | |
35 | exit(1) | |
36 | ||
37 | if len(args) > 0: | |
38 | if args[0] == "-h": | |
f03868bd | 39 | print(usage()) |
eb60aa57 AF |
40 | exit(0); |
41 | elif args[0] == "-s": | |
42 | try: | |
43 | socket_path = args[1] | |
44 | except: | |
45 | usage_error("missing argument: QMP socket path or address"); | |
46 | args = args[2:] | |
47 | ||
48 | if not socket_path: | |
d7a4228e | 49 | if 'QMP_SOCKET' in os.environ: |
eb60aa57 AF |
50 | socket_path = os.environ['QMP_SOCKET'] |
51 | else: | |
52 | usage_error("no QMP socket path or address given"); | |
53 | ||
54 | srv = QEMUMonitorProtocol(socket_path) | |
55 | srv.connect() | |
56 | ||
57 | def list_node(path): | |
f03868bd | 58 | print('%s' % path) |
eb60aa57 AF |
59 | items = srv.command('qom-list', path=path) |
60 | for item in items: | |
61 | if not item['type'].startswith('child<'): | |
62 | try: | |
f03868bd | 63 | print(' %s: %s (%s)' % (item['name'], srv.command('qom-get', path=path, property=item['name']), item['type'])) |
eb60aa57 | 64 | except: |
f03868bd EH |
65 | print(' %s: <EXCEPTION> (%s)' % (item['name'], item['type'])) |
66 | print('') | |
eb60aa57 AF |
67 | for item in items: |
68 | if item['type'].startswith('child<'): | |
ff5397bc | 69 | list_node((path if (path != '/') else '') + '/' + item['name']) |
eb60aa57 | 70 | |
ff5397bc MC |
71 | if len(args) == 0: |
72 | path = '/' | |
73 | else: | |
74 | path = args[0] | |
75 | ||
76 | list_node(path) |