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(a)redhat.com>
Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
generator.py | 1 +
libvirt-override-virConnect.py | 47 ++++++++++++++++++++++++++++++++++++++
libvirt-override.c | 52 ++++++++++++++++++++++++++++++++++++++++++
sanitytest.py | 3 +++
4 files changed, 103 insertions(+)
diff --git a/generator.py b/generator.py
index 3fc7db2..1daf866 100755
--- a/generator.py
+++ b/generator.py
@@ -508,6 +508,7 @@ skip_function = (
'virConnectListAllNWFilters', # overridden in virConnect.py
'virConnectListAllSecrets', # overridden in virConnect.py
'virConnectGetAllDomainStats', # overridden in virConnect.py
+ 'virDomainListGetStats', # overriden in virConnect.py
'virStreamRecvAll', # Pure python libvirt-override-virStream.py
'virStreamSendAll', # Pure python libvirt-override-virStream.py
diff --git a/libvirt-override-virConnect.py b/libvirt-override-virConnect.py
index c4c400a..218f266 100644
--- a/libvirt-override-virConnect.py
+++ b/libvirt-override-virConnect.py
@@ -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
diff --git a/libvirt-override.c b/libvirt-override.c
index 2da43ab..569778d 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -8045,6 +8045,57 @@ libvirt_virConnectGetAllDomainStats(PyObject *self
ATTRIBUTE_UNUSED,
return py_retval;
}
+
+static PyObject *
+libvirt_virDomainListGetStats(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args)
+{
+ PyObject *pyobj_conn;
+ PyObject *py_retval;
+ PyObject *py_domlist;
+ virConnectPtr conn;
+ virDomainStatsRecordPtr *records = NULL;
+ virDomainPtr *doms = NULL;
+ int nrecords;
+ int ndoms;
+ size_t i;
+ unsigned int flags;
+ unsigned int stats;
+
+ if (!PyArg_ParseTuple(args, (char *)"OOii:virDomainListGetStats",
+ &pyobj_conn, &py_domlist, &stats, &flags))
+ return NULL;
+ conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+
+ if (PyList_Check(py_domlist)) {
+ ndoms = PyList_Size(py_domlist);
+
+ if (VIR_ALLOC_N(doms, ndoms + 1) < 0)
+ return PyErr_NoMemory();
+
+ for (i = 0; i < ndoms; i++)
+ doms[i] = PyvirDomain_Get(PyList_GetItem(py_domlist, i));
+ }
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ nrecords = virDomainListGetStats(doms, stats, &records, flags);
+ LIBVIRT_END_ALLOW_THREADS;
+
+ if (nrecords < 0) {
+ py_retval = VIR_PY_NONE;
+ goto cleanup;
+ }
+
+ if (!(py_retval = convertDomainStatsRecord(records, nrecords)))
+ py_retval = VIR_PY_NONE;
+
+ cleanup:
+ virDomainStatsRecordListFree(records);
+ VIR_FREE(doms);
+
+ return py_retval;
+}
+
#endif /* LIBVIR_CHECK_VERSION(1, 2, 8) */
/************************************************************************
@@ -8234,6 +8285,7 @@ static PyMethodDef libvirtMethods[] = {
#endif /* LIBVIR_CHECK_VERSION(1, 2, 6) */
#if LIBVIR_CHECK_VERSION(1, 2, 8)
{(char *) "virConnectGetAllDomainStats",
libvirt_virConnectGetAllDomainStats, METH_VARARGS, NULL},
+ {(char *) "virDomainListGetStats", libvirt_virDomainListGetStats,
METH_VARARGS, NULL},
#endif /* LIBVIR_CHECK_VERSION(1, 2, 8) */
{NULL, NULL, 0, NULL}
};
diff --git a/sanitytest.py b/sanitytest.py
index 10cf9f0..3c1568b 100644
--- a/sanitytest.py
+++ b/sanitytest.py
@@ -84,6 +84,9 @@ for cname in wantfunctions:
if name[0:28] == "virDomainStatsRecordListFree":
continue
+ if name[0:21] == "virDomainListGetStats":
+ name = "virConnectDomainListGetStats"
+
# These aren't functions, they're callback signatures
if name in ["virConnectAuthCallbackPtr", "virConnectCloseFunc",
"virStreamSinkFunc", "virStreamSourceFunc",
"virStreamEventCallback",
--
1.8.5.5