From 0c00f64669bfbdb6bde8e5cb7cfc205dec284e50 Mon Sep 17 00:00:00 2001 From: "Jose M. Guisado" Date: Wed, 1 Sep 2021 13:13:39 +0200 Subject: #1059 virtual: replace qmp polling for event listening Polling for a qmp port availability is undesirable, as QEMU only handles one connection to the qmp port at a time, ogClient may interfere with cloneer-manager. Check vm thread now connects to a separate qmp tcp socket, listening for a shutdown guest event. When ogClient is run just after ogVDI installation (before guest installation) it will try to connect until it's possible, ie: after an iso is specified and a qemu vm is started that exposes the appropiate qmp tcp port. --- src/virtual/ogOperations.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/virtual/ogOperations.py') diff --git a/src/virtual/ogOperations.py b/src/virtual/ogOperations.py index 5da735e..a3f94a8 100644 --- a/src/virtual/ogOperations.py +++ b/src/virtual/ogOperations.py @@ -7,6 +7,7 @@ # (at your option) any later version. from src.ogRest import ThreadState +from src.virtual import poweroffd import socket import errno import select @@ -223,15 +224,19 @@ class OgVirtualOperations: return installed_os def check_vm_state_loop(self, ogRest): - POLLING_WAIT_TIME = 12 + # If we can't connect, wait until it's possible. while True: - time.sleep(POLLING_WAIT_TIME) - state = self.check_vm_state() - installed_os = self.get_installed_os() - if state == OgVM.State.STOPPED and \ - ogRest.state == ThreadState.IDLE and \ - len(installed_os) > 0: - self.poweroff_host() + try: + with socket.create_connection((poweroffd.QMP_DEFAULT_HOST, + poweroffd.QMP_DEFAULT_PORT)): + break + except ConnectionRefusedError: + time.sleep(1) + + qmpconn = poweroffd.init() + if poweroffd.run(qmpconn) < 0: + return + self.poweroff_host() def shellrun(self, request, ogRest): return -- cgit v1.2.3-18-g5258