This will allow automatic connection and socket cleanup on command completion.
Signed-off-by: Apollon Oikonomopoulos <[email protected]> --- lib/hypervisor/hv_kvm/monitor.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/hypervisor/hv_kvm/monitor.py b/lib/hypervisor/hv_kvm/monitor.py index e24d7e3..6a7ff3a 100644 --- a/lib/hypervisor/hv_kvm/monitor.py +++ b/lib/hypervisor/hv_kvm/monitor.py @@ -189,6 +189,12 @@ class QmpConnection(MonitorSocket): super(QmpConnection, self).__init__(monitor_filename) self._buf = "" + def __enter__(self): + self.connect() + + def __exit__(self, exc_type, exc_value, tb): + self.close() + def connect(self): """Connects to the QMP monitor. -- 1.9.1
