1*06d4c71fSPhilippe Mathieu-Daudé#!/usr/bin/env python3 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 14235fe3bfSAnthony Liguoriimport sys 15235fe3bfSAnthony Liguoriimport os 16bf20b675SEduardo Habkostfrom qmp import QEMUMonitorProtocol 17235fe3bfSAnthony Liguori 18235fe3bfSAnthony Liguoricmd, args = sys.argv[0], sys.argv[1:] 19235fe3bfSAnthony Liguorisocket_path = None 20235fe3bfSAnthony Liguoripath = None 21235fe3bfSAnthony Liguoriprop = None 22235fe3bfSAnthony Liguori 23235fe3bfSAnthony Liguoridef usage(): 24235fe3bfSAnthony Liguori return '''environment variables: 25235fe3bfSAnthony Liguori QMP_SOCKET=<path | addr:port> 26235fe3bfSAnthony Liguoriusage: 27235fe3bfSAnthony Liguori %s [-h] [-s <QMP socket path | addr:port>] [<path>] 28235fe3bfSAnthony Liguori''' % cmd 29235fe3bfSAnthony Liguori 30235fe3bfSAnthony Liguoridef usage_error(error_msg = "unspecified error"): 31235fe3bfSAnthony Liguori sys.stderr.write('%s\nERROR: %s\n' % (usage(), error_msg)) 32235fe3bfSAnthony Liguori exit(1) 33235fe3bfSAnthony Liguori 34235fe3bfSAnthony Liguoriif len(args) > 0: 35235fe3bfSAnthony Liguori if args[0] == "-h": 36f03868bdSEduardo Habkost print(usage()) 37235fe3bfSAnthony Liguori exit(0); 38235fe3bfSAnthony Liguori elif args[0] == "-s": 39235fe3bfSAnthony Liguori try: 40235fe3bfSAnthony Liguori socket_path = args[1] 41235fe3bfSAnthony Liguori except: 42235fe3bfSAnthony Liguori usage_error("missing argument: QMP socket path or address"); 43235fe3bfSAnthony Liguori args = args[2:] 44235fe3bfSAnthony Liguori 45235fe3bfSAnthony Liguoriif not socket_path: 46d7a4228eSEduardo Habkost if 'QMP_SOCKET' in os.environ: 47235fe3bfSAnthony Liguori socket_path = os.environ['QMP_SOCKET'] 48235fe3bfSAnthony Liguori else: 49235fe3bfSAnthony Liguori usage_error("no QMP socket path or address given"); 50235fe3bfSAnthony Liguori 51235fe3bfSAnthony Liguorisrv = QEMUMonitorProtocol(socket_path) 52235fe3bfSAnthony Liguorisrv.connect() 53235fe3bfSAnthony Liguori 54235fe3bfSAnthony Liguoriif len(args) == 0: 55f03868bdSEduardo Habkost print('/') 56235fe3bfSAnthony Liguori sys.exit(0) 57235fe3bfSAnthony Liguori 58235fe3bfSAnthony Liguorifor item in srv.command('qom-list', path=args[0]): 59235fe3bfSAnthony Liguori if item['type'].startswith('child<'): 60f03868bdSEduardo Habkost print('%s/' % item['name']) 61235fe3bfSAnthony Liguori elif item['type'].startswith('link<'): 62f03868bdSEduardo Habkost print('@%s/' % item['name']) 63235fe3bfSAnthony Liguori else: 64f03868bdSEduardo Habkost print('%s' % item['name']) 65