mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-01 14:53:54 -06:00
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>
This commit is contained in:
parent
a3cfea92e2
commit
603a3bad4b
1 changed files with 15 additions and 3 deletions
|
@ -22,6 +22,7 @@ old interface.
|
||||||
#
|
#
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import socket
|
||||||
from types import TracebackType
|
from types import TracebackType
|
||||||
from typing import (
|
from typing import (
|
||||||
Any,
|
Any,
|
||||||
|
@ -69,22 +70,32 @@ class QEMUMonitorProtocol:
|
||||||
|
|
||||||
:param address: QEMU address, can be either a unix socket path (string)
|
:param address: QEMU address, can be either a unix socket path (string)
|
||||||
or a tuple in the form ( address, port ) for a TCP
|
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 server: Act as the socket server. (See 'accept')
|
||||||
:param nickname: Optional nickname used for logging.
|
: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,
|
server: bool = False,
|
||||||
nickname: Optional[str] = None):
|
nickname: Optional[str] = None):
|
||||||
|
|
||||||
|
assert address or sock
|
||||||
self._qmp = QMPClient(nickname)
|
self._qmp = QMPClient(nickname)
|
||||||
self._aloop = asyncio.get_event_loop()
|
self._aloop = asyncio.get_event_loop()
|
||||||
self._address = address
|
self._address = address
|
||||||
|
self._sock = sock
|
||||||
self._timeout: Optional[float] = None
|
self._timeout: Optional[float] = None
|
||||||
|
|
||||||
if server:
|
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')
|
_T = TypeVar('_T')
|
||||||
|
|
||||||
|
@ -139,6 +150,7 @@ class QEMUMonitorProtocol:
|
||||||
:return: QMP greeting dict, or None if negotiate is false
|
:return: QMP greeting dict, or None if negotiate is false
|
||||||
:raise ConnectError: on connection errors
|
:raise ConnectError: on connection errors
|
||||||
"""
|
"""
|
||||||
|
assert self._address is not None
|
||||||
self._qmp.await_greeting = negotiate
|
self._qmp.await_greeting = negotiate
|
||||||
self._qmp.negotiate = negotiate
|
self._qmp.negotiate = negotiate
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue