]>
Commit | Line | Data |
---|---|---|
06d4c71f | 1 | #!/usr/bin/env python3 |
235fe3bf AL |
2 | ## |
3 | # QEMU Object Model test tools | |
4 | # | |
5 | # Copyright IBM, Corp. 2011 | |
6 | # | |
7 | # Authors: | |
8 | # Anthony Liguori <aliguori@us.ibm.com> | |
9 | # | |
10 | # This work is licensed under the terms of the GNU GPL, version 2 or later. See | |
11 | # the COPYING file in the top-level directory. | |
12 | ## | |
13 | ||
14 | import sys | |
15 | import os | |
c7b942d7 JS |
16 | |
17 | sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python')) | |
18 | from qemu.qmp import QEMUMonitorProtocol | |
235fe3bf AL |
19 | |
20 | cmd, args = sys.argv[0], sys.argv[1:] | |
21 | socket_path = None | |
22 | path = None | |
23 | prop = None | |
24 | ||
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 | |
31 | ||
32 | def usage_error(error_msg = "unspecified error"): | |
33 | sys.stderr.write('%s\nERROR: %s\n' % (usage(), error_msg)) | |
34 | exit(1) | |
35 | ||
36 | if len(args) > 0: | |
37 | if args[0] == "-h": | |
f03868bd | 38 | print(usage()) |
235fe3bf AL |
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:] | |
46 | ||
47 | if not socket_path: | |
d7a4228e | 48 | if 'QMP_SOCKET' in os.environ: |
235fe3bf AL |
49 | socket_path = os.environ['QMP_SOCKET'] |
50 | else: | |
51 | usage_error("no QMP socket path or address given"); | |
52 | ||
53 | srv = QEMUMonitorProtocol(socket_path) | |
54 | srv.connect() | |
55 | ||
56 | if len(args) == 0: | |
f03868bd | 57 | print('/') |
235fe3bf AL |
58 | sys.exit(0) |
59 | ||
60 | for item in srv.command('qom-list', path=args[0]): | |
61 | if item['type'].startswith('child<'): | |
f03868bd | 62 | print('%s/' % item['name']) |
235fe3bf | 63 | elif item['type'].startswith('link<'): |
f03868bd | 64 | print('@%s/' % item['name']) |
235fe3bf | 65 | else: |
f03868bd | 66 | print('%s' % item['name']) |