[Libvir] [PATCH] Python bindings for virNodeGetCellsFreeMemory

Daniel Veillard veillard at redhat.com
Thu Dec 6 17:42:26 UTC 2007


  I realized that one of the NUMA API entry point didn't had a 
binding in Python, the enclosed patch adds it, it's a method
on a virConnect class, taking the startCell and maxCells integer
parameters and returning a list of available memory for that
range of cell, using it should be as simple as launching python
as root after reinstallation of the libvirt library and bindings
and doing the following:

>>> import libvirt
>>> conn = libvirt.open(None)
>>> conn.getCellsFreeMemory(0, 20)

 it should return the array of available heap for each of the
20 first cells in machine, but I can't test this at the moment.
Saori, Beth is there any chance you could test that patch ?

  thanks,

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
veillard at redhat.com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/
-------------- next part --------------
Index: python/generator.py
===================================================================
RCS file: /data/cvs/libxen/python/generator.py,v
retrieving revision 1.24
diff -u -r1.24 generator.py
--- python/generator.py	30 Sep 2007 20:52:13 -0000	1.24
+++ python/generator.py	6 Dec 2007 15:27:40 -0000
@@ -278,6 +278,7 @@
     'virNetworkLookupByUUID',
     'virDomainBlockStats',
     'virDomainInterfaceStats',
+    'virNodeGetCellsFreeMemory',
 )
 
 def skip_function(name):
Index: python/libvir.c
===================================================================
RCS file: /data/cvs/libxen/python/libvir.c,v
retrieving revision 1.26
diff -u -r1.26 libvir.c
--- python/libvir.c	5 Dec 2007 19:09:23 -0000	1.26
+++ python/libvir.c	6 Dec 2007 15:27:40 -0000
@@ -27,6 +27,7 @@
 PyObject *libvirt_virConnGetLastError(PyObject *self ATTRIBUTE_UNUSED, PyObject *args);
 PyObject * libvirt_virDomainBlockStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args);
 PyObject * libvirt_virDomainInterfaceStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args);
+PyObject * libvirt_virNodeGetCellsFreeMemory(PyObject *self ATTRIBUTE_UNUSED, PyObject *args);
 
 /************************************************************************
  *									*
@@ -844,7 +845,45 @@
     return(py_retval);
 }
 
+PyObject * libvirt_virNodeGetCellsFreeMemory(PyObject *self ATTRIBUTE_UNUSED,
+         PyObject *args)
+{
+    PyObject *py_retval;
+    PyObject *pyobj_conn;
+    int startCell, maxCells, c_retval, i;
+    virConnectPtr conn;
+    unsigned long long *freeMems;
+
+    if (!PyArg_ParseTuple(args, (char *)"Oii:virNodeGetCellsFreeMemory", &pyobj_conn, &startCell, &maxCells))
+        return(NULL);
 
+    if ((startCell < 0) || (maxCells <= 0) || (startCell + maxCells > 10000))
+        goto error;
+
+    conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+    freeMems = (unsigned long long *)
+          malloc(maxCells * sizeof(unsigned long long));
+    if (freeMems == NULL)
+        goto error;
+
+    LIBVIRT_BEGIN_ALLOW_THREADS;
+    c_retval = virNodeGetCellsFreeMemory(conn, freeMems, startCell, maxCells);
+    LIBVIRT_END_ALLOW_THREADS;
+
+    if (c_retval < 0) {
+	free(freeMems);
+error:
+        Py_INCREF(Py_None);
+	return Py_None;
+    }
+    py_retval = PyList_New(c_retval);
+    for (i = 0;i < c_retval;i++) {
+	PyList_SetItem(py_retval, i, 
+	        libvirt_longlongWrap((long long) freeMems[i]));
+    }
+    free(freeMems);
+    return(py_retval);
+}
 
 /************************************************************************
  *									*
@@ -875,6 +914,7 @@
     {(char *) "virNetworkGetAutostart", libvirt_virNetworkGetAutostart, METH_VARARGS, NULL},
     {(char *) "virDomainBlockStats", libvirt_virDomainBlockStats, METH_VARARGS, NULL},
     {(char *) "virDomainInterfaceStats", libvirt_virDomainInterfaceStats, METH_VARARGS, NULL},
+    {(char *) "virNodeGetCellsFreeMemory", libvirt_virNodeGetCellsFreeMemory, METH_VARARGS, NULL},
     {NULL, NULL, 0, NULL}
 };
 
Index: python/libvirt-python-api.xml
===================================================================
RCS file: /data/cvs/libxen/python/libvirt-python-api.xml,v
retrieving revision 1.8
diff -u -r1.8 libvirt-python-api.xml
--- python/libvirt-python-api.xml	30 Sep 2007 20:52:13 -0000	1.8
+++ python/libvirt-python-api.xml	6 Dec 2007 15:27:40 -0000
@@ -75,5 +75,12 @@
       <arg name='domain' type='virDomainPtr' info='a domain object'/>
       <arg name='path' type='char *' info='the path for the interface device'/>
     </function>
+    <function name="virNodeGetCellsFreeMemory" file='python'>
+      <info>Returns the availbale memory for a list of cells</info>
+      <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
+      <arg name='startCell' type='int' info='first cell in the list'/>
+      <arg name='maxCells' type='int' info='number of cell in the list'/>
+      <return type='int *' info="the list available memory in the cells"/>
+    </function>
   </symbols>
 </api>


More information about the libvir-list mailing list