summaryrefslogtreecommitdiffstats
path: root/src/virtual/ogOperations.py
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2021-09-01 13:13:39 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2021-09-01 13:29:58 +0200
commit0c00f64669bfbdb6bde8e5cb7cfc205dec284e50 (patch)
tree3439f9c75282c0fa4e8cfe4ac88bc0fdd422b292 /src/virtual/ogOperations.py
parent082079ad78979efc163f785811dfd56deb078059 (diff)
#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.
Diffstat (limited to 'src/virtual/ogOperations.py')
-rw-r--r--src/virtual/ogOperations.py21
1 files changed, 13 insertions, 8 deletions
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