[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 11/16] python/machine.py: use qmp.command
From: |
John Snow |
Subject: |
[PATCH v3 11/16] python/machine.py: use qmp.command |
Date: |
Thu, 4 Jun 2020 16:22:31 -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 <jsnow@redhat.com>
---
python/qemu/machine.py | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/python/qemu/machine.py b/python/qemu/machine.py
index 4afd67a9351..d8289936816 100644
--- a/python/qemu/machine.py
+++ b/python/qemu/machine.py
@@ -26,6 +26,8 @@
import socket
import tempfile
from typing import (
+ Any,
+ Dict,
List,
Optional,
Type,
@@ -455,17 +457,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):
@@ -474,12 +482,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.3
- [PATCH v3 07/16] python/machine.py: Fix monitor address typing, (continued)
[PATCH v3 10/16] python/machine.py: Handle None events in events_wait, John Snow, 2020/06/04
[PATCH v3 11/16] python/machine.py: use qmp.command,
John Snow <=
[PATCH v3 15/16] iotests.py: Adjust HMP kwargs typing, John Snow, 2020/06/04
[PATCH v3 13/16] python/machine.py: fix _popen access, John Snow, 2020/06/04
[PATCH v3 14/16] python/qemu: make 'args' style arguments immutable, John Snow, 2020/06/04
[PATCH v3 16/16] python/qemu: Add mypy type annotations, John Snow, 2020/06/04
[PATCH v3 01/16] python/qmp.py: Define common types, John Snow, 2020/06/04
Re: [PATCH v3 00/16] python: add mypy support to python/qemu, Kevin Wolf, 2020/06/05