diff options
author | Peter Krempa <pkrempa@redhat.com> | 2011-11-28 18:19:27 +0100 |
---|---|---|
committer | Peter Krempa <pkrempa@redhat.com> | 2011-12-05 12:22:33 +0100 |
commit | 37f6644416d061ad47b550e96e6f78c18907bd3b (patch) | |
tree | b83c8fab372e253925d58c9b215b2c45bfb47b08 /libvirt-override.c | |
parent | 4d6d685288f849db152fcd8e5985fc7605764606 (diff) | |
download | libvirt-python-split-37f6644416d061ad47b550e96e6f78c18907bd3b.tar.gz libvirt-python-split-37f6644416d061ad47b550e96e6f78c18907bd3b.tar.xz libvirt-python-split-37f6644416d061ad47b550e96e6f78c18907bd3b.zip |
python: Expose binding for virNodeGetCPUStats()
This patch adds binding for virNodeGetCPUStats method of libvirtd.
Return value is represented as a python dictionary mapping field names
to values.
Diffstat (limited to 'libvirt-override.c')
-rw-r--r-- | libvirt-override.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/libvirt-override.c b/libvirt-override.c index cfb9a31..5d80e64 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -2256,6 +2256,52 @@ libvirt_virNodeGetCellsFreeMemory(PyObject *self ATTRIBUTE_UNUSED, PyObject *arg return(py_retval); } +static PyObject * +libvirt_virNodeGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) +{ + PyObject *ret; + PyObject *pyobj_conn; + virConnectPtr conn; + unsigned int flags; + int cpuNum, c_retval, i; + int nparams = 0; + virNodeCPUStatsPtr stats = NULL; + + if (!PyArg_ParseTuple(args, (char *)"Oii:virNodeGetCPUStats", &pyobj_conn, &cpuNum, &flags)) + return(NULL); + conn = (virConnectPtr)(PyvirConnect_Get(pyobj_conn)); + + LIBVIRT_BEGIN_ALLOW_THREADS; + c_retval = virNodeGetCPUStats(conn, cpuNum, 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 = virNodeGetCPUStats(conn, cpuNum, 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, @@ -4949,6 +4995,7 @@ static PyMethodDef libvirtMethods[] = { {(char *) "virDomainGetControlInfo", libvirt_virDomainGetControlInfo, METH_VARARGS, NULL}, {(char *) "virDomainGetBlockInfo", libvirt_virDomainGetBlockInfo, METH_VARARGS, NULL}, {(char *) "virNodeGetInfo", libvirt_virNodeGetInfo, METH_VARARGS, NULL}, + {(char *) "virNodeGetCPUStats", libvirt_virNodeGetCPUStats, METH_VARARGS, NULL}, {(char *) "virDomainGetUUID", libvirt_virDomainGetUUID, METH_VARARGS, NULL}, {(char *) "virDomainGetUUIDString", libvirt_virDomainGetUUIDString, METH_VARARGS, NULL}, {(char *) "virDomainLookupByUUID", libvirt_virDomainLookupByUUID, METH_VARARGS, NULL}, |