build: always include sanitytest in tarball
[libvirt-python/ericb.git] / libvirt-override-virConnect.py
blob5495b70f267f49fbe92ba162d5c12ca54e4dc435
1 def __del__(self):
2 try:
3 for cb,opaque in self.domainEventCallbacks.items():
4 del self.domainEventCallbacks[cb]
5 del self.domainEventCallbacks
6 libvirtmod.virConnectDomainEventDeregister(self._o, self)
7 except AttributeError:
8 pass
10 if self._o != None:
11 libvirtmod.virConnectClose(self._o)
12 self._o = None
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 """
17 try:
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:
24 pass
26 def domainEventRegister(self, cb, opaque):
27 """Adds a Domain Event Callback. Registering for a domain
28 callback will enable delivery of the events """
29 try:
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
38 """
39 try:
40 for cb,opaque in self.domainEventCallbacks.items():
41 cb(self,dom,event,detail,opaque)
42 return 0
43 except AttributeError:
44 pass
46 def _dispatchDomainEventLifecycleCallback(self, dom, event, detail, cbData):
47 """Dispatches events to python user domain lifecycle event callbacks
48 """
49 cb = cbData["cb"]
50 opaque = cbData["opaque"]
52 cb(self, virDomain(self, _obj=dom), event, detail, opaque)
53 return 0
55 def _dispatchDomainEventGenericCallback(self, dom, cbData):
56 """Dispatches events to python user domain generic event callbacks
57 """
58 cb = cbData["cb"]
59 opaque = cbData["opaque"]
61 cb(self, virDomain(self, _obj=dom), opaque)
62 return 0
64 def _dispatchDomainEventRTCChangeCallback(self, dom, offset, cbData):
65 """Dispatches events to python user domain RTC change event callbacks
66 """
67 cb = cbData["cb"]
68 opaque = cbData["opaque"]
70 cb(self, virDomain(self, _obj=dom), offset ,opaque)
71 return 0
73 def _dispatchDomainEventWatchdogCallback(self, dom, action, cbData):
74 """Dispatches events to python user domain watchdog event callbacks
75 """
76 cb = cbData["cb"]
77 opaque = cbData["opaque"]
79 cb(self, virDomain(self, _obj=dom), action, opaque)
80 return 0
82 def _dispatchDomainEventIOErrorCallback(self, dom, srcPath, devAlias,
83 action, cbData):
84 """Dispatches events to python user domain IO error event callbacks
85 """
86 cb = cbData["cb"]
87 opaque = cbData["opaque"]
89 cb(self, virDomain(self, _obj=dom), srcPath, devAlias, action, opaque)
90 return 0
92 def _dispatchDomainEventIOErrorReasonCallback(self, dom, srcPath,
93 devAlias, action, reason,
94 cbData):
95 """Dispatches events to python user domain IO error event callbacks
96 """
97 cb = cbData["cb"]
98 opaque = cbData["opaque"]
100 cb(self, virDomain(self, _obj=dom), srcPath, devAlias, action,
101 reason, opaque)
102 return 0
104 def _dispatchDomainEventGraphicsCallback(self, dom, phase, localAddr,
105 remoteAddr, authScheme, subject,
106 cbData):
107 """Dispatches events to python user domain graphics event callbacks
109 cb = cbData["cb"]
110 opaque = cbData["opaque"]
112 cb(self, virDomain(self, _obj=dom), phase, localAddr, remoteAddr,
113 authScheme, subject, opaque)
114 return 0
116 def dispatchDomainEventBlockPullCallback(self, dom, path, type, status, cbData):
117 """Dispatches events to python user domain blockJob event callbacks
119 try:
120 cb = cbData["cb"]
121 opaque = cbData["opaque"]
123 cb(self, virDomain(self, _obj=dom), path, type, status, opaque)
124 return 0
125 except AttributeError:
126 pass
128 def _dispatchDomainEventDiskChangeCallback(self, dom, oldSrcPath, newSrcPath, devAlias, reason, cbData):
129 """Dispatches event to python user domain diskChange event callbacks
131 cb = cbData["cb"]
132 opaque = cbData["opaque"]
134 cb(self, virDomain(self, _obj=dom), oldSrcPath, newSrcPath, devAlias, reason, opaque)
135 return 0
137 def _dispatchDomainEventTrayChangeCallback(self, dom, devAlias, reason, cbData):
138 """Dispatches event to python user domain trayChange event callbacks
140 cb = cbData["cb"]
141 opaque = cbData["opaque"]
143 cb(self, virDomain(self, _obj=dom), devAlias, reason, opaque)
144 return 0
146 def _dispatchDomainEventPMWakeupCallback(self, dom, reason, cbData):
147 """Dispatches event to python user domain pmwakeup event callbacks
149 cb = cbData["cb"]
150 opaque = cbData["opaque"]
152 cb(self, virDomain(self, _obj=dom), reason, opaque)
153 return 0
155 def _dispatchDomainEventPMSuspendCallback(self, dom, reason, cbData):
156 """Dispatches event to python user domain pmsuspend event callbacks
158 cb = cbData["cb"]
159 opaque = cbData["opaque"]
161 cb(self, virDomain(self, _obj=dom), reason, opaque)
162 return 0
164 def _dispatchDomainEventBalloonChangeCallback(self, dom, actual, cbData):
165 """Dispatches events to python user domain balloon change event callbacks
167 cb = cbData["cb"]
168 opaque = cbData["opaque"]
170 cb(self, virDomain(self, _obj=dom), actual, opaque)
171 return 0
173 def _dispatchDomainEventPMSuspendDiskCallback(self, dom, reason, cbData):
174 """Dispatches event to python user domain pmsuspend-disk event callbacks
176 cb = cbData["cb"]
177 opaque = cbData["opaque"]
179 cb(self, virDomain(self, _obj=dom), reason, opaque)
180 return 0
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 """
185 try:
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:
190 pass
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 }
198 if dom is None:
199 ret = libvirtmod.virConnectDomainEventRegisterAny(self._o, None, eventID, cbData)
200 else:
201 ret = libvirtmod.virConnectDomainEventRegisterAny(self._o, dom._o, eventID, cbData)
202 if ret == -1:
203 raise libvirtError ('virConnectDomainEventRegisterAny() failed', conn=self)
204 self.domainEventCallbackID[ret] = opaque
205 return ret
207 def listAllDomains(self, flags=0):
208 """List all domains and returns a list of domain objects"""
209 ret = libvirtmod.virConnectListAllDomains(self._o, flags)
210 if ret is None:
211 raise libvirtError("virConnectListAllDomains() failed", conn=self)
213 retlist = list()
214 for domptr in ret:
215 retlist.append(virDomain(self, _obj=domptr))
217 return retlist
219 def listAllStoragePools(self, flags=0):
220 """Returns a list of storage pool objects"""
221 ret = libvirtmod.virConnectListAllStoragePools(self._o, flags)
222 if ret is None:
223 raise libvirtError("virConnectListAllStoragePools() failed", conn=self)
225 retlist = list()
226 for poolptr in ret:
227 retlist.append(virStoragePool(self, _obj=poolptr))
229 return retlist
231 def listAllNetworks(self, flags=0):
232 """Returns a list of network objects"""
233 ret = libvirtmod.virConnectListAllNetworks(self._o, flags)
234 if ret is None:
235 raise libvirtError("virConnectListAllNetworks() failed", conn=self)
237 retlist = list()
238 for netptr in ret:
239 retlist.append(virNetwork(self, _obj=netptr))
241 return retlist
243 def listAllInterfaces(self, flags=0):
244 """Returns a list of interface objects"""
245 ret = libvirtmod.virConnectListAllInterfaces(self._o, flags)
246 if ret is None:
247 raise libvirtError("virConnectListAllInterfaces() failed", conn=self)
249 retlist = list()
250 for ifaceptr in ret:
251 retlist.append(virInterface(self, _obj=ifaceptr))
253 return retlist
255 def listAllDevices(self, flags=0):
256 """Returns a list of host node device objects"""
257 ret = libvirtmod.virConnectListAllNodeDevices(self._o, flags)
258 if ret is None:
259 raise libvirtError("virConnectListAllNodeDevices() failed", conn=self)
261 retlist = list()
262 for devptr in ret:
263 retlist.append(virNodeDevice(self, _obj=devptr))
265 return retlist
267 def listAllNWFilters(self, flags=0):
268 """Returns a list of network filter objects"""
269 ret = libvirtmod.virConnectListAllNWFilters(self._o, flags)
270 if ret is None:
271 raise libvirtError("virConnectListAllNWFilters() failed", conn=self)
273 retlist = list()
274 for filter_ptr in ret:
275 retlist.append(virNWFilter(self, _obj=filter_ptr))
277 return retlist
279 def listAllSecrets(self, flags=0):
280 """Returns a list of secret objects"""
281 ret = libvirtmod.virConnectListAllSecrets(self._o, flags)
282 if ret is None:
283 raise libvirtError("virConnectListAllSecrets() failed", conn=self)
285 retlist = list()
286 for secret_ptr in ret:
287 retlist.append(virSecret(self, _obj=secret_ptr))
289 return retlist
291 def _dispatchCloseCallback(self, reason, cbData):
292 """Dispatches events to python user close callback"""
293 cb = cbData["cb"]
294 opaque = cbData["opaque"]
296 cb(self, reason, opaque)
297 return 0
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)
310 if ret == -1:
311 raise libvirtError ('virConnectRegisterCloseCallback() failed', conn=self)
312 return ret