qemu/QMP/qom-get
<<
>>
Prefs
   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>.<property>
  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
  51if len(args) > 0:
  52    try:
  53        path, prop = args[0].rsplit('.', 1)
  54    except:
  55        usage_error("invalid format for path/property/value")
  56else:
  57    usage_error("not enough arguments")
  58
  59srv = QEMUMonitorProtocol(socket_path)
  60srv.connect()
  61
  62rsp = srv.command('qom-get', path=path, property=prop)
  63if type(rsp) == dict:
  64    for i in rsp.keys():
  65        print '%s: %s' % (i, rsp[i])
  66else:
  67    print rsp
  68