Disable Python 2 on future RHEL and Fedora > 29
[libvirt-python/ericb.git] / libvirt-override-virConnect.py
blobf26e65a99ee13de8a79800131b8b3b30068f003c
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 is not 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, virDomain(self, _obj=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 _dispatchDomainEventBlockJobCallback(self, dom, disk, type, status, cbData):
117 """Dispatches events to python user domain blockJob/blockJob2 event callbacks
119 try:
120 cb = cbData["cb"]
121 opaque = cbData["opaque"]
123 cb(self, virDomain(self, _obj=dom), disk, 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 _dispatchDomainEventDeviceRemovedCallback(self, dom, devAlias, cbData):
183 """Dispatches event to python user domain device removed event callbacks
185 cb = cbData["cb"]
186 opaque = cbData["opaque"]
188 cb(self, virDomain(self, _obj=dom), devAlias, opaque)
189 return 0
191 def _dispatchDomainEventTunableCallback(self, dom, params, cbData):
192 """Dispatches event to python user domain tunable event callbacks
194 cb = cbData["cb"]
195 opaque = cbData["opaque"]
197 cb(self, virDomain(self, _obj=dom), params, opaque)
198 return 0
200 def _dispatchDomainEventAgentLifecycleCallback(self, dom, state, reason, cbData):
201 """Dispatches event to python user domain agent lifecycle event callback
204 cb = cbData["cb"]
205 opaque = cbData["opaque"]
207 cb(self, virDomain(self, _obj=dom), state, reason, opaque)
208 return 0
210 def _dispatchDomainEventDeviceAddedCallback(self, dom, devAlias, cbData):
211 """Dispatches event to python user domain device added event callbacks
213 cb = cbData["cb"]
214 opaque = cbData["opaque"]
216 cb(self, virDomain(self, _obj=dom), devAlias, opaque)
217 return 0
219 def _dispatchDomainEventMigrationIterationCallback(self, dom, iteration, cbData):
220 """Dispatches event to python user domain migration iteration event callbacks
222 cb = cbData["cb"]
223 opaque = cbData["opaque"]
225 cb(self, virDomain(self, _obj=dom), iteration, opaque)
226 return 0
228 def _dispatchDomainEventJobCompletedCallback(self, dom, params, cbData):
229 """Dispatches event to python user domain job completed callbacks
231 cb = cbData["cb"]
232 opaque = cbData["opaque"]
234 cb(self, virDomain(self, _obj=dom), params, opaque)
235 return 0
237 def _dispatchDomainEventDeviceRemovalFailedCallback(self, dom, devAlias, cbData):
238 """Dispatches event to python user domain device removal failed event callbacks
240 cb = cbData["cb"]
241 opaque = cbData["opaque"]
243 cb(self, virDomain(self, _obj=dom), devAlias, opaque)
244 return 0
246 def _dispatchDomainEventMetadataChangeCallback(self, dom, mtype, nsuri, cbData):
247 """Dispatches event to python user domain metadata change event callbacks
249 cb = cbData["cb"]
250 opaque = cbData["opaque"]
252 cb(self, virDomain(self, _obj=dom), mtype, nsuri, opaque)
253 return 0
255 def _dispatchDomainEventBlockThresholdCallback(self, dom, dev, path, threshold, excess, cbData):
256 """Dispatches event to python user domain block device threshold event callbacks
258 cb = cbData["cb"]
259 opaque = cbData["opaque"]
261 cb(self, virDomain(self, _obj=dom), dev, path, threshold, excess, opaque)
262 return 0
264 def domainEventDeregisterAny(self, callbackID):
265 """Removes a Domain Event Callback. De-registering for a
266 domain callback will disable delivery of this event type """
267 try:
268 ret = libvirtmod.virConnectDomainEventDeregisterAny(self._o, callbackID)
269 if ret == -1: raise libvirtError ('virConnectDomainEventDeregisterAny() failed', conn=self)
270 del self.domainEventCallbackID[callbackID]
271 except AttributeError:
272 pass
274 def _dispatchNetworkEventLifecycleCallback(self, net, event, detail, cbData):
275 """Dispatches events to python user network lifecycle event callbacks
277 cb = cbData["cb"]
278 opaque = cbData["opaque"]
280 cb(self, virNetwork(self, _obj=net), event, detail, opaque)
281 return 0
283 def networkEventDeregisterAny(self, callbackID):
284 """Removes a Network Event Callback. De-registering for a
285 network callback will disable delivery of this event type"""
286 try:
287 ret = libvirtmod.virConnectNetworkEventDeregisterAny(self._o, callbackID)
288 if ret == -1: raise libvirtError ('virConnectNetworkEventDeregisterAny() failed', conn=self)
289 del self.networkEventCallbackID[callbackID]
290 except AttributeError:
291 pass
293 def networkEventRegisterAny(self, net, eventID, cb, opaque):
294 """Adds a Network Event Callback. Registering for a network
295 callback will enable delivery of the events"""
296 if not hasattr(self, 'networkEventCallbackID'):
297 self.networkEventCallbackID = {}
298 cbData = { "cb": cb, "conn": self, "opaque": opaque }
299 if net is None:
300 ret = libvirtmod.virConnectNetworkEventRegisterAny(self._o, None, eventID, cbData)
301 else:
302 ret = libvirtmod.virConnectNetworkEventRegisterAny(self._o, net._o, eventID, cbData)
303 if ret == -1:
304 raise libvirtError ('virConnectNetworkEventRegisterAny() failed', conn=self)
305 self.networkEventCallbackID[ret] = opaque
306 return ret
308 def domainEventRegisterAny(self, dom, eventID, cb, opaque):
309 """Adds a Domain Event Callback. Registering for a domain
310 callback will enable delivery of the events """
311 if not hasattr(self, 'domainEventCallbackID'):
312 self.domainEventCallbackID = {}
313 cbData = { "cb": cb, "conn": self, "opaque": opaque }
314 if dom is None:
315 ret = libvirtmod.virConnectDomainEventRegisterAny(self._o, None, eventID, cbData)
316 else:
317 ret = libvirtmod.virConnectDomainEventRegisterAny(self._o, dom._o, eventID, cbData)
318 if ret == -1:
319 raise libvirtError ('virConnectDomainEventRegisterAny() failed', conn=self)
320 self.domainEventCallbackID[ret] = opaque
321 return ret
323 def _dispatchStoragePoolEventLifecycleCallback(self, pool, event, detail, cbData):
324 """Dispatches events to python user storage pool
325 lifecycle event callbacks
327 cb = cbData["cb"]
328 opaque = cbData["opaque"]
330 cb(self, virStoragePool(self, _obj=pool), event, detail, opaque)
331 return 0
333 def _dispatchStoragePoolEventGenericCallback(self, pool, cbData):
334 """Dispatches events to python user storage pool
335 generic event callbacks
337 cb = cbData["cb"]
338 opaque = cbData["opaque"]
340 cb(self, virStoragePool(self, _obj=pool), opaque)
341 return 0
343 def storagePoolEventDeregisterAny(self, callbackID):
344 """Removes a Storage Pool Event Callback. De-registering for a
345 storage pool callback will disable delivery of this event type"""
346 try:
347 ret = libvirtmod.virConnectStoragePoolEventDeregisterAny(self._o, callbackID)
348 if ret == -1: raise libvirtError ('virConnectStoragePoolEventDeregisterAny() failed', conn=self)
349 del self.storagePoolEventCallbackID[callbackID]
350 except AttributeError:
351 pass
353 def storagePoolEventRegisterAny(self, pool, eventID, cb, opaque):
354 """Adds a Storage Pool Event Callback. Registering for a storage pool
355 callback will enable delivery of the events"""
356 if not hasattr(self, 'storagePoolEventCallbackID'):
357 self.storagePoolEventCallbackID = {}
358 cbData = { "cb": cb, "conn": self, "opaque": opaque }
359 if pool is None:
360 ret = libvirtmod.virConnectStoragePoolEventRegisterAny(self._o, None, eventID, cbData)
361 else:
362 ret = libvirtmod.virConnectStoragePoolEventRegisterAny(self._o, pool._o, eventID, cbData)
363 if ret == -1:
364 raise libvirtError ('virConnectStoragePoolEventRegisterAny() failed', conn=self)
365 self.storagePoolEventCallbackID[ret] = opaque
366 return ret
368 def _dispatchNodeDeviceEventLifecycleCallback(self, dev, event, detail, cbData):
369 """Dispatches events to python user node device
370 lifecycle event callbacks
372 cb = cbData["cb"]
373 opaque = cbData["opaque"]
375 cb(self, virNodeDevice(self, _obj=dev), event, detail, opaque)
376 return 0
378 def _dispatchNodeDeviceEventGenericCallback(self, dev, cbData):
379 """Dispatches events to python user node device
380 generic event callbacks
382 cb = cbData["cb"]
383 opaque = cbData["opaque"]
385 cb(self, virNodeDevice(self, _obj=dev), opaque)
386 return 0
388 def nodeDeviceEventDeregisterAny(self, callbackID):
389 """Removes a Node Device Event Callback. De-registering for a
390 node device callback will disable delivery of this event type"""
391 try:
392 ret = libvirtmod.virConnectNodeDeviceEventDeregisterAny(self._o, callbackID)
393 if ret == -1: raise libvirtError ('virConnectNodeDeviceEventDeregisterAny() failed', conn=self)
394 del self.nodeDeviceEventCallbackID[callbackID]
395 except AttributeError:
396 pass
398 def nodeDeviceEventRegisterAny(self, dev, eventID, cb, opaque):
399 """Adds a Node Device Event Callback. Registering for a node device
400 callback will enable delivery of the events"""
401 if not hasattr(self, 'nodeDeviceEventCallbackID'):
402 self.nodeDeviceEventCallbackID = {}
403 cbData = { "cb": cb, "conn": self, "opaque": opaque }
404 if dev is None:
405 ret = libvirtmod.virConnectNodeDeviceEventRegisterAny(self._o, None, eventID, cbData)
406 else:
407 ret = libvirtmod.virConnectNodeDeviceEventRegisterAny(self._o, dev._o, eventID, cbData)
408 if ret == -1:
409 raise libvirtError ('virConnectNodeDeviceEventRegisterAny() failed', conn=self)
410 self.nodeDeviceEventCallbackID[ret] = opaque
411 return ret
413 def _dispatchSecretEventLifecycleCallback(self, secret, event, detail, cbData):
414 """Dispatches events to python user secret lifecycle event callbacks
416 cb = cbData["cb"]
417 opaque = cbData["opaque"]
419 cb(self, virSecret(self, _obj=secret), event, detail, opaque)
420 return 0
422 def _dispatchSecretEventGenericCallback(self, secret, cbData):
423 """Dispatches events to python user secret generic event callbacks
425 cb = cbData["cb"]
426 opaque = cbData["opaque"]
428 cb(self, virSecret(self, _obj=secret), opaque)
429 return 0
431 def secretEventDeregisterAny(self, callbackID):
432 """Removes a Secret Event Callback. De-registering for a
433 secret callback will disable delivery of this event type"""
434 try:
435 ret = libvirtmod.virConnectSecretEventDeregisterAny(self._o, callbackID)
436 if ret == -1: raise libvirtError ('virConnectSecretEventDeregisterAny() failed', conn=self)
437 del self.secretEventCallbackID[callbackID]
438 except AttributeError:
439 pass
441 def secretEventRegisterAny(self, secret, eventID, cb, opaque):
442 """Adds a Secret Event Callback. Registering for a secret
443 callback will enable delivery of the events"""
444 if not hasattr(self, 'secretEventCallbackID'):
445 self.secretEventCallbackID = {}
446 cbData = { "cb": cb, "conn": self, "opaque": opaque }
447 if secret is None:
448 ret = libvirtmod.virConnectSecretEventRegisterAny(self._o, None, eventID, cbData)
449 else:
450 ret = libvirtmod.virConnectSecretEventRegisterAny(self._o, secret._o, eventID, cbData)
451 if ret == -1:
452 raise libvirtError ('virConnectSecretEventRegisterAny() failed', conn=self)
453 self.secretEventCallbackID[ret] = opaque
454 return ret
456 def listAllDomains(self, flags=0):
457 """List all domains and returns a list of domain objects"""
458 ret = libvirtmod.virConnectListAllDomains(self._o, flags)
459 if ret is None:
460 raise libvirtError("virConnectListAllDomains() failed", conn=self)
462 retlist = list()
463 for domptr in ret:
464 retlist.append(virDomain(self, _obj=domptr))
466 return retlist
468 def listAllStoragePools(self, flags=0):
469 """Returns a list of storage pool objects"""
470 ret = libvirtmod.virConnectListAllStoragePools(self._o, flags)
471 if ret is None:
472 raise libvirtError("virConnectListAllStoragePools() failed", conn=self)
474 retlist = list()
475 for poolptr in ret:
476 retlist.append(virStoragePool(self, _obj=poolptr))
478 return retlist
480 def listAllNetworks(self, flags=0):
481 """Returns a list of network objects"""
482 ret = libvirtmod.virConnectListAllNetworks(self._o, flags)
483 if ret is None:
484 raise libvirtError("virConnectListAllNetworks() failed", conn=self)
486 retlist = list()
487 for netptr in ret:
488 retlist.append(virNetwork(self, _obj=netptr))
490 return retlist
492 def listAllInterfaces(self, flags=0):
493 """Returns a list of interface objects"""
494 ret = libvirtmod.virConnectListAllInterfaces(self._o, flags)
495 if ret is None:
496 raise libvirtError("virConnectListAllInterfaces() failed", conn=self)
498 retlist = list()
499 for ifaceptr in ret:
500 retlist.append(virInterface(self, _obj=ifaceptr))
502 return retlist
504 def listAllDevices(self, flags=0):
505 """Returns a list of host node device objects"""
506 ret = libvirtmod.virConnectListAllNodeDevices(self._o, flags)
507 if ret is None:
508 raise libvirtError("virConnectListAllNodeDevices() failed", conn=self)
510 retlist = list()
511 for devptr in ret:
512 retlist.append(virNodeDevice(self, _obj=devptr))
514 return retlist
516 def listAllNWFilters(self, flags=0):
517 """Returns a list of network filter objects"""
518 ret = libvirtmod.virConnectListAllNWFilters(self._o, flags)
519 if ret is None:
520 raise libvirtError("virConnectListAllNWFilters() failed", conn=self)
522 retlist = list()
523 for filter_ptr in ret:
524 retlist.append(virNWFilter(self, _obj=filter_ptr))
526 return retlist
528 def listAllSecrets(self, flags=0):
529 """Returns a list of secret objects"""
530 ret = libvirtmod.virConnectListAllSecrets(self._o, flags)
531 if ret is None:
532 raise libvirtError("virConnectListAllSecrets() failed", conn=self)
534 retlist = list()
535 for secret_ptr in ret:
536 retlist.append(virSecret(self, _obj=secret_ptr))
538 return retlist
540 def _dispatchCloseCallback(self, reason, cbData):
541 """Dispatches events to python user close callback"""
542 cb = cbData["cb"]
543 opaque = cbData["opaque"]
545 cb(self, reason, opaque)
546 return 0
549 def unregisterCloseCallback(self):
550 """Removes a close event callback"""
551 ret = libvirtmod.virConnectUnregisterCloseCallback(self._o)
552 if ret == -1: raise libvirtError ('virConnectUnregisterCloseCallback() failed', conn=self)
554 def registerCloseCallback(self, cb, opaque):
555 """Adds a close event callback, providing a notification
556 when a connection fails / closes"""
557 cbData = { "cb": cb, "conn": self, "opaque": opaque }
558 ret = libvirtmod.virConnectRegisterCloseCallback(self._o, cbData)
559 if ret == -1:
560 raise libvirtError ('virConnectRegisterCloseCallback() failed', conn=self)
561 return ret
563 def createXMLWithFiles(self, xmlDesc, files, flags=0):
564 """Launch a new guest domain, based on an XML description similar
565 to the one returned by virDomainGetXMLDesc()
566 This function may require privileged access to the hypervisor.
567 The domain is not persistent, so its definition will disappear when it
568 is destroyed, or if the host is restarted (see virDomainDefineXML() to
569 define persistent domains).
571 @files provides an array of file descriptors which will be
572 made available to the 'init' process of the guest. The file
573 handles exposed to the guest will be renumbered to start
574 from 3 (ie immediately following stderr). This is only
575 supported for guests which use container based virtualization
576 technology.
578 If the VIR_DOMAIN_START_PAUSED flag is set, the guest domain
579 will be started, but its CPUs will remain paused. The CPUs
580 can later be manually started using virDomainResume.
582 If the VIR_DOMAIN_START_AUTODESTROY flag is set, the guest
583 domain will be automatically destroyed when the virConnectPtr
584 object is finally released. This will also happen if the
585 client application crashes / loses its connection to the
586 libvirtd daemon. Any domains marked for auto destroy will
587 block attempts at migration, save-to-file, or snapshots. """
588 ret = libvirtmod.virDomainCreateXMLWithFiles(self._o, xmlDesc, files, flags)
589 if ret is None:raise libvirtError('virDomainCreateXMLWithFiles() failed', conn=self)
590 __tmp = virDomain(self,_obj=ret)
591 return __tmp
593 def getAllDomainStats(self, stats = 0, flags=0):
594 """Query statistics for all domains on a given connection.
596 Report statistics of various parameters for a running VM according to @stats
597 field. The statistics are returned as an array of structures for each queried
598 domain. The structure contains an array of typed parameters containing the
599 individual statistics. The typed parameter name for each statistic field
600 consists of a dot-separated string containing name of the requested group
601 followed by a group specific description of the statistic value.
603 The statistic groups are enabled using the @stats parameter which is a
604 binary-OR of enum virDomainStatsTypes. The following groups are available
605 (although not necessarily implemented for each hypervisor):
607 VIR_DOMAIN_STATS_STATE: Return domain state and reason for entering that
608 state. The typed parameter keys are in this format:
609 "state.state" - state of the VM, returned as int from virDomainState enum
610 "state.reason" - reason for entering given state, returned as int from
611 virDomain*Reason enum corresponding to given state.
613 Using 0 for @stats returns all stats groups supported by the given
614 hypervisor.
616 Specifying VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS as @flags makes
617 the function return error in case some of the stat types in @stats were
618 not recognized by the daemon.
620 Similarly to virConnectListAllDomains, @flags can contain various flags to
621 filter the list of domains to provide stats for.
623 VIR_CONNECT_GET_ALL_DOMAINS_STATS_ACTIVE selects online domains while
624 VIR_CONNECT_GET_ALL_DOMAINS_STATS_INACTIVE selects offline ones.
626 VIR_CONNECT_GET_ALL_DOMAINS_STATS_PERSISTENT and
627 VIR_CONNECT_GET_ALL_DOMAINS_STATS_TRANSIENT allow to filter the list
628 according to their persistence.
630 To filter the list of VMs by domain state @flags can contain
631 VIR_CONNECT_GET_ALL_DOMAINS_STATS_RUNNING,
632 VIR_CONNECT_GET_ALL_DOMAINS_STATS_PAUSED,
633 VIR_CONNECT_GET_ALL_DOMAINS_STATS_SHUTOFF and/or
634 VIR_CONNECT_GET_ALL_DOMAINS_STATS_OTHER for all other states. """
635 ret = libvirtmod.virConnectGetAllDomainStats(self._o, stats, flags)
636 if ret is None:
637 raise libvirtError("virConnectGetAllDomainStats() failed", conn=self)
639 retlist = list()
640 for elem in ret:
641 record = (virDomain(self, _obj=elem[0]) , elem[1])
642 retlist.append(record)
644 return retlist
646 def domainListGetStats(self, doms, stats=0, flags=0):
647 """ Query statistics for given domains.
649 Report statistics of various parameters for a running VM according to @stats
650 field. The statistics are returned as an array of structures for each queried
651 domain. The structure contains an array of typed parameters containing the
652 individual statistics. The typed parameter name for each statistic field
653 consists of a dot-separated string containing name of the requested group
654 followed by a group specific description of the statistic value.
656 The statistic groups are enabled using the @stats parameter which is a
657 binary-OR of enum virDomainStatsTypes. The following groups are available
658 (although not necessarily implemented for each hypervisor):
660 VIR_DOMAIN_STATS_STATE: Return domain state and reason for entering that
661 state. The typed parameter keys are in this format:
662 "state.state" - state of the VM, returned as int from virDomainState enum
663 "state.reason" - reason for entering given state, returned as int from
664 virDomain*Reason enum corresponding to given state.
666 Using 0 for @stats returns all stats groups supported by the given
667 hypervisor.
669 Specifying VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS as @flags makes
670 the function return error in case some of the stat types in @stats were
671 not recognized by the daemon.
673 Get statistics about domains provided as a list in @doms. @stats is
674 a bit field selecting requested statistics types."""
675 domlist = list()
676 for dom in doms:
677 if not isinstance(dom, virDomain):
678 raise libvirtError("domain list contains non-domain elements", conn=self)
680 domlist.append(dom._o)
682 ret = libvirtmod.virDomainListGetStats(self._o, domlist, stats, flags)
683 if ret is None:
684 raise libvirtError("virDomainListGetStats() failed", conn=self)
686 retlist = list()
687 for elem in ret:
688 record = (virDomain(self, _obj=elem[0]) , elem[1])
689 retlist.append(record)
691 return retlist