Revision d9982f38 lib/hypervisor/hv_kvm/__init__.py
b/lib/hypervisor/hv_kvm/__init__.py | ||
---|---|---|
118 | 118 |
def _with_qmp(fn): |
119 | 119 |
"""Wrapper used on hotplug related methods""" |
120 | 120 |
def wrapper(self, instance, *args, **kwargs): |
121 |
"""Open a QmpConnection, run the wrapped method and then close it""" |
|
122 |
conn_created = False |
|
121 |
"""Create a QmpConnection and run the wrapped method""" |
|
123 | 122 |
if not getattr(self, "qmp", None): |
124 | 123 |
filename = self._InstanceQmpMonitor(instance.name)# pylint: disable=W0212 |
125 | 124 |
self.qmp = QmpConnection(filename) |
126 |
conn_created = True |
|
127 |
|
|
128 |
self.qmp.connect() |
|
129 |
try: |
|
130 |
ret = fn(self, instance, *args, **kwargs) |
|
131 |
finally: |
|
132 |
if conn_created = True: |
|
133 |
self.qmp.close() |
|
134 |
return ret |
|
125 |
return fn(self, instance, *args, **kwargs) |
|
135 | 126 |
return wrapper |
136 | 127 |
|
137 | 128 |
|
Also available in: Unified diff