]>
Commit | Line | Data |
---|---|---|
235fe3bf AL |
1 | #!/usr/bin/python |
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 | ||
f03868bd | 14 | from __future__ import print_function |
235fe3bf AL |
15 | import sys |
16 | import os | |
17 | from qmp import QEMUMonitorProtocol | |
18 | ||
19 | cmd, args = sys.argv[0], sys.argv[1:] | |
20 | socket_path = None | |
21 | path = None | |
22 | prop = None | |
23 | ||
24 | def usage(): | |
25 | return '''environment variables: | |
26 | QMP_SOCKET=<path | addr:port> | |
27 | usage: | |
28 | %s [-h] [-s <QMP socket path | addr:port>] [<path>] | |
29 | ''' % cmd | |
30 | ||
31 | def usage_error(error_msg = "unspecified error"): | |
32 | sys.stderr.write('%s\nERROR: %s\n' % (usage(), error_msg)) | |
33 | exit(1) | |
34 | ||
35 | if len(args) > 0: | |
36 | if args[0] == "-h": | |
f03868bd | 37 | print(usage()) |
235fe3bf AL |
38 | exit(0); |
39 | elif args[0] == "-s": | |
40 | try: | |
41 | socket_path = args[1] | |
42 | except: | |
43 | usage_error("missing argument: QMP socket path or address"); | |
44 | args = args[2:] | |
45 | ||
46 | if not socket_path: | |
47 | if os.environ.has_key('QMP_SOCKET'): | |
48 | socket_path = os.environ['QMP_SOCKET'] | |
49 | else: | |
50 | usage_error("no QMP socket path or address given"); | |
51 | ||
52 | srv = QEMUMonitorProtocol(socket_path) | |
53 | srv.connect() | |
54 | ||
55 | if len(args) == 0: | |
f03868bd | 56 | print('/') |
235fe3bf AL |
57 | sys.exit(0) |
58 | ||
59 | for item in srv.command('qom-list', path=args[0]): | |
60 | if item['type'].startswith('child<'): | |
f03868bd | 61 | print('%s/' % item['name']) |
235fe3bf | 62 | elif item['type'].startswith('link<'): |
f03868bd | 63 | print('@%s/' % item['name']) |
235fe3bf | 64 | else: |
f03868bd | 65 | print('%s' % item['name']) |