root / QMP / qom-set @ 136be99e
History | View | Annotate | Download (1.5 kB)
1 | 235fe3bf | Anthony Liguori | #!/usr/bin/python |
---|---|---|---|
2 | 235fe3bf | Anthony Liguori | ## |
3 | 235fe3bf | Anthony Liguori | # QEMU Object Model test tools |
4 | 235fe3bf | Anthony Liguori | # |
5 | 235fe3bf | Anthony Liguori | # Copyright IBM, Corp. 2011 |
6 | 235fe3bf | Anthony Liguori | # |
7 | 235fe3bf | Anthony Liguori | # Authors: |
8 | 235fe3bf | Anthony Liguori | # Anthony Liguori <aliguori@us.ibm.com> |
9 | 235fe3bf | Anthony Liguori | # |
10 | 235fe3bf | Anthony Liguori | # This work is licensed under the terms of the GNU GPL, version 2 or later. See |
11 | 235fe3bf | Anthony Liguori | # the COPYING file in the top-level directory. |
12 | 235fe3bf | Anthony Liguori | ## |
13 | 235fe3bf | Anthony Liguori | |
14 | 235fe3bf | Anthony Liguori | import sys |
15 | 235fe3bf | Anthony Liguori | import os |
16 | 235fe3bf | Anthony Liguori | from qmp import QEMUMonitorProtocol |
17 | 235fe3bf | Anthony Liguori | |
18 | 235fe3bf | Anthony Liguori | cmd, args = sys.argv[0], sys.argv[1:] |
19 | 235fe3bf | Anthony Liguori | socket_path = None |
20 | 235fe3bf | Anthony Liguori | path = None |
21 | 235fe3bf | Anthony Liguori | prop = None |
22 | 235fe3bf | Anthony Liguori | value = None |
23 | 235fe3bf | Anthony Liguori | |
24 | 235fe3bf | Anthony Liguori | def usage(): |
25 | 235fe3bf | Anthony Liguori | return '''environment variables: |
26 | 235fe3bf | Anthony Liguori | QMP_SOCKET=<path | addr:port> |
27 | 235fe3bf | Anthony Liguori | usage: |
28 | 235fe3bf | Anthony Liguori | %s [-h] [-s <QMP socket path | addr:port>] <path>.<property> <value> |
29 | 235fe3bf | Anthony Liguori | ''' % cmd |
30 | 235fe3bf | Anthony Liguori | |
31 | 235fe3bf | Anthony Liguori | def usage_error(error_msg = "unspecified error"): |
32 | 235fe3bf | Anthony Liguori | sys.stderr.write('%s\nERROR: %s\n' % (usage(), error_msg)) |
33 | 235fe3bf | Anthony Liguori | exit(1) |
34 | 235fe3bf | Anthony Liguori | |
35 | 235fe3bf | Anthony Liguori | if len(args) > 0: |
36 | 235fe3bf | Anthony Liguori | if args[0] == "-h": |
37 | 235fe3bf | Anthony Liguori | print usage() |
38 | 235fe3bf | Anthony Liguori | exit(0); |
39 | 235fe3bf | Anthony Liguori | elif args[0] == "-s": |
40 | 235fe3bf | Anthony Liguori | try: |
41 | 235fe3bf | Anthony Liguori | socket_path = args[1] |
42 | 235fe3bf | Anthony Liguori | except: |
43 | 235fe3bf | Anthony Liguori | usage_error("missing argument: QMP socket path or address"); |
44 | 235fe3bf | Anthony Liguori | args = args[2:] |
45 | 235fe3bf | Anthony Liguori | |
46 | 235fe3bf | Anthony Liguori | if not socket_path: |
47 | 235fe3bf | Anthony Liguori | if os.environ.has_key('QMP_SOCKET'): |
48 | 235fe3bf | Anthony Liguori | socket_path = os.environ['QMP_SOCKET'] |
49 | 235fe3bf | Anthony Liguori | else: |
50 | 235fe3bf | Anthony Liguori | usage_error("no QMP socket path or address given"); |
51 | 235fe3bf | Anthony Liguori | |
52 | 235fe3bf | Anthony Liguori | if len(args) > 1: |
53 | 235fe3bf | Anthony Liguori | try: |
54 | 235fe3bf | Anthony Liguori | path, prop = args[0].rsplit('.', 1) |
55 | 235fe3bf | Anthony Liguori | except: |
56 | 235fe3bf | Anthony Liguori | usage_error("invalid format for path/property/value") |
57 | 235fe3bf | Anthony Liguori | value = args[1] |
58 | 235fe3bf | Anthony Liguori | else: |
59 | 235fe3bf | Anthony Liguori | usage_error("not enough arguments") |
60 | 235fe3bf | Anthony Liguori | |
61 | 235fe3bf | Anthony Liguori | srv = QEMUMonitorProtocol(socket_path) |
62 | 235fe3bf | Anthony Liguori | srv.connect() |
63 | 235fe3bf | Anthony Liguori | |
64 | 235fe3bf | Anthony Liguori | print srv.command('qom-set', path=path, property=prop, value=sys.argv[2]) |