Add missing impl of virNetworkListAllPorts
[libvirt-python/ericb.git] / libvirt-override-virConnect.py
blob7fe08e05501aeb422bd0e7f6e3bbf3802c2f595a
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 __enter__(self):
15 return self
17 def __exit__(self, exc_type_, exc_value_, traceback_):
18 self.close()
20 def domainEventDeregister(self, cb):
21 """Removes a Domain Event Callback. De-registering for a
22 domain callback will disable delivery of this event type """
23 try:
24 del self.domainEventCallbacks[cb]
25 if len(self.domainEventCallbacks) == 0:
26 del self.domainEventCallbacks
27 ret = libvirtmod.virConnectDomainEventDeregister(self._o, self)
28 if ret == -1: raise libvirtError ('virConnectDomainEventDeregister() failed', conn=self)
29 except AttributeError:
30 pass
32 def domainEventRegister(self, cb, opaque):
33 """Adds a Domain Event Callback. Registering for a domain
34 callback will enable delivery of the events """
35 try:
36 self.domainEventCallbacks[cb] = opaque
37 except AttributeError:
38 self.domainEventCallbacks = {cb:opaque}
39 ret = libvirtmod.virConnectDomainEventRegister(self._o, self)
40 if ret == -1: raise libvirtError ('virConnectDomainEventRegister() failed', conn=self)
42 def _dispatchDomainEventCallbacks(self, dom, event, detail):
43 """Dispatches events to python user domain event callbacks
44 """
45 try:
46 for cb,opaque in self.domainEventCallbacks.items():
47 cb(self, virDomain(self, _obj=dom), event, detail, opaque)
48 return 0
49 except AttributeError:
50 pass
52 def _dispatchDomainEventLifecycleCallback(self, dom, event, detail, cbData):
53 """Dispatches events to python user domain lifecycle event callbacks
54 """
55 cb = cbData["cb"]
56 opaque = cbData["opaque"]
58 cb(self, virDomain(self, _obj=dom), event, detail, opaque)
59 return 0
61 def _dispatchDomainEventGenericCallback(self, dom, cbData):
62 """Dispatches events to python user domain generic event callbacks
63 """
64 cb = cbData["cb"]
65 opaque = cbData["opaque"]
67 cb(self, virDomain(self, _obj=dom), opaque)
68 return 0
70 def _dispatchDomainEventRTCChangeCallback(self, dom, offset, cbData):
71 """Dispatches events to python user domain RTC change event callbacks
72 """
73 cb = cbData["cb"]
74 opaque = cbData["opaque"]
76 cb(self, virDomain(self, _obj=dom), offset ,opaque)
77 return 0
79 def _dispatchDomainEventWatchdogCallback(self, dom, action, cbData):
80 """Dispatches events to python user domain watchdog event callbacks
81 """
82 cb = cbData["cb"]
83 opaque = cbData["opaque"]
85 cb(self, virDomain(self, _obj=dom), action, opaque)
86 return 0
88 def _dispatchDomainEventIOErrorCallback(self, dom, srcPath, devAlias,
89 action, cbData):
90 """Dispatches events to python user domain IO error event callbacks
91 """
92 cb = cbData["cb"]
93 opaque = cbData["opaque"]
95 cb(self, virDomain(self, _obj=dom), srcPath, devAlias, action, opaque)
96 return 0
98 def _dispatchDomainEventIOErrorReasonCallback(self, dom, srcPath,
99 devAlias, action, reason,
100 cbData):
101 """Dispatches events to python user domain IO error event callbacks
103 cb = cbData["cb"]
104 opaque = cbData["opaque"]
106 cb(self, virDomain(self, _obj=dom), srcPath, devAlias, action,
107 reason, opaque)
108 return 0
110 def _dispatchDomainEventGraphicsCallback(self, dom, phase, localAddr,
111 remoteAddr, authScheme, subject,
112 cbData):
113 """Dispatches events to python user domain graphics event callbacks
115 cb = cbData["cb"]
116 opaque = cbData["opaque"]
118 cb(self, virDomain(self, _obj=dom), phase, localAddr, remoteAddr,
119 authScheme, subject, opaque)
120 return 0
122 def _dispatchDomainEventBlockJobCallback(self, dom, disk, type, status, cbData):
123 """Dispatches events to python user domain blockJob/blockJob2 event callbacks
125 try:
126 cb = cbData["cb"]
127 opaque = cbData["opaque"]
129 cb(self, virDomain(self, _obj=dom), disk, type, status, opaque)
130 return 0
131 except AttributeError:
132 pass
134 def _dispatchDomainEventDiskChangeCallback(self, dom, oldSrcPath, newSrcPath, devAlias, reason, cbData):
135 """Dispatches event to python user domain diskChange event callbacks
137 cb = cbData["cb"]
138 opaque = cbData["opaque"]
140 cb(self, virDomain(self, _obj=dom), oldSrcPath, newSrcPath, devAlias, reason, opaque)
141 return 0
143 def _dispatchDomainEventTrayChangeCallback(self, dom, devAlias, reason, cbData):
144 """Dispatches event to python user domain trayChange event callbacks
146 cb = cbData["cb"]
147 opaque = cbData["opaque"]
149 cb(self, virDomain(self, _obj=dom), devAlias, reason, opaque)
150 return 0
152 def _dispatchDomainEventPMWakeupCallback(self, dom, reason, cbData):
153 """Dispatches event to python user domain pmwakeup event callbacks
155 cb = cbData["cb"]
156 opaque = cbData["opaque"]
158 cb(self, virDomain(self, _obj=dom), reason, opaque)
159 return 0
161 def _dispatchDomainEventPMSuspendCallback(self, dom, reason, cbData):
162 """Dispatches event to python user domain pmsuspend event callbacks
164 cb = cbData["cb"]
165 opaque = cbData["opaque"]
167 cb(self, virDomain(self, _obj=dom), reason, opaque)
168 return 0
170 def _dispatchDomainEventBalloonChangeCallback(self, dom, actual, cbData):
171 """Dispatches events to python user domain balloon change event callbacks
173 cb = cbData["cb"]
174 opaque = cbData["opaque"]
176 cb(self, virDomain(self, _obj=dom), actual, opaque)
177 return 0
179 def _dispatchDomainEventPMSuspendDiskCallback(self, dom, reason, cbData):
180 """Dispatches event to python user domain pmsuspend-disk event callbacks
182 cb = cbData["cb"]
183 opaque = cbData["opaque"]
185 cb(self, virDomain(self, _obj=dom), reason, opaque)
186 return 0
188 def _dispatchDomainEventDeviceRemovedCallback(self, dom, devAlias, cbData):
189 """Dispatches event to python user domain device removed event callbacks
191 cb = cbData["cb"]
192 opaque = cbData["opaque"]
194 cb(self, virDomain(self, _obj=dom), devAlias, opaque)
195 return 0
197 def _dispatchDomainEventTunableCallback(self, dom, params, cbData):
198 """Dispatches event to python user domain tunable event callbacks
200 cb = cbData["cb"]
201 opaque = cbData["opaque"]
203 cb(self, virDomain(self, _obj=dom), params, opaque)
204 return 0
206 def _dispatchDomainEventAgentLifecycleCallback(self, dom, state, reason, cbData):
207 """Dispatches event to python user domain agent lifecycle event callback
210 cb = cbData["cb"]
211 opaque = cbData["opaque"]
213 cb(self, virDomain(self, _obj=dom), state, reason, opaque)
214 return 0
216 def _dispatchDomainEventDeviceAddedCallback(self, dom, devAlias, cbData):
217 """Dispatches event to python user domain device added event callbacks
219 cb = cbData["cb"]
220 opaque = cbData["opaque"]
222 cb(self, virDomain(self, _obj=dom), devAlias, opaque)
223 return 0
225 def _dispatchDomainEventMigrationIterationCallback(self, dom, iteration, cbData):
226 """Dispatches event to python user domain migration iteration event callbacks
228 cb = cbData["cb"]
229 opaque = cbData["opaque"]
231 cb(self, virDomain(self, _obj=dom), iteration, opaque)
232 return 0
234 def _dispatchDomainEventJobCompletedCallback(self, dom, params, cbData):
235 """Dispatches event to python user domain job completed callbacks
237 cb = cbData["cb"]
238 opaque = cbData["opaque"]
240 cb(self, virDomain(self, _obj=dom), params, opaque)
241 return 0
243 def _dispatchDomainEventDeviceRemovalFailedCallback(self, dom, devAlias, cbData):
244 """Dispatches event to python user domain device removal failed event callbacks
246 cb = cbData["cb"]
247 opaque = cbData["opaque"]
249 cb(self, virDomain(self, _obj=dom), devAlias, opaque)
250 return 0
252 def _dispatchDomainEventMetadataChangeCallback(self, dom, mtype, nsuri, cbData):
253 """Dispatches event to python user domain metadata change event callbacks
255 cb = cbData["cb"]
256 opaque = cbData["opaque"]
258 cb(self, virDomain(self, _obj=dom), mtype, nsuri, opaque)
259 return 0
261 def _dispatchDomainEventBlockThresholdCallback(self, dom, dev, path, threshold, excess, cbData):
262 """Dispatches event to python user domain block device threshold event callbacks
264 cb = cbData["cb"]
265 opaque = cbData["opaque"]
267 cb(self, virDomain(self, _obj=dom), dev, path, threshold, excess, opaque)
268 return 0
270 def domainEventDeregisterAny(self, callbackID):
271 """Removes a Domain Event Callback. De-registering for a
272 domain callback will disable delivery of this event type """
273 try:
274 ret = libvirtmod.virConnectDomainEventDeregisterAny(self._o, callbackID)
275 if ret == -1: raise libvirtError ('virConnectDomainEventDeregisterAny() failed', conn=self)
276 del self.domainEventCallbackID[callbackID]
277 except AttributeError:
278 pass
280 def _dispatchNetworkEventLifecycleCallback(self, net, event, detail, cbData):
281 """Dispatches events to python user network lifecycle event callbacks
283 cb = cbData["cb"]
284 opaque = cbData["opaque"]
286 cb(self, virNetwork(self, _obj=net), event, detail, opaque)
287 return 0
289 def networkEventDeregisterAny(self, callbackID):
290 """Removes a Network Event Callback. De-registering for a
291 network callback will disable delivery of this event type"""
292 try:
293 ret = libvirtmod.virConnectNetworkEventDeregisterAny(self._o, callbackID)
294 if ret == -1: raise libvirtError ('virConnectNetworkEventDeregisterAny() failed', conn=self)
295 del self.networkEventCallbackID[callbackID]
296 except AttributeError:
297 pass
299 def networkEventRegisterAny(self, net, eventID, cb, opaque):
300 """Adds a Network Event Callback. Registering for a network
301 callback will enable delivery of the events"""
302 if not hasattr(self, 'networkEventCallbackID'):
303 self.networkEventCallbackID = {}
304 cbData = { "cb": cb, "conn": self, "opaque": opaque }
305 if net is None:
306 ret = libvirtmod.virConnectNetworkEventRegisterAny(self._o, None, eventID, cbData)
307 else:
308 ret = libvirtmod.virConnectNetworkEventRegisterAny(self._o, net._o, eventID, cbData)
309 if ret == -1:
310 raise libvirtError ('virConnectNetworkEventRegisterAny() failed', conn=self)
311 self.networkEventCallbackID[ret] = opaque
312 return ret
314 def domainEventRegisterAny(self, dom, eventID, cb, opaque):
315 """Adds a Domain Event Callback. Registering for a domain
316 callback will enable delivery of the events """
317 if not hasattr(self, 'domainEventCallbackID'):
318 self.domainEventCallbackID = {}
319 cbData = { "cb": cb, "conn": self, "opaque": opaque }
320 if dom is None:
321 ret = libvirtmod.virConnectDomainEventRegisterAny(self._o, None, eventID, cbData)
322 else:
323 ret = libvirtmod.virConnectDomainEventRegisterAny(self._o, dom._o, eventID, cbData)
324 if ret == -1:
325 raise libvirtError ('virConnectDomainEventRegisterAny() failed', conn=self)
326 self.domainEventCallbackID[ret] = opaque
327 return ret
329 def _dispatchStoragePoolEventLifecycleCallback(self, pool, event, detail, cbData):
330 """Dispatches events to python user storage pool
331 lifecycle event callbacks
333 cb = cbData["cb"]
334 opaque = cbData["opaque"]
336 cb(self, virStoragePool(self, _obj=pool), event, detail, opaque)
337 return 0
339 def _dispatchStoragePoolEventGenericCallback(self, pool, cbData):
340 """Dispatches events to python user storage pool
341 generic event callbacks
343 cb = cbData["cb"]
344 opaque = cbData["opaque"]
346 cb(self, virStoragePool(self, _obj=pool), opaque)
347 return 0
349 def storagePoolEventDeregisterAny(self, callbackID):
350 """Removes a Storage Pool Event Callback. De-registering for a
351 storage pool callback will disable delivery of this event type"""
352 try:
353 ret = libvirtmod.virConnectStoragePoolEventDeregisterAny(self._o, callbackID)
354 if ret == -1: raise libvirtError ('virConnectStoragePoolEventDeregisterAny() failed', conn=self)
355 del self.storagePoolEventCallbackID[callbackID]
356 except AttributeError:
357 pass
359 def storagePoolEventRegisterAny(self, pool, eventID, cb, opaque):
360 """Adds a Storage Pool Event Callback. Registering for a storage pool
361 callback will enable delivery of the events"""
362 if not hasattr(self, 'storagePoolEventCallbackID'):
363 self.storagePoolEventCallbackID = {}
364 cbData = { "cb": cb, "conn": self, "opaque": opaque }
365 if pool is None:
366 ret = libvirtmod.virConnectStoragePoolEventRegisterAny(self._o, None, eventID, cbData)
367 else:
368 ret = libvirtmod.virConnectStoragePoolEventRegisterAny(self._o, pool._o, eventID, cbData)
369 if ret == -1:
370 raise libvirtError ('virConnectStoragePoolEventRegisterAny() failed', conn=self)
371 self.storagePoolEventCallbackID[ret] = opaque
372 return ret
374 def _dispatchNodeDeviceEventLifecycleCallback(self, dev, event, detail, cbData):
375 """Dispatches events to python user node device
376 lifecycle event callbacks
378 cb = cbData["cb"]
379 opaque = cbData["opaque"]
381 cb(self, virNodeDevice(self, _obj=dev), event, detail, opaque)
382 return 0
384 def _dispatchNodeDeviceEventGenericCallback(self, dev, cbData):
385 """Dispatches events to python user node device
386 generic event callbacks
388 cb = cbData["cb"]
389 opaque = cbData["opaque"]
391 cb(self, virNodeDevice(self, _obj=dev), opaque)
392 return 0
394 def nodeDeviceEventDeregisterAny(self, callbackID):
395 """Removes a Node Device Event Callback. De-registering for a
396 node device callback will disable delivery of this event type"""
397 try:
398 ret = libvirtmod.virConnectNodeDeviceEventDeregisterAny(self._o, callbackID)
399 if ret == -1: raise libvirtError ('virConnectNodeDeviceEventDeregisterAny() failed', conn=self)
400 del self.nodeDeviceEventCallbackID[callbackID]
401 except AttributeError:
402 pass
404 def nodeDeviceEventRegisterAny(self, dev, eventID, cb, opaque):
405 """Adds a Node Device Event Callback. Registering for a node device
406 callback will enable delivery of the events"""
407 if not hasattr(self, 'nodeDeviceEventCallbackID'):
408 self.nodeDeviceEventCallbackID = {}
409 cbData = { "cb": cb, "conn": self, "opaque": opaque }
410 if dev is None:
411 ret = libvirtmod.virConnectNodeDeviceEventRegisterAny(self._o, None, eventID, cbData)
412 else:
413 ret = libvirtmod.virConnectNodeDeviceEventRegisterAny(self._o, dev._o, eventID, cbData)
414 if ret == -1:
415 raise libvirtError ('virConnectNodeDeviceEventRegisterAny() failed', conn=self)
416 self.nodeDeviceEventCallbackID[ret] = opaque
417 return ret
419 def _dispatchSecretEventLifecycleCallback(self, secret, event, detail, cbData):
420 """Dispatches events to python user secret lifecycle event callbacks
422 cb = cbData["cb"]
423 opaque = cbData["opaque"]
425 cb(self, virSecret(self, _obj=secret), event, detail, opaque)
426 return 0
428 def _dispatchSecretEventGenericCallback(self, secret, cbData):
429 """Dispatches events to python user secret generic event callbacks
431 cb = cbData["cb"]
432 opaque = cbData["opaque"]
434 cb(self, virSecret(self, _obj=secret), opaque)
435 return 0
437 def secretEventDeregisterAny(self, callbackID):
438 """Removes a Secret Event Callback. De-registering for a
439 secret callback will disable delivery of this event type"""
440 try:
441 ret = libvirtmod.virConnectSecretEventDeregisterAny(self._o, callbackID)
442 if ret == -1: raise libvirtError ('virConnectSecretEventDeregisterAny() failed', conn=self)
443 del self.secretEventCallbackID[callbackID]
444 except AttributeError:
445 pass
447 def secretEventRegisterAny(self, secret, eventID, cb, opaque):
448 """Adds a Secret Event Callback. Registering for a secret
449 callback will enable delivery of the events"""
450 if not hasattr(self, 'secretEventCallbackID'):
451 self.secretEventCallbackID = {}
452 cbData = { "cb": cb, "conn": self, "opaque": opaque }
453 if secret is None:
454 ret = libvirtmod.virConnectSecretEventRegisterAny(self._o, None, eventID, cbData)
455 else:
456 ret = libvirtmod.virConnectSecretEventRegisterAny(self._o, secret._o, eventID, cbData)
457 if ret == -1:
458 raise libvirtError ('virConnectSecretEventRegisterAny() failed', conn=self)
459 self.secretEventCallbackID[ret] = opaque
460 return ret
462 def listAllDomains(self, flags=0):
463 """List all domains and returns a list of domain objects"""
464 ret = libvirtmod.virConnectListAllDomains(self._o, flags)
465 if ret is None:
466 raise libvirtError("virConnectListAllDomains() failed", conn=self)
468 retlist = list()
469 for domptr in ret:
470 retlist.append(virDomain(self, _obj=domptr))
472 return retlist
474 def listAllStoragePools(self, flags=0):
475 """Returns a list of storage pool objects"""
476 ret = libvirtmod.virConnectListAllStoragePools(self._o, flags)
477 if ret is None:
478 raise libvirtError("virConnectListAllStoragePools() failed", conn=self)
480 retlist = list()
481 for poolptr in ret:
482 retlist.append(virStoragePool(self, _obj=poolptr))
484 return retlist
486 def listAllNetworks(self, flags=0):
487 """Returns a list of network objects"""
488 ret = libvirtmod.virConnectListAllNetworks(self._o, flags)
489 if ret is None:
490 raise libvirtError("virConnectListAllNetworks() failed", conn=self)
492 retlist = list()
493 for netptr in ret:
494 retlist.append(virNetwork(self, _obj=netptr))
496 return retlist
498 def listAllInterfaces(self, flags=0):
499 """Returns a list of interface objects"""
500 ret = libvirtmod.virConnectListAllInterfaces(self._o, flags)
501 if ret is None:
502 raise libvirtError("virConnectListAllInterfaces() failed", conn=self)
504 retlist = list()
505 for ifaceptr in ret:
506 retlist.append(virInterface(self, _obj=ifaceptr))
508 return retlist
510 def listAllDevices(self, flags=0):
511 """Returns a list of host node device objects"""
512 ret = libvirtmod.virConnectListAllNodeDevices(self._o, flags)
513 if ret is None:
514 raise libvirtError("virConnectListAllNodeDevices() failed", conn=self)
516 retlist = list()
517 for devptr in ret:
518 retlist.append(virNodeDevice(self, _obj=devptr))
520 return retlist
522 def listAllNWFilters(self, flags=0):
523 """Returns a list of network filter objects"""
524 ret = libvirtmod.virConnectListAllNWFilters(self._o, flags)
525 if ret is None:
526 raise libvirtError("virConnectListAllNWFilters() failed", conn=self)
528 retlist = list()
529 for filter_ptr in ret:
530 retlist.append(virNWFilter(self, _obj=filter_ptr))
532 return retlist
534 def listAllNWFilterBindings(self, flags=0):
535 """Returns a list of network filter binding objects"""
536 ret = libvirtmod.virConnectListAllNWFilterBindings(self._o, flags)
537 if ret is None:
538 raise libvirtError("virConnectListAllNWFilterBindings() failed", conn=self)
540 retlist = list()
541 for filter_ptr in ret:
542 retlist.append(virNWFilterBinding(self, _obj=filter_ptr))
544 return retlist
546 def listAllSecrets(self, flags=0):
547 """Returns a list of secret objects"""
548 ret = libvirtmod.virConnectListAllSecrets(self._o, flags)
549 if ret is None:
550 raise libvirtError("virConnectListAllSecrets() failed", conn=self)
552 retlist = list()
553 for secret_ptr in ret:
554 retlist.append(virSecret(self, _obj=secret_ptr))
556 return retlist
558 def _dispatchCloseCallback(self, reason, cbData):
559 """Dispatches events to python user close callback"""
560 cb = cbData["cb"]
561 opaque = cbData["opaque"]
563 cb(self, reason, opaque)
564 return 0
567 def unregisterCloseCallback(self):
568 """Removes a close event callback"""
569 ret = libvirtmod.virConnectUnregisterCloseCallback(self._o)
570 if ret == -1: raise libvirtError ('virConnectUnregisterCloseCallback() failed', conn=self)
572 def registerCloseCallback(self, cb, opaque):
573 """Adds a close event callback, providing a notification
574 when a connection fails / closes"""
575 cbData = { "cb": cb, "conn": self, "opaque": opaque }
576 ret = libvirtmod.virConnectRegisterCloseCallback(self._o, cbData)
577 if ret == -1:
578 raise libvirtError ('virConnectRegisterCloseCallback() failed', conn=self)
579 return ret
581 def createXMLWithFiles(self, xmlDesc, files, flags=0):
582 """Launch a new guest domain, based on an XML description similar
583 to the one returned by virDomainGetXMLDesc()
584 This function may require privileged access to the hypervisor.
585 The domain is not persistent, so its definition will disappear when it
586 is destroyed, or if the host is restarted (see virDomainDefineXML() to
587 define persistent domains).
589 @files provides an array of file descriptors which will be
590 made available to the 'init' process of the guest. The file
591 handles exposed to the guest will be renumbered to start
592 from 3 (ie immediately following stderr). This is only
593 supported for guests which use container based virtualization
594 technology.
596 If the VIR_DOMAIN_START_PAUSED flag is set, the guest domain
597 will be started, but its CPUs will remain paused. The CPUs
598 can later be manually started using virDomainResume.
600 If the VIR_DOMAIN_START_AUTODESTROY flag is set, the guest
601 domain will be automatically destroyed when the virConnectPtr
602 object is finally released. This will also happen if the
603 client application crashes / loses its connection to the
604 libvirtd daemon. Any domains marked for auto destroy will
605 block attempts at migration, save-to-file, or snapshots. """
606 ret = libvirtmod.virDomainCreateXMLWithFiles(self._o, xmlDesc, files, flags)
607 if ret is None:raise libvirtError('virDomainCreateXMLWithFiles() failed', conn=self)
608 __tmp = virDomain(self,_obj=ret)
609 return __tmp
611 def getAllDomainStats(self, stats = 0, flags=0):
612 """Query statistics for all domains on a given connection.
614 Report statistics of various parameters for a running VM according to @stats
615 field. The statistics are returned as an array of structures for each queried
616 domain. The structure contains an array of typed parameters containing the
617 individual statistics. The typed parameter name for each statistic field
618 consists of a dot-separated string containing name of the requested group
619 followed by a group specific description of the statistic value.
621 The statistic groups are enabled using the @stats parameter which is a
622 binary-OR of enum virDomainStatsTypes. The following groups are available
623 (although not necessarily implemented for each hypervisor):
625 VIR_DOMAIN_STATS_STATE: Return domain state and reason for entering that
626 state. The typed parameter keys are in this format:
627 "state.state" - state of the VM, returned as int from virDomainState enum
628 "state.reason" - reason for entering given state, returned as int from
629 virDomain*Reason enum corresponding to given state.
631 Using 0 for @stats returns all stats groups supported by the given
632 hypervisor.
634 Specifying VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS as @flags makes
635 the function return error in case some of the stat types in @stats were
636 not recognized by the daemon.
638 Similarly to virConnectListAllDomains, @flags can contain various flags to
639 filter the list of domains to provide stats for.
641 VIR_CONNECT_GET_ALL_DOMAINS_STATS_ACTIVE selects online domains while
642 VIR_CONNECT_GET_ALL_DOMAINS_STATS_INACTIVE selects offline ones.
644 VIR_CONNECT_GET_ALL_DOMAINS_STATS_PERSISTENT and
645 VIR_CONNECT_GET_ALL_DOMAINS_STATS_TRANSIENT allow to filter the list
646 according to their persistence.
648 To filter the list of VMs by domain state @flags can contain
649 VIR_CONNECT_GET_ALL_DOMAINS_STATS_RUNNING,
650 VIR_CONNECT_GET_ALL_DOMAINS_STATS_PAUSED,
651 VIR_CONNECT_GET_ALL_DOMAINS_STATS_SHUTOFF and/or
652 VIR_CONNECT_GET_ALL_DOMAINS_STATS_OTHER for all other states. """
653 ret = libvirtmod.virConnectGetAllDomainStats(self._o, stats, flags)
654 if ret is None:
655 raise libvirtError("virConnectGetAllDomainStats() failed", conn=self)
657 retlist = list()
658 for elem in ret:
659 record = (virDomain(self, _obj=elem[0]) , elem[1])
660 retlist.append(record)
662 return retlist
664 def domainListGetStats(self, doms, stats=0, flags=0):
665 """ Query statistics for given domains.
667 Report statistics of various parameters for a running VM according to @stats
668 field. The statistics are returned as an array of structures for each queried
669 domain. The structure contains an array of typed parameters containing the
670 individual statistics. The typed parameter name for each statistic field
671 consists of a dot-separated string containing name of the requested group
672 followed by a group specific description of the statistic value.
674 The statistic groups are enabled using the @stats parameter which is a
675 binary-OR of enum virDomainStatsTypes. The following groups are available
676 (although not necessarily implemented for each hypervisor):
678 VIR_DOMAIN_STATS_STATE: Return domain state and reason for entering that
679 state. The typed parameter keys are in this format:
680 "state.state" - state of the VM, returned as int from virDomainState enum
681 "state.reason" - reason for entering given state, returned as int from
682 virDomain*Reason enum corresponding to given state.
684 Using 0 for @stats returns all stats groups supported by the given
685 hypervisor.
687 Specifying VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS as @flags makes
688 the function return error in case some of the stat types in @stats were
689 not recognized by the daemon.
691 Get statistics about domains provided as a list in @doms. @stats is
692 a bit field selecting requested statistics types."""
693 domlist = list()
694 for dom in doms:
695 if not isinstance(dom, virDomain):
696 raise libvirtError("domain list contains non-domain elements", conn=self)
698 domlist.append(dom._o)
700 ret = libvirtmod.virDomainListGetStats(self._o, domlist, stats, flags)
701 if ret is None:
702 raise libvirtError("virDomainListGetStats() failed", conn=self)
704 retlist = list()
705 for elem in ret:
706 record = (virDomain(self, _obj=elem[0]) , elem[1])
707 retlist.append(record)
709 return retlist