summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xgenerator.py3
-rw-r--r--libvirt-override-api.xml5
-rw-r--r--libvirt-override.c44
3 files changed, 50 insertions, 2 deletions
diff --git a/generator.py b/generator.py
index 06f1ff4..56f8925 100755
--- a/generator.py
+++ b/generator.py
@@ -161,7 +161,6 @@ def enum(type, name, value):
functions_failed = []
functions_skipped = [
"virConnectListDomains",
- "virDomainMemoryStats"
]
skipped_modules = {
@@ -171,7 +170,6 @@ skipped_types = {
# 'int *': "usually a return type",
'virConnectDomainEventCallback': "No function types in python",
'virEventAddHandleFunc': "No function types in python",
- 'virDomainMemoryStatPtr': "Not implemented yet",
}
#######################################################################
@@ -283,6 +281,7 @@ skip_impl = (
'virNetworkGetAutostart',
'virDomainBlockStats',
'virDomainInterfaceStats',
+ 'virDomainMemoryStats',
'virNodeGetCellsFreeMemory',
'virDomainGetSchedulerType',
'virDomainGetSchedulerParameters',
diff --git a/libvirt-override-api.xml b/libvirt-override-api.xml
index 96958b5..6ae2742 100644
--- a/libvirt-override-api.xml
+++ b/libvirt-override-api.xml
@@ -105,6 +105,11 @@
<arg name='domain' type='virDomainPtr' info='a domain object'/>
<arg name='path' type='char *' info='the path for the interface device'/>
</function>
+ <function name='virDomainMemoryStats' file='python'>
+ <info>Extracts memory statistics for a domain</info>
+ <return type='virDomainMemoryStats' info='a dictionary of statistics'/>
+ <arg name='domain' type='virDomainPtr' info='a domain object'/>
+ </function>
<function name="virNodeGetCellsFreeMemory" file='python'>
<info>Returns the available memory for a list of cells</info>
<arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
diff --git a/libvirt-override.c b/libvirt-override.c
index 6c1e51b..db4c0e1 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -120,6 +120,49 @@ libvirt_virDomainInterfaceStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
return(info);
}
+static PyObject *
+libvirt_virDomainMemoryStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
+ virDomainPtr domain;
+ PyObject *pyobj_domain;
+ unsigned int nr_stats, i;
+ virDomainMemoryStatStruct stats[VIR_DOMAIN_MEMORY_STAT_NR];
+ PyObject *info;
+
+ if (!PyArg_ParseTuple(args, (char *)"O:virDomainMemoryStats", &pyobj_domain))
+ return(NULL);
+ domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
+
+ nr_stats = virDomainMemoryStats(domain, stats,
+ VIR_DOMAIN_MEMORY_STAT_NR, 0);
+ if (nr_stats == -1)
+ return VIR_PY_NONE;
+
+ /* convert to a Python dictionary */
+ if ((info = PyDict_New()) == NULL)
+ return VIR_PY_NONE;
+
+ for (i = 0; i < nr_stats; i++) {
+ if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_SWAP_IN)
+ PyDict_SetItem(info, libvirt_constcharPtrWrap("swap_in"),
+ PyLong_FromUnsignedLongLong(stats[i].val));
+ else if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_SWAP_OUT)
+ PyDict_SetItem(info, libvirt_constcharPtrWrap("swap_out"),
+ PyLong_FromUnsignedLongLong(stats[i].val));
+ else if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_MAJOR_FAULT)
+ PyDict_SetItem(info, libvirt_constcharPtrWrap("major_fault"),
+ PyLong_FromUnsignedLongLong(stats[i].val));
+ else if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_MINOR_FAULT)
+ PyDict_SetItem(info, libvirt_constcharPtrWrap("minor_fault"),
+ PyLong_FromUnsignedLongLong(stats[i].val));
+ else if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_UNUSED)
+ PyDict_SetItem(info, libvirt_constcharPtrWrap("unused"),
+ PyLong_FromUnsignedLongLong(stats[i].val));
+ else if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_AVAILABLE)
+ PyDict_SetItem(info, libvirt_constcharPtrWrap("available"),
+ PyLong_FromUnsignedLongLong(stats[i].val));
+ }
+ return info;
+}
static PyObject *
libvirt_virDomainGetSchedulerType(PyObject *self ATTRIBUTE_UNUSED,
@@ -2635,6 +2678,7 @@ static PyMethodDef libvirtMethods[] = {
{(char *) "virNetworkGetAutostart", libvirt_virNetworkGetAutostart, METH_VARARGS, NULL},
{(char *) "virDomainBlockStats", libvirt_virDomainBlockStats, METH_VARARGS, NULL},
{(char *) "virDomainInterfaceStats", libvirt_virDomainInterfaceStats, METH_VARARGS, NULL},
+ {(char *) "virDomainMemoryStats", libvirt_virDomainMemoryStats, METH_VARARGS, NULL},
{(char *) "virNodeGetCellsFreeMemory", libvirt_virNodeGetCellsFreeMemory, METH_VARARGS, NULL},
{(char *) "virDomainGetSchedulerType", libvirt_virDomainGetSchedulerType, METH_VARARGS, NULL},
{(char *) "virDomainGetSchedulerParameters", libvirt_virDomainGetSchedulerParameters, METH_VARARGS, NULL},