xref: /openbmc/qemu/scripts/qmp/qom-set (revision 992861fb)
1#!/usr/bin/env python3
2##
3# QEMU Object Model test tools
4#
5# Copyright IBM, Corp. 2011
6#
7# Authors:
8#  Anthony Liguori   <aliguori@us.ibm.com>
9#
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.
12##
13
14import sys
15import os
16
17sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
18from qemu.qmp import QEMUMonitorProtocol
19
20cmd, args = sys.argv[0], sys.argv[1:]
21socket_path = None
22path = None
23prop = None
24value = None
25
26def usage():
27    return '''environment variables:
28    QMP_SOCKET=<path | addr:port>
29usage:
30    %s [-h] [-s <QMP socket path | addr:port>] <path>.<property> <value>
31''' % cmd
32
33def usage_error(error_msg = "unspecified error"):
34    sys.stderr.write('%s\nERROR: %s\n' % (usage(), error_msg))
35    exit(1)
36
37if 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:]
47
48if 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");
53
54if 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]
60else:
61    usage_error("not enough arguments")
62
63srv = QEMUMonitorProtocol(socket_path)
64srv.connect()
65
66print(srv.command('qom-set', path=path, property=prop, value=value))
67