リビジョン | f3efd12930f34b9724e15d8fd2ff56a97b67219d (tree) |
---|---|
日時 | 2022-01-22 06:01:31 |
作者 | John Snow <jsnow@redh...> |
コミッター | John Snow |
python/qmp: switch qmp-shell to AQMP
We have a replacement for async QMP, but it doesn't have feature parity
yet. For now, then, port the old tool onto the new backend.
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
@@ -22,6 +22,9 @@ from .protocol import Runstate, SocketAddrT | ||
22 | 22 | from .qmp_client import QMPClient |
23 | 23 | |
24 | 24 | |
25 | +# (Temporarily) Re-export QMPBadPortError | |
26 | +QMPBadPortError = qemu.qmp.QMPBadPortError | |
27 | + | |
25 | 28 | #: QMPMessage is an entire QMP message of any kind. |
26 | 29 | QMPMessage = Dict[str, Any] |
27 | 30 |
@@ -95,8 +95,13 @@ from typing import ( | ||
95 | 95 | Sequence, |
96 | 96 | ) |
97 | 97 | |
98 | -from qemu import qmp | |
99 | -from qemu.qmp import QMPMessage | |
98 | +from qemu.aqmp import ConnectError, QMPError, SocketAddrT | |
99 | +from qemu.aqmp.legacy import ( | |
100 | + QEMUMonitorProtocol, | |
101 | + QMPBadPortError, | |
102 | + QMPMessage, | |
103 | + QMPObject, | |
104 | +) | |
100 | 105 | |
101 | 106 | |
102 | 107 | LOG = logging.getLogger(__name__) |
@@ -125,7 +130,7 @@ class QMPCompleter: | ||
125 | 130 | return None |
126 | 131 | |
127 | 132 | |
128 | -class QMPShellError(qmp.QMPError): | |
133 | +class QMPShellError(QMPError): | |
129 | 134 | """ |
130 | 135 | QMP Shell Base error class. |
131 | 136 | """ |
@@ -153,7 +158,7 @@ class FuzzyJSON(ast.NodeTransformer): | ||
153 | 158 | return node |
154 | 159 | |
155 | 160 | |
156 | -class QMPShell(qmp.QEMUMonitorProtocol): | |
161 | +class QMPShell(QEMUMonitorProtocol): | |
157 | 162 | """ |
158 | 163 | QMPShell provides a basic readline-based QMP shell. |
159 | 164 |
@@ -161,7 +166,7 @@ class QMPShell(qmp.QEMUMonitorProtocol): | ||
161 | 166 | :param pretty: Pretty-print QMP messages. |
162 | 167 | :param verbose: Echo outgoing QMP messages to console. |
163 | 168 | """ |
164 | - def __init__(self, address: qmp.SocketAddrT, | |
169 | + def __init__(self, address: SocketAddrT, | |
165 | 170 | pretty: bool = False, verbose: bool = False): |
166 | 171 | super().__init__(address) |
167 | 172 | self._greeting: Optional[QMPMessage] = None |
@@ -237,7 +242,7 @@ class QMPShell(qmp.QEMUMonitorProtocol): | ||
237 | 242 | |
238 | 243 | def _cli_expr(self, |
239 | 244 | tokens: Sequence[str], |
240 | - parent: qmp.QMPObject) -> None: | |
245 | + parent: QMPObject) -> None: | |
241 | 246 | for arg in tokens: |
242 | 247 | (key, sep, val) = arg.partition('=') |
243 | 248 | if sep != '=': |
@@ -403,7 +408,7 @@ class HMPShell(QMPShell): | ||
403 | 408 | :param pretty: Pretty-print QMP messages. |
404 | 409 | :param verbose: Echo outgoing QMP messages to console. |
405 | 410 | """ |
406 | - def __init__(self, address: qmp.SocketAddrT, | |
411 | + def __init__(self, address: SocketAddrT, | |
407 | 412 | pretty: bool = False, verbose: bool = False): |
408 | 413 | super().__init__(address, pretty, verbose) |
409 | 414 | self._cpu_index = 0 |
@@ -512,19 +517,17 @@ def main() -> None: | ||
512 | 517 | |
513 | 518 | try: |
514 | 519 | address = shell_class.parse_address(args.qmp_server) |
515 | - except qmp.QMPBadPortError: | |
520 | + except QMPBadPortError: | |
516 | 521 | parser.error(f"Bad port number: {args.qmp_server}") |
517 | 522 | return # pycharm doesn't know error() is noreturn |
518 | 523 | |
519 | 524 | with shell_class(address, args.pretty, args.verbose) as qemu: |
520 | 525 | try: |
521 | 526 | qemu.connect(negotiate=not args.skip_negotiation) |
522 | - except qmp.QMPConnectError: | |
523 | - die("Didn't get QMP greeting message") | |
524 | - except qmp.QMPCapabilitiesError: | |
525 | - die("Couldn't negotiate capabilities") | |
526 | - except OSError as err: | |
527 | - die(f"Couldn't connect to {args.qmp_server}: {err!s}") | |
527 | + except ConnectError as err: | |
528 | + if isinstance(err.exc, OSError): | |
529 | + die(f"Couldn't connect to {args.qmp_server}: {err!s}") | |
530 | + die(str(err)) | |
528 | 531 | |
529 | 532 | for _ in qemu.repl(): |
530 | 533 | pass |