On 08/28/2014 06:32 PM, Peter Krempa wrote:
Implement the function by returning a list of tuples instead the
array
of virDomainStatsRecords and store the typed parameters as dict.
---
generator.py | 1 +
libvirt-override-virConnect.py | 47 +++++++++++++++++++++++++++++++++++++++
libvirt-override.c | 50 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 98 insertions(+)
diff --git a/generator.py b/generator.py
index 9addb89..3642838 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
The function 'domainListGetStats' should be implemented in
libvirt-override-virDomain.py as 'listGetStats'.
diff --git a/libvirt-override.c b/libvirt-override.c
index df4f15b..7e9f570 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -5052,6 +5052,55 @@ 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;
Set records to NULL to make 'virDomainStatsRecordListFree' happy if the
'virDomainListGetStats' fails.
+ 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)
+ return VIR_PY_NONE;
There you will leak 'doms'.
+
+ if (!(py_retval = convertDomainStatsRecord(records, nrecords)))
+ py_retval = VIR_PY_NONE;
+
+ cleanup:
+ virDomainStatsRecordListFree(records);
+ VIR_FREE(doms);
+
+ return py_retval;
+}
#endif
@@ -8233,6 +8282,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}
};
ACK with the changes
Pavel