mirror of
https://gitlab.com/libvirt/libvirt-python.git
synced 2025-11-30 04:23:46 +03:00
API: Implement bindings for virDomainListGetStats
Implement the function by returning a list of tuples instead the array of virDomainStatsRecords and store the typed parameters as dict. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
@@ -436,3 +436,50 @@
|
||||
retlist.append(record)
|
||||
|
||||
return retlist
|
||||
|
||||
def domainListGetStats(self, doms, stats=0, flags=0):
|
||||
""" Query statistics for given domains.
|
||||
|
||||
Report statistics of various parameters for a running VM according to @stats
|
||||
field. The statistics are returned as an array of structures for each queried
|
||||
domain. The structure contains an array of typed parameters containing the
|
||||
individual statistics. The typed parameter name for each statistic field
|
||||
consists of a dot-separated string containing name of the requested group
|
||||
followed by a group specific description of the statistic value.
|
||||
|
||||
The statistic groups are enabled using the @stats parameter which is a
|
||||
binary-OR of enum virDomainStatsTypes. The following groups are available
|
||||
(although not necessarily implemented for each hypervisor):
|
||||
|
||||
VIR_DOMAIN_STATS_STATE: Return domain state and reason for entering that
|
||||
state. The typed parameter keys are in this format:
|
||||
"state.state" - state of the VM, returned as int from virDomainState enum
|
||||
"state.reason" - reason for entering given state, returned as int from
|
||||
virDomain*Reason enum corresponding to given state.
|
||||
|
||||
Using 0 for @stats returns all stats groups supported by the given
|
||||
hypervisor.
|
||||
|
||||
Specifying VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS as @flags makes
|
||||
the function return error in case some of the stat types in @stats were
|
||||
not recognized by the daemon.
|
||||
|
||||
Get statistics about domains provided as a list in @doms. @stats is
|
||||
a bit field selecting requested statistics types."""
|
||||
domlist = list()
|
||||
for dom in doms:
|
||||
if not isinstance(dom, virDomain):
|
||||
raise libvirtError("domain list contains non-domain elements", conn=self)
|
||||
|
||||
domlist.append(dom._o)
|
||||
|
||||
ret = libvirtmod.virDomainListGetStats(self._o, domlist, stats, flags)
|
||||
if ret is None:
|
||||
raise libvirtError("virDomainListGetStats() failed", conn=self)
|
||||
|
||||
retlist = list()
|
||||
for elem in ret:
|
||||
record = (virDomain(self, _obj=elem[0]) , elem[1])
|
||||
retlist.append(record)
|
||||
|
||||
return retlist
|
||||
|
||||
Reference in New Issue
Block a user