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 14f03868bdSEduardo Habkostfrom __future__ import print_function 15068cf7a4SEduardo Habkostfrom __future__ import absolute_import 16235fe3bfSAnthony Liguoriimport sys 17235fe3bfSAnthony Liguoriimport os 18068cf7a4SEduardo Habkostfrom .qmp import QEMUMonitorProtocol 19235fe3bfSAnthony Liguori 20235fe3bfSAnthony Liguoricmd, args = sys.argv[0], sys.argv[1:] 21235fe3bfSAnthony Liguorisocket_path = None 22235fe3bfSAnthony Liguoripath = None 23235fe3bfSAnthony Liguoriprop = None 24235fe3bfSAnthony Liguorivalue = None 25235fe3bfSAnthony Liguori 26235fe3bfSAnthony Liguoridef usage(): 27235fe3bfSAnthony Liguori return '''environment variables: 28235fe3bfSAnthony Liguori QMP_SOCKET=<path | addr:port> 29235fe3bfSAnthony Liguoriusage: 30235fe3bfSAnthony Liguori %s [-h] [-s <QMP socket path | addr:port>] <path>.<property> <value> 31235fe3bfSAnthony Liguori''' % cmd 32235fe3bfSAnthony Liguori 33235fe3bfSAnthony Liguoridef usage_error(error_msg = "unspecified error"): 34235fe3bfSAnthony Liguori sys.stderr.write('%s\nERROR: %s\n' % (usage(), error_msg)) 35235fe3bfSAnthony Liguori exit(1) 36235fe3bfSAnthony Liguori 37235fe3bfSAnthony Liguoriif len(args) > 0: 38235fe3bfSAnthony Liguori if args[0] == "-h": 39f03868bdSEduardo Habkost print(usage()) 40235fe3bfSAnthony Liguori exit(0); 41235fe3bfSAnthony Liguori elif args[0] == "-s": 42235fe3bfSAnthony Liguori try: 43235fe3bfSAnthony Liguori socket_path = args[1] 44235fe3bfSAnthony Liguori except: 45235fe3bfSAnthony Liguori usage_error("missing argument: QMP socket path or address"); 46235fe3bfSAnthony Liguori args = args[2:] 47235fe3bfSAnthony Liguori 48235fe3bfSAnthony Liguoriif not socket_path: 49*d7a4228eSEduardo Habkost if 'QMP_SOCKET' in os.environ: 50235fe3bfSAnthony Liguori socket_path = os.environ['QMP_SOCKET'] 51235fe3bfSAnthony Liguori else: 52235fe3bfSAnthony Liguori usage_error("no QMP socket path or address given"); 53235fe3bfSAnthony Liguori 54235fe3bfSAnthony Liguoriif len(args) > 1: 55235fe3bfSAnthony Liguori try: 56235fe3bfSAnthony Liguori path, prop = args[0].rsplit('.', 1) 57235fe3bfSAnthony Liguori except: 58235fe3bfSAnthony Liguori usage_error("invalid format for path/property/value") 59235fe3bfSAnthony Liguori value = args[1] 60235fe3bfSAnthony Liguorielse: 61235fe3bfSAnthony Liguori usage_error("not enough arguments") 62235fe3bfSAnthony Liguori 63235fe3bfSAnthony Liguorisrv = QEMUMonitorProtocol(socket_path) 64235fe3bfSAnthony Liguorisrv.connect() 65235fe3bfSAnthony Liguori 66f03868bdSEduardo Habkostprint(srv.command('qom-set', path=path, property=prop, value=value)) 67