xref: /openbmc/qemu/scripts/qmp/qom-list (revision 1b111dc1)
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
14import sys
15import os
16from qmp import QEMUMonitorProtocol
17
18cmd, args = sys.argv[0], sys.argv[1:]
19socket_path = None
20path = None
21prop = None
22
23def usage():
24    return '''environment variables:
25    QMP_SOCKET=<path | addr:port>
26usage:
27    %s [-h] [-s <QMP socket path | addr:port>] [<path>]
28''' % cmd
29
30def usage_error(error_msg = "unspecified error"):
31    sys.stderr.write('%s\nERROR: %s\n' % (usage(), error_msg))
32    exit(1)
33
34if 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
45if 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
51srv = QEMUMonitorProtocol(socket_path)
52srv.connect()
53
54if len(args) == 0:
55    print '/'
56    sys.exit(0)
57
58for 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']
65