Merge remote-tracking branch 'remotes/amarkovic/tags/mips-queue-jul-02-2019' into...
[qemu/ar7.git] / scripts / qmp / qom-set
blob26ed9e3263be0cfe4c47604c9bfcad90e18aa572
1 #!/usr/bin/python
2 ##
3 # QEMU Object Model test tools
5 # Copyright IBM, Corp. 2011
7 # Authors:
8 # Anthony Liguori <aliguori@us.ibm.com>
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.
14 from __future__ import print_function
15 import sys
16 import os
17 from qmp import QEMUMonitorProtocol
19 cmd, args = sys.argv[0], sys.argv[1:]
20 socket_path = None
21 path = None
22 prop = None
23 value = None
25 def usage():
26 return '''environment variables:
27 QMP_SOCKET=<path | addr:port>
28 usage:
29 %s [-h] [-s <QMP socket path | addr:port>] <path>.<property> <value>
30 ''' % cmd
32 def usage_error(error_msg = "unspecified error"):
33 sys.stderr.write('%s\nERROR: %s\n' % (usage(), error_msg))
34 exit(1)
36 if len(args) > 0:
37 if args[0] == "-h":
38 print(usage())
39 exit(0);
40 elif args[0] == "-s":
41 try:
42 socket_path = args[1]
43 except:
44 usage_error("missing argument: QMP socket path or address");
45 args = args[2:]
47 if not socket_path:
48 if 'QMP_SOCKET' in os.environ:
49 socket_path = os.environ['QMP_SOCKET']
50 else:
51 usage_error("no QMP socket path or address given");
53 if len(args) > 1:
54 try:
55 path, prop = args[0].rsplit('.', 1)
56 except:
57 usage_error("invalid format for path/property/value")
58 value = args[1]
59 else:
60 usage_error("not enough arguments")
62 srv = QEMUMonitorProtocol(socket_path)
63 srv.connect()
65 print(srv.command('qom-set', path=path, property=prop, value=value))