aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2023-01-11 12:01:00 +0400
committerJohn Snow <jsnow@redhat.com>2023-01-24 13:37:13 -0500
commit603a3bad4b9a95b524dc8d6a41b1be4d5c5cacdf (patch)
tree8a1c1123be2b0472cdc7e527d5bb0334a5ff5b5a /python
parenta3cfea92e2030926e00a2519d299384ea648e36e (diff)
downloadqemu-603a3bad4b9a95b524dc8d6a41b1be4d5c5cacdf.zip
qemu-603a3bad4b9a95b524dc8d6a41b1be4d5c5cacdf.tar.gz
qemu-603a3bad4b9a95b524dc8d6a41b1be4d5c5cacdf.tar.bz2
python/qmp/legacy: make QEMUMonitorProtocol accept a socket
Teach QEMUMonitorProtocol to accept an exisiting socket. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Message-id: 20230111080101.969151-3-marcandre.lureau@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
Diffstat (limited to 'python')
-rw-r--r--python/qemu/qmp/legacy.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/python/qemu/qmp/legacy.py b/python/qemu/qmp/legacy.py
index 1951754..8b09ee7 100644
--- a/python/qemu/qmp/legacy.py
+++ b/python/qemu/qmp/legacy.py
@@ -22,6 +22,7 @@ old interface.
#
import asyncio
+import socket
from types import TracebackType
from typing import (
Any,
@@ -69,22 +70,32 @@ class QEMUMonitorProtocol:
:param address: QEMU address, can be either a unix socket path (string)
or a tuple in the form ( address, port ) for a TCP
- connection
+ connection or None
+ :param sock: a socket or None
:param server: Act as the socket server. (See 'accept')
:param nickname: Optional nickname used for logging.
"""
- def __init__(self, address: SocketAddrT,
+ def __init__(self,
+ address: Optional[SocketAddrT] = None,
+ sock: Optional[socket.socket] = None,
server: bool = False,
nickname: Optional[str] = None):
+ assert address or sock
self._qmp = QMPClient(nickname)
self._aloop = asyncio.get_event_loop()
self._address = address
+ self._sock = sock
self._timeout: Optional[float] = None
if server:
- self._sync(self._qmp.start_server(self._address))
+ if sock:
+ assert self._sock is not None
+ self._sync(self._qmp.open_with_socket(self._sock))
+ else:
+ assert self._address is not None
+ self._sync(self._qmp.start_server(self._address))
_T = TypeVar('_T')
@@ -139,6 +150,7 @@ class QEMUMonitorProtocol:
:return: QMP greeting dict, or None if negotiate is false
:raise ConnectError: on connection errors
"""
+ assert self._address is not None
self._qmp.await_greeting = negotiate
self._qmp.negotiate = negotiate