1235fe3bfSAnthony Liguori#!/usr/bin/python 2235fe3bfSAnthony Liguori## 3235fe3bfSAnthony Liguori# QEMU Object Model test tools 4235fe3bfSAnthony Liguori# 5235fe3bfSAnthony Liguori# Copyright IBM, Corp. 2011 6235fe3bfSAnthony Liguori# 7235fe3bfSAnthony Liguori# Authors: 8235fe3bfSAnthony Liguori# Anthony Liguori <aliguori@us.ibm.com> 9235fe3bfSAnthony Liguori# 10235fe3bfSAnthony Liguori# This work is licensed under the terms of the GNU GPL, version 2 or later. See 11235fe3bfSAnthony Liguori# the COPYING file in the top-level directory. 12235fe3bfSAnthony Liguori## 13235fe3bfSAnthony Liguori 14*f03868bdSEduardo Habkostfrom __future__ import print_function 15235fe3bfSAnthony Liguoriimport sys 16235fe3bfSAnthony Liguoriimport os 17235fe3bfSAnthony Liguorifrom qmp import QEMUMonitorProtocol 18235fe3bfSAnthony Liguori 19235fe3bfSAnthony Liguoricmd, args = sys.argv[0], sys.argv[1:] 20235fe3bfSAnthony Liguorisocket_path = None 21235fe3bfSAnthony Liguoripath = None 22235fe3bfSAnthony Liguoriprop = None 23235fe3bfSAnthony Liguori 24235fe3bfSAnthony Liguoridef usage(): 25235fe3bfSAnthony Liguori return '''environment variables: 26235fe3bfSAnthony Liguori QMP_SOCKET=<path | addr:port> 27235fe3bfSAnthony Liguoriusage: 28235fe3bfSAnthony Liguori %s [-h] [-s <QMP socket path | addr:port>] [<path>] 29235fe3bfSAnthony Liguori''' % cmd 30235fe3bfSAnthony Liguori 31235fe3bfSAnthony Liguoridef usage_error(error_msg = "unspecified error"): 32235fe3bfSAnthony Liguori sys.stderr.write('%s\nERROR: %s\n' % (usage(), error_msg)) 33235fe3bfSAnthony Liguori exit(1) 34235fe3bfSAnthony Liguori 35235fe3bfSAnthony Liguoriif len(args) > 0: 36235fe3bfSAnthony Liguori if args[0] == "-h": 37*f03868bdSEduardo Habkost print(usage()) 38235fe3bfSAnthony Liguori exit(0); 39235fe3bfSAnthony Liguori elif args[0] == "-s": 40235fe3bfSAnthony Liguori try: 41235fe3bfSAnthony Liguori socket_path = args[1] 42235fe3bfSAnthony Liguori except: 43235fe3bfSAnthony Liguori usage_error("missing argument: QMP socket path or address"); 44235fe3bfSAnthony Liguori args = args[2:] 45235fe3bfSAnthony Liguori 46235fe3bfSAnthony Liguoriif not socket_path: 47235fe3bfSAnthony Liguori if os.environ.has_key('QMP_SOCKET'): 48235fe3bfSAnthony Liguori socket_path = os.environ['QMP_SOCKET'] 49235fe3bfSAnthony Liguori else: 50235fe3bfSAnthony Liguori usage_error("no QMP socket path or address given"); 51235fe3bfSAnthony Liguori 52235fe3bfSAnthony Liguorisrv = QEMUMonitorProtocol(socket_path) 53235fe3bfSAnthony Liguorisrv.connect() 54235fe3bfSAnthony Liguori 55235fe3bfSAnthony Liguoriif len(args) == 0: 56*f03868bdSEduardo Habkost print('/') 57235fe3bfSAnthony Liguori sys.exit(0) 58235fe3bfSAnthony Liguori 59235fe3bfSAnthony Liguorifor item in srv.command('qom-list', path=args[0]): 60235fe3bfSAnthony Liguori if item['type'].startswith('child<'): 61*f03868bdSEduardo Habkost print('%s/' % item['name']) 62235fe3bfSAnthony Liguori elif item['type'].startswith('link<'): 63*f03868bdSEduardo Habkost print('@%s/' % item['name']) 64235fe3bfSAnthony Liguori else: 65*f03868bdSEduardo Habkost print('%s' % item['name']) 66