source: ogClient-Git/src/virtual/poweroffd.py @ 1ab981a

Last change on this file since 1ab981a was 0c00f64, checked in by OpenGnSys Support Team <soporte-og@…>, 4 years ago

#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.

  • Property mode set to 100644
File size: 1.3 KB
Line 
1#
2# Copyright (C) 2021 Soleta Networks <info@soleta.eu>
3#
4# This program is free software: you can redistribute it and/or modify it under
5# the terms of the GNU Affero General Public License as published by the
6# Free Software Foundation; either version 3 of the License, or
7# (at your option) any later version.
8
9
10from src.virtual.qmp import QEMUMonitorProtocol
11from src.virtual.qmp import QMPCapabilitiesError, QMPConnectError
12
13QMP_DEFAULT_PORT = 4445
14QMP_DEFAULT_HOST = "127.0.0.1"
15
16def is_shutdown_event(qmp_ev):
17    """
18    """
19    return qmp_ev.get('event') == 'SHUTDOWN'
20
21
22def init(host=QMP_DEFAULT_HOST, port=QMP_DEFAULT_PORT):
23    """
24    """
25    qmpconn = QEMUMonitorProtocol((host, port))
26    try:
27        qmpconn.connect()
28    except ConnectionRefusedError:
29        print("Critical err: Connection refused")
30        return None
31    except QMPCapabilitiesError as e:
32        print("Error negotiating capabilities")
33        return None
34    return qmpconn
35
36
37def run(qmpconn):
38    """
39    """
40    while(True):
41        try:
42            qmp_ev = qmpconn.pull_event(wait=True)
43        except QMPConnectError as e:
44            print("Error trying to pull an event")
45            ret = -1
46            break
47        if is_shutdown_event(qmp_ev):
48            print("Detected guest shutdown, let's go")
49            ret = 0
50            break
51
52    qmpconn.close()
53    return ret
Note: See TracBrowser for help on using the repository browser.