diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index b0fbf947b2..0a560940de 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -445,9 +445,11 @@ struct _virNodeCPUStats { /** * VIR_NODE_MEMORY_STATS_ALL_CELLS: * - * Macro for the total memory of all cells. + * Value for specifying request for the total memory of all cells. */ -#define VIR_NODE_MEMORY_STATS_ALL_CELLS (-1) +typedef enum { + VIR_NODE_MEMORY_STATS_ALL_CELLS = -1, +} virNodeGetMemoryStatsAllCells; /** * VIR_NODE_MEMORY_STATS_TOTAL: diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml index 9cc7840bd9..7c1876348d 100644 --- a/python/libvirt-override-api.xml +++ b/python/libvirt-override-api.xml @@ -84,6 +84,13 @@ + + Extract node's memory statistics. + + + + + Extract the UUID unique Identifier of a domain. diff --git a/python/libvirt-override.c b/python/libvirt-override.c index 5d80e64626..9e98918ee8 100644 --- a/python/libvirt-override.c +++ b/python/libvirt-override.c @@ -2303,6 +2303,53 @@ libvirt_virNodeGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) return ret; } +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) { @@ -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},