roms: Update SLOF submodule to current status
[qemu.git] / scripts / qmp / qom-set
blob0352668812ec226032c0730fc50a3b3536e5c0be
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 from __future__ import absolute_import
16 import sys
17 import os
18 from .qmp import QEMUMonitorProtocol
20 cmd, args = sys.argv[0], sys.argv[1:]
21 socket_path = None
22 path = None
23 prop = None
24 value = None
26 def usage():
27 return '''environment variables:
28 QMP_SOCKET=<path | addr:port>
29 usage:
30 %s [-h] [-s <QMP socket path | addr:port>] <path>.<property> <value>
31 ''' % cmd
33 def usage_error(error_msg = "unspecified error"):
34 sys.stderr.write('%s\nERROR: %s\n' % (usage(), error_msg))
35 exit(1)
37 if len(args) > 0:
38 if args[0] == "-h":
39 print(usage())
40 exit(0);
41 elif args[0] == "-s":
42 try:
43 socket_path = args[1]
44 except:
45 usage_error("missing argument: QMP socket path or address");
46 args = args[2:]
48 if not socket_path:
49 if 'QMP_SOCKET' in os.environ:
50 socket_path = os.environ['QMP_SOCKET']
51 else:
52 usage_error("no QMP socket path or address given");
54 if len(args) > 1:
55 try:
56 path, prop = args[0].rsplit('.', 1)
57 except:
58 usage_error("invalid format for path/property/value")
59 value = args[1]
60 else:
61 usage_error("not enough arguments")
63 srv = QEMUMonitorProtocol(socket_path)
64 srv.connect()
66 print(srv.command('qom-set', path=path, property=prop, value=value))