Received: from eggs.gnu.org ([2001:4830:134:3::10]:40104) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WB6NZ-0007J6-GW for qemu-devel@nongnu.org; Wed, 05 Feb 2014 12:35:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WB6NT-0000iY-Ht for qemu-devel@nongnu.org; Wed, 05 Feb 2014 12:35:17 -0500 Received: from cantor2.suse.de ([195.135.220.15]:39448 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WB6NT-0000hJ-Bu for qemu-devel@nongnu.org; Wed, 05 Feb 2014 12:35:11 -0500 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Wed, 5 Feb 2014 18:35:09 +0100 Message-Id: <1391621709-15620-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH] scripts: Add qom-tree script as modern equivalent of info qtree List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, armbru@redhat.com, lcapitulino@redhat.com, aliguori@amazon.com, pbonzini@redhat.com, =?UTF-8?q?Andreas=20F=C3=A4rber?= Functionally it is a recursive qom-list with qom-get per non-child<> property. Some failures needed to be handled, such as trying to read a pointer property, which is not representable in QMP. Those print a literal "". Signed-off-by: Andreas F=C3=A4rber --- scripts/qmp/qom-tree | 70 ++++++++++++++++++++++++++++++++++++++++++++++= ++++++ 1 file changed, 70 insertions(+) create mode 100755 scripts/qmp/qom-tree diff --git a/scripts/qmp/qom-tree b/scripts/qmp/qom-tree new file mode 100755 index 0000000..5fd506a --- /dev/null +++ b/scripts/qmp/qom-tree @@ -0,0 +1,70 @@ +#!/usr/bin/python +## +# QEMU Object Model test tools +# +# Copyright IBM, Corp. 2011 +# Copyright (c) 2013 SUSE LINUX Products GmbH +# +# Authors: +# Anthony Liguori +# Andreas Faerber +# +# This work is licensed under the terms of the GNU GPL, version 2 or lat= er. See +# the COPYING file in the top-level directory. +## + +import sys +import os +from qmp import QEMUMonitorProtocol + +cmd, args =3D sys.argv[0], sys.argv[1:] +socket_path =3D None +path =3D None +prop =3D None + +def usage(): + return '''environment variables: + QMP_SOCKET=3D +usage: + %s [-h] [-s ] [] +''' % cmd + +def usage_error(error_msg =3D "unspecified error"): + sys.stderr.write('%s\nERROR: %s\n' % (usage(), error_msg)) + exit(1) + +if len(args) > 0: + if args[0] =3D=3D "-h": + print usage() + exit(0); + elif args[0] =3D=3D "-s": + try: + socket_path =3D args[1] + except: + usage_error("missing argument: QMP socket path or address"); + args =3D args[2:] + +if not socket_path: + if os.environ.has_key('QMP_SOCKET'): + socket_path =3D os.environ['QMP_SOCKET'] + else: + usage_error("no QMP socket path or address given"); + +srv =3D QEMUMonitorProtocol(socket_path) +srv.connect() + +def list_node(path): + print '%s' % path + items =3D srv.command('qom-list', path=3Dpath) + for item in items: + if not item['type'].startswith('child<'): + try: + print ' %s: %s (%s)' % (item['name'], srv.command('qom-= get', path=3Dpath, property=3Ditem['name']), item['type']) + except: + print ' %s: (%s)' % (item['name'], item['ty= pe']) + print '' + for item in items: + if item['type'].startswith('child<'): + list_node(path + '/' + item['name']) + +list_node('/machine') --=20 1.8.4.5