3 for cb
,opaque
in self
.domainEventCallbacks
.items():
4 del self
.domainEventCallbacks
[cb
]
5 del self
.domainEventCallbacks
6 libvirtmod
.virConnectDomainEventDeregister(self
._o
, self
)
11 libvirtmod
.virConnectClose(self
._o
)
14 def domainEventDeregister(self
, cb
):
15 """Removes a Domain Event Callback. De-registering for a
16 domain callback will disable delivery of this event type """
18 del self
.domainEventCallbacks
[cb
]
19 if len(self
.domainEventCallbacks
) == 0:
20 del self
.domainEventCallbacks
21 ret
= libvirtmod
.virConnectDomainEventDeregister(self
._o
, self
)
22 if ret
== -1: raise libvirtError ('virConnectDomainEventDeregister() failed', conn
=self
)
23 except AttributeError:
26 def domainEventRegister(self
, cb
, opaque
):
27 """Adds a Domain Event Callback. Registering for a domain
28 callback will enable delivery of the events """
30 self
.domainEventCallbacks
[cb
] = opaque
31 except AttributeError:
32 self
.domainEventCallbacks
= {cb
:opaque
}
33 ret
= libvirtmod
.virConnectDomainEventRegister(self
._o
, self
)
34 if ret
== -1: raise libvirtError ('virConnectDomainEventRegister() failed', conn
=self
)
36 def _dispatchDomainEventCallbacks(self
, dom
, event
, detail
):
37 """Dispatches events to python user domain event callbacks
40 for cb
,opaque
in self
.domainEventCallbacks
.items():
41 cb(self
,dom
,event
,detail
,opaque
)
43 except AttributeError:
46 def _dispatchDomainEventLifecycleCallback(self
, dom
, event
, detail
, cbData
):
47 """Dispatches events to python user domain lifecycle event callbacks
50 opaque
= cbData
["opaque"]
52 cb(self
, virDomain(self
, _obj
=dom
), event
, detail
, opaque
)
55 def _dispatchDomainEventGenericCallback(self
, dom
, cbData
):
56 """Dispatches events to python user domain generic event callbacks
59 opaque
= cbData
["opaque"]
61 cb(self
, virDomain(self
, _obj
=dom
), opaque
)
64 def _dispatchDomainEventRTCChangeCallback(self
, dom
, offset
, cbData
):
65 """Dispatches events to python user domain RTC change event callbacks
68 opaque
= cbData
["opaque"]
70 cb(self
, virDomain(self
, _obj
=dom
), offset
,opaque
)
73 def _dispatchDomainEventWatchdogCallback(self
, dom
, action
, cbData
):
74 """Dispatches events to python user domain watchdog event callbacks
77 opaque
= cbData
["opaque"]
79 cb(self
, virDomain(self
, _obj
=dom
), action
, opaque
)
82 def _dispatchDomainEventIOErrorCallback(self
, dom
, srcPath
, devAlias
,
84 """Dispatches events to python user domain IO error event callbacks
87 opaque
= cbData
["opaque"]
89 cb(self
, virDomain(self
, _obj
=dom
), srcPath
, devAlias
, action
, opaque
)
92 def _dispatchDomainEventIOErrorReasonCallback(self
, dom
, srcPath
,
93 devAlias
, action
, reason
,
95 """Dispatches events to python user domain IO error event callbacks
98 opaque
= cbData
["opaque"]
100 cb(self
, virDomain(self
, _obj
=dom
), srcPath
, devAlias
, action
,
104 def _dispatchDomainEventGraphicsCallback(self
, dom
, phase
, localAddr
,
105 remoteAddr
, authScheme
, subject
,
107 """Dispatches events to python user domain graphics event callbacks
110 opaque
= cbData
["opaque"]
112 cb(self
, virDomain(self
, _obj
=dom
), phase
, localAddr
, remoteAddr
,
113 authScheme
, subject
, opaque
)
116 def dispatchDomainEventBlockPullCallback(self
, dom
, path
, type, status
, cbData
):
117 """Dispatches events to python user domain blockJob event callbacks
121 opaque
= cbData
["opaque"]
123 cb(self
, virDomain(self
, _obj
=dom
), path
, type, status
, opaque
)
125 except AttributeError:
128 def _dispatchDomainEventDiskChangeCallback(self
, dom
, oldSrcPath
, newSrcPath
, devAlias
, reason
, cbData
):
129 """Dispatches event to python user domain diskChange event callbacks
132 opaque
= cbData
["opaque"]
134 cb(self
, virDomain(self
, _obj
=dom
), oldSrcPath
, newSrcPath
, devAlias
, reason
, opaque
)
137 def _dispatchDomainEventTrayChangeCallback(self
, dom
, devAlias
, reason
, cbData
):
138 """Dispatches event to python user domain trayChange event callbacks
141 opaque
= cbData
["opaque"]
143 cb(self
, virDomain(self
, _obj
=dom
), devAlias
, reason
, opaque
)
146 def _dispatchDomainEventPMWakeupCallback(self
, dom
, reason
, cbData
):
147 """Dispatches event to python user domain pmwakeup event callbacks
150 opaque
= cbData
["opaque"]
152 cb(self
, virDomain(self
, _obj
=dom
), reason
, opaque
)
155 def _dispatchDomainEventPMSuspendCallback(self
, dom
, reason
, cbData
):
156 """Dispatches event to python user domain pmsuspend event callbacks
159 opaque
= cbData
["opaque"]
161 cb(self
, virDomain(self
, _obj
=dom
), reason
, opaque
)
164 def _dispatchDomainEventBalloonChangeCallback(self
, dom
, actual
, cbData
):
165 """Dispatches events to python user domain balloon change event callbacks
168 opaque
= cbData
["opaque"]
170 cb(self
, virDomain(self
, _obj
=dom
), actual
, opaque
)
173 def _dispatchDomainEventPMSuspendDiskCallback(self
, dom
, reason
, cbData
):
174 """Dispatches event to python user domain pmsuspend-disk event callbacks
177 opaque
= cbData
["opaque"]
179 cb(self
, virDomain(self
, _obj
=dom
), reason
, opaque
)
182 def domainEventDeregisterAny(self
, callbackID
):
183 """Removes a Domain Event Callback. De-registering for a
184 domain callback will disable delivery of this event type """
186 ret
= libvirtmod
.virConnectDomainEventDeregisterAny(self
._o
, callbackID
)
187 if ret
== -1: raise libvirtError ('virConnectDomainEventDeregisterAny() failed', conn
=self
)
188 del self
.domainEventCallbackID
[callbackID
]
189 except AttributeError:
192 def domainEventRegisterAny(self
, dom
, eventID
, cb
, opaque
):
193 """Adds a Domain Event Callback. Registering for a domain
194 callback will enable delivery of the events """
195 if not hasattr(self
, 'domainEventCallbackID'):
196 self
.domainEventCallbackID
= {}
197 cbData
= { "cb": cb
, "conn": self
, "opaque": opaque
}
199 ret
= libvirtmod
.virConnectDomainEventRegisterAny(self
._o
, None, eventID
, cbData
)
201 ret
= libvirtmod
.virConnectDomainEventRegisterAny(self
._o
, dom
._o
, eventID
, cbData
)
203 raise libvirtError ('virConnectDomainEventRegisterAny() failed', conn
=self
)
204 self
.domainEventCallbackID
[ret
] = opaque
207 def listAllDomains(self
, flags
):
208 """List all domains and returns a list of domain objects"""
209 ret
= libvirtmod
.virConnectListAllDomains(self
._o
, flags
)
211 raise libvirtError("virConnectListAllDomains() failed", conn
=self
)
215 retlist
.append(virDomain(self
, _obj
=domptr
))
219 def listAllStoragePools(self
, flags
):
220 """Returns a list of storage pool objects"""
221 ret
= libvirtmod
.virConnectListAllStoragePools(self
._o
, flags
)
223 raise libvirtError("virConnectListAllStoragePools() failed", conn
=self
)
227 retlist
.append(virStoragePool(self
, _obj
=poolptr
))
231 def listAllNetworks(self
, flags
):
232 """Returns a list of network objects"""
233 ret
= libvirtmod
.virConnectListAllNetworks(self
._o
, flags
)
235 raise libvirtError("virConnectListAllNetworks() failed", conn
=self
)
239 retlist
.append(virNetwork(self
, _obj
=netptr
))
243 def listAllInterfaces(self
, flags
):
244 """Returns a list of interface objects"""
245 ret
= libvirtmod
.virConnectListAllInterfaces(self
._o
, flags
)
247 raise libvirtError("virConnectListAllInterfaces() failed", conn
=self
)
251 retlist
.append(virInterface(self
, _obj
=ifaceptr
))
255 def listAllDevices(self
, flags
):
256 """Returns a list of host node device objects"""
257 ret
= libvirtmod
.virConnectListAllNodeDevices(self
._o
, flags
)
259 raise libvirtError("virConnectListAllNodeDevices() failed", conn
=self
)
263 retlist
.append(virNodeDevice(self
, _obj
=devptr
))
267 def listAllNWFilters(self
, flags
):
268 """Returns a list of network filter objects"""
269 ret
= libvirtmod
.virConnectListAllNWFilters(self
._o
, flags
)
271 raise libvirtError("virConnectListAllNWFilters() failed", conn
=self
)
274 for filter_ptr
in ret
:
275 retlist
.append(virNWFilter(self
, _obj
=filter_ptr
))
279 def listAllSecrets(self
, flags
):
280 """Returns a list of secret objects"""
281 ret
= libvirtmod
.virConnectListAllSecrets(self
._o
, flags
)
283 raise libvirtError("virConnectListAllSecrets() failed", conn
=self
)
286 for secret_ptr
in ret
:
287 retlist
.append(virSecret(self
, _obj
=secret_ptr
))
291 def _dispatchCloseCallback(self
, reason
, cbData
):
292 """Dispatches events to python user close callback"""
294 opaque
= cbData
["opaque"]
296 cb(self
, reason
, opaque
)
300 def unregisterCloseCallback(self
):
301 """Removes a close event callback"""
302 ret
= libvirtmod
.virConnectUnregisterCloseCallback(self
._o
)
303 if ret
== -1: raise libvirtError ('virConnectUnregisterCloseCallback() failed', conn
=self
)
305 def registerCloseCallback(self
, cb
, opaque
):
306 """Adds a close event callback, providing a notification
307 when a connection fails / closes"""
308 cbData
= { "cb": cb
, "conn": self
, "opaque": opaque
}
309 ret
= libvirtmod
.virConnectRegisterCloseCallback(self
._o
, cbData
)
311 raise libvirtError ('virConnectRegisterCloseCallback() failed', conn
=self
)