[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH RFC 26/32] python//machine.py: use qmp.command
From: |
John Snow |
Subject: |
[PATCH RFC 26/32] python//machine.py: use qmp.command |
Date: |
Thu, 14 May 2020 01:53:57 -0400 |
machine.py and qmp.py both do the same thing here; refactor machine.py
to use qmp.py's functionality more directly.
Signed-off-by: John Snow <address@hidden>
---
python/qemu/lib/machine.py | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/python/qemu/lib/machine.py b/python/qemu/lib/machine.py
index 61ee3a0e81..34e6b6f9e9 100644
--- a/python/qemu/lib/machine.py
+++ b/python/qemu/lib/machine.py
@@ -25,6 +25,8 @@
import socket
import tempfile
from typing import (
+ Any,
+ Dict,
List,
Optional,
Type,
@@ -416,17 +418,23 @@ def set_qmp_monitor(self, enabled=True):
self._qmp_set = False
self._qmp = None
- def qmp(self, cmd, conv_keys=True, **args):
- """
- Invoke a QMP command and return the response dict
- """
+ @classmethod
+ def _qmp_args(cls, _conv_keys: bool = True, **args: Any) -> Dict[str, Any]:
qmp_args = dict()
for key, value in args.items():
- if conv_keys:
+ if _conv_keys:
qmp_args[key.replace('_', '-')] = value
else:
qmp_args[key] = value
+ return qmp_args
+ def qmp(self, cmd: str,
+ conv_keys: bool = True,
+ **args: Any) -> QMPMessage:
+ """
+ Invoke a QMP command and return the response dict
+ """
+ qmp_args = self._qmp_args(conv_keys, **args)
return self._qmp.cmd(cmd, args=qmp_args)
def command(self, cmd, conv_keys=True, **args):
@@ -435,12 +443,8 @@ def command(self, cmd, conv_keys=True, **args):
On success return the response dict.
On failure raise an exception.
"""
- reply = self.qmp(cmd, conv_keys, **args)
- if reply is None:
- raise qmp.QMPError("Monitor is closed")
- if "error" in reply:
- raise qmp.QMPResponseError(reply)
- return reply["return"]
+ qmp_args = self._qmp_args(conv_keys, **args)
+ return self._qmp.command(cmd, **qmp_args)
def get_qmp_event(self, wait=False):
"""
--
2.21.1
- Re: [PATCH RFC 20/32] python//qmp.py: assert sockfile is not None, (continued)
- [PATCH RFC 21/32] python//machine.py: remove logging configuration, John Snow, 2020/05/14
- [PATCH RFC 22/32] python//machine.py: Fix monitor address typing, John Snow, 2020/05/14
- [PATCH RFC 23/32] python//machine.py: reorder __init__, John Snow, 2020/05/14
- [PATCH RFC 24/32] python//machine.py: Don't modify state in _base_args(), John Snow, 2020/05/14
- [PATCH RFC 25/32] python//machine.py: Handle None events in event_wait, John Snow, 2020/05/14
- [PATCH RFC 26/32] python//machine.py: use qmp.command,
John Snow <=
- [PATCH RFC 28/32] python//machine.py: fix _popen access, John Snow, 2020/05/14
- [PATCH RFC 27/32] python//machine.py: Add _qmp access shim, John Snow, 2020/05/14
- [PATCH RFC 29/32] python//qtest.py: Check before accessing _qtest, John Snow, 2020/05/14
- [PATCH RFC 12/32] python/qemu/lib: fix socket.makefile() typing, John Snow, 2020/05/14
- [PATCH RFC 31/32] python/qemu: add mypy to Pipfile, John Snow, 2020/05/14
- [PATCH RFC 19/32] python//qmp.py: add QMPProtocolError, John Snow, 2020/05/14