summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Krempa <pkrempa@redhat.com>2011-11-28 18:19:28 +0100
committerPeter Krempa <pkrempa@redhat.com>2011-12-05 12:22:33 +0100
commitd3c1ea120cd128ec326fe2f3455e1984687cc130 (patch)
treef57c3a0b9ca43b4a5c65e7c8a912370a4fc1a32e
parent37f6644416d061ad47b550e96e6f78c18907bd3b (diff)
downloadlibvirt-python-split-d3c1ea120cd128ec326fe2f3455e1984687cc130.zip
libvirt-python-split-d3c1ea120cd128ec326fe2f3455e1984687cc130.tar.gz
libvirt-python-split-d3c1ea120cd128ec326fe2f3455e1984687cc130.tar.xz
python: Expose binding for virNodeGetMemoryStats()v0.9.8
This patch adds binding for virNodeGetMemoryStats method of libvirtd. Return value is represented as a python dictionary mapping field names to values.
-rw-r--r--libvirt-override-api.xml7
-rw-r--r--libvirt-override.c48
2 files changed, 55 insertions, 0 deletions
diff --git a/libvirt-override-api.xml b/libvirt-override-api.xml
index 9cc7840..7c18763 100644
--- a/libvirt-override-api.xml
+++ b/libvirt-override-api.xml
@@ -84,6 +84,13 @@
<arg name='cpuNum' type='int' info='number of node cpu. (VIR_NODE_CPU_STATS_ALL_CPUS means total cpu statistics)'/>
<arg name='flags' type='unsigned int' info='additional flags'/>
</function>
+ <function name='virNodeGetMemoryStats' file='python'>
+ <info>Extract node's memory statistics.</info>
+ <return type='virNodeMemoryStats' info='dictionary mapping field names to values or None in case of error'/>
+ <arg name='conn' type='virConnectPtr' info='pointer to hypervisor connection'/>
+ <arg name='cellNum' type='int' info='number of node cell. (VIR_NODE_MEMORY_STATS_ALL_CELLS means total cell statistics)'/>
+ <arg name='flags' type='unsigned int' info='additional flags'/>
+ </function>
<function name='virDomainGetUUID' file='python'>
<info>Extract the UUID unique Identifier of a domain.</info>
<return type='char *' info='the 16 bytes string or None in case of error'/>
diff --git a/libvirt-override.c b/libvirt-override.c
index 5d80e64..9e98918 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -2304,6 +2304,53 @@ libvirt_virNodeGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
}
static PyObject *
+libvirt_virNodeGetMemoryStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
+{
+ PyObject *ret;
+ PyObject *pyobj_conn;
+ virConnectPtr conn;
+ unsigned int flags;
+ int cellNum, c_retval, i;
+ int nparams = 0;
+ virNodeMemoryStatsPtr stats = NULL;
+
+ if (!PyArg_ParseTuple(args, (char *)"Oii:virNodeGetMemoryStats", &pyobj_conn, &cellNum, &flags))
+ return(NULL);
+ conn = (virConnectPtr)(PyvirConnect_Get(pyobj_conn));
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ c_retval = virNodeGetMemoryStats(conn, cellNum, NULL, &nparams, flags);
+ LIBVIRT_END_ALLOW_THREADS;
+ if (c_retval < 0)
+ return VIR_PY_NONE;
+
+ if (nparams) {
+ if (!(stats = malloc(sizeof(*stats) * nparams)))
+ return VIR_PY_NONE;
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ c_retval = virNodeGetMemoryStats(conn, cellNum, stats, &nparams, flags);
+ LIBVIRT_END_ALLOW_THREADS;
+ if (c_retval < 0) {
+ free(stats);
+ return VIR_PY_NONE;
+ }
+ }
+ if (!(ret = PyDict_New())) {
+ free(stats);
+ return VIR_PY_NONE;
+ }
+ for (i = 0; i < nparams; i++) {
+ PyDict_SetItem(ret,
+ libvirt_constcharPtrWrap(stats[i].field),
+ libvirt_ulonglongWrap(stats[i].value));
+ }
+
+ free(stats);
+ return ret;
+}
+
+static PyObject *
libvirt_virConnectListStoragePools(PyObject *self ATTRIBUTE_UNUSED,
PyObject *args) {
PyObject *py_retval;
@@ -4996,6 +5043,7 @@ static PyMethodDef libvirtMethods[] = {
{(char *) "virDomainGetBlockInfo", libvirt_virDomainGetBlockInfo, METH_VARARGS, NULL},
{(char *) "virNodeGetInfo", libvirt_virNodeGetInfo, METH_VARARGS, NULL},
{(char *) "virNodeGetCPUStats", libvirt_virNodeGetCPUStats, METH_VARARGS, NULL},
+ {(char *) "virNodeGetMemoryStats", libvirt_virNodeGetMemoryStats, METH_VARARGS, NULL},
{(char *) "virDomainGetUUID", libvirt_virDomainGetUUID, METH_VARARGS, NULL},
{(char *) "virDomainGetUUIDString", libvirt_virDomainGetUUIDString, METH_VARARGS, NULL},
{(char *) "virDomainLookupByUUID", libvirt_virDomainLookupByUUID, METH_VARARGS, NULL},