root / QMP / qom-list @ 5f8ae8e2
History | View | Annotate | Download (1.5 kB)
1 | 235fe3bf | Anthony Liguori | #!/usr/bin/python |
---|---|---|---|
2 | 235fe3bf | Anthony Liguori | ## |
3 | 235fe3bf | Anthony Liguori | # QEMU Object Model test tools |
4 | 235fe3bf | Anthony Liguori | # |
5 | 235fe3bf | Anthony Liguori | # Copyright IBM, Corp. 2011 |
6 | 235fe3bf | Anthony Liguori | # |
7 | 235fe3bf | Anthony Liguori | # Authors: |
8 | 235fe3bf | Anthony Liguori | # Anthony Liguori <aliguori@us.ibm.com> |
9 | 235fe3bf | Anthony Liguori | # |
10 | 235fe3bf | Anthony Liguori | # This work is licensed under the terms of the GNU GPL, version 2 or later. See |
11 | 235fe3bf | Anthony Liguori | # the COPYING file in the top-level directory. |
12 | 235fe3bf | Anthony Liguori | ## |
13 | 235fe3bf | Anthony Liguori | |
14 | 235fe3bf | Anthony Liguori | import sys |
15 | 235fe3bf | Anthony Liguori | import os |
16 | 235fe3bf | Anthony Liguori | from qmp import QEMUMonitorProtocol |
17 | 235fe3bf | Anthony Liguori | |
18 | 235fe3bf | Anthony Liguori | cmd, args = sys.argv[0], sys.argv[1:] |
19 | 235fe3bf | Anthony Liguori | socket_path = None |
20 | 235fe3bf | Anthony Liguori | path = None |
21 | 235fe3bf | Anthony Liguori | prop = None |
22 | 235fe3bf | Anthony Liguori | |
23 | 235fe3bf | Anthony Liguori | def usage(): |
24 | 235fe3bf | Anthony Liguori | return '''environment variables: |
25 | 235fe3bf | Anthony Liguori | QMP_SOCKET=<path | addr:port> |
26 | 235fe3bf | Anthony Liguori | usage: |
27 | 235fe3bf | Anthony Liguori | %s [-h] [-s <QMP socket path | addr:port>] [<path>] |
28 | 235fe3bf | Anthony Liguori | ''' % cmd |
29 | 235fe3bf | Anthony Liguori | |
30 | 235fe3bf | Anthony Liguori | def usage_error(error_msg = "unspecified error"): |
31 | 235fe3bf | Anthony Liguori | sys.stderr.write('%s\nERROR: %s\n' % (usage(), error_msg)) |
32 | 235fe3bf | Anthony Liguori | exit(1) |
33 | 235fe3bf | Anthony Liguori | |
34 | 235fe3bf | Anthony Liguori | if len(args) > 0: |
35 | 235fe3bf | Anthony Liguori | if args[0] == "-h": |
36 | 235fe3bf | Anthony Liguori | print usage() |
37 | 235fe3bf | Anthony Liguori | exit(0); |
38 | 235fe3bf | Anthony Liguori | elif args[0] == "-s": |
39 | 235fe3bf | Anthony Liguori | try: |
40 | 235fe3bf | Anthony Liguori | socket_path = args[1] |
41 | 235fe3bf | Anthony Liguori | except: |
42 | 235fe3bf | Anthony Liguori | usage_error("missing argument: QMP socket path or address"); |
43 | 235fe3bf | Anthony Liguori | args = args[2:] |
44 | 235fe3bf | Anthony Liguori | |
45 | 235fe3bf | Anthony Liguori | if not socket_path: |
46 | 235fe3bf | Anthony Liguori | if os.environ.has_key('QMP_SOCKET'): |
47 | 235fe3bf | Anthony Liguori | socket_path = os.environ['QMP_SOCKET'] |
48 | 235fe3bf | Anthony Liguori | else: |
49 | 235fe3bf | Anthony Liguori | usage_error("no QMP socket path or address given"); |
50 | 235fe3bf | Anthony Liguori | |
51 | 235fe3bf | Anthony Liguori | srv = QEMUMonitorProtocol(socket_path) |
52 | 235fe3bf | Anthony Liguori | srv.connect() |
53 | 235fe3bf | Anthony Liguori | |
54 | 235fe3bf | Anthony Liguori | if len(args) == 0: |
55 | 235fe3bf | Anthony Liguori | print '/' |
56 | 235fe3bf | Anthony Liguori | sys.exit(0) |
57 | 235fe3bf | Anthony Liguori | |
58 | 235fe3bf | Anthony Liguori | for item in srv.command('qom-list', path=args[0]): |
59 | 235fe3bf | Anthony Liguori | if item['type'].startswith('child<'): |
60 | 235fe3bf | Anthony Liguori | print '%s/' % item['name'] |
61 | 235fe3bf | Anthony Liguori | elif item['type'].startswith('link<'): |
62 | 235fe3bf | Anthony Liguori | print '@%s/' % item['name'] |
63 | 235fe3bf | Anthony Liguori | else: |
64 | 235fe3bf | Anthony Liguori | print '%s' % item['name'] |