Statistics
| Branch: | Revision:

root / scripts / qmp / qom-list @ 22f3946b

History | View | Annotate | Download (1.5 kB)

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

    
14
import sys
15
import os
16
from qmp import QEMUMonitorProtocol
17

    
18
cmd, args = sys.argv[0], sys.argv[1:]
19
socket_path = None
20
path = None
21
prop = None
22

    
23
def usage():
24
    return '''environment variables:
25
    QMP_SOCKET=<path | addr:port>
26
usage:
27
    %s [-h] [-s <QMP socket path | addr:port>] [<path>]
28
''' % cmd
29

    
30
def usage_error(error_msg = "unspecified error"):
31
    sys.stderr.write('%s\nERROR: %s\n' % (usage(), error_msg))
32
    exit(1)
33

    
34
if len(args) > 0:
35
    if args[0] == "-h":
36
        print usage()
37
        exit(0);
38
    elif args[0] == "-s":
39
        try:
40
            socket_path = args[1]
41
        except:
42
            usage_error("missing argument: QMP socket path or address");
43
        args = args[2:]
44

    
45
if not socket_path:
46
    if os.environ.has_key('QMP_SOCKET'):
47
        socket_path = os.environ['QMP_SOCKET']
48
    else:
49
        usage_error("no QMP socket path or address given");
50

    
51
srv = QEMUMonitorProtocol(socket_path)
52
srv.connect()
53

    
54
if len(args) == 0:
55
    print '/'
56
    sys.exit(0)
57

    
58
for item in srv.command('qom-list', path=args[0]):
59
    if item['type'].startswith('child<'):
60
        print '%s/' % item['name']
61
    elif item['type'].startswith('link<'):
62
        print '@%s/' % item['name']
63
    else:
64
        print '%s' % item['name']