]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
list: Expose virConnectListAllNodeDevices to Python binding
authorOsier Yang <jyang@redhat.com>
Wed, 5 Sep 2012 05:34:11 +0000 (13:34 +0800)
committerOsier Yang <jyang@redhat.com>
Mon, 17 Sep 2012 02:41:03 +0000 (10:41 +0800)
The implementation is done manually as the generator does not support
wrapping lists of C pointers into Python objects.

python/libvirt-override-api.xml: Document

python/libvirt-override-virConnect.py:
  * Implementation for listAllNodeDevices.

python/libvirt-override.c: Implementation for the wrapper.

python/libvirt-override-api.xml
python/libvirt-override-virConnect.py
python/libvirt-override.c

index ab6f407126c611829205bfe6a431edc339bcaf25..a3d6bbb89adab610efe02d049833ef9c2662d9c7 100644 (file)
       <arg name='flags' type='unsigned int' info='flags (unused; pass 0)'/>
       <return type='str *' info='the list of Names or None in case of error'/>
     </function>
+    <function name='virConnectListAllNodeDevices' file='python'>
+      <info>returns list of all host node devices</info>
+      <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
+      <arg name='flags' type='unsigned int' info='optional flags'/>
+      <return type='device *' info='the list of host node device or None in case of error'/>
+    </function>
     <function name='virNodeDeviceListCaps' file='python'>
       <info>list the node device's capabilities</info>
       <arg name='dev' type='virNodeDevicePtr' info='pointer to the node device'/>
index ffa1a3cbd099ddef0b81847960ecbada0754b661..0859c361afc6377158b6ddeaaf0125d36874eec5 100644 (file)
             retlist.append(virInterface(self, _obj=ifaceptr))
 
         return retlist
+
+    def listAllDevices(self, flags):
+        """Returns a list of host node device objects"""
+        ret = libvirtmod.virConnectListAllNodeDevices(self._o, flags)
+        if ret is None:
+            raise libvirtError("virConnectListAllNodeDevices() failed", conn=self)
+
+        retlist = list()
+        for devptr in ret:
+            retlist.append(virNodeDevice(self, _obj=devptr))
+
+        return retlist
index d07e7cb452d6b92bdb39c6e4737f0596b621b9ef..426d57e317960f7cccbea696b0f8df35a7c17a3d 100644 (file)
@@ -3386,6 +3386,53 @@ libvirt_virNodeListDevices(PyObject *self ATTRIBUTE_UNUSED,
     return py_retval;
 }
 
+static PyObject *
+libvirt_virConnectListAllNodeDevices(PyObject *self ATTRIBUTE_UNUSED,
+                                     PyObject *args)
+{
+    PyObject *pyobj_conn;
+    PyObject *py_retval = NULL;
+    PyObject *tmp = NULL;
+    virConnectPtr conn;
+    virNodeDevicePtr *devices = NULL;
+    int c_retval = 0;
+    int i;
+    unsigned int flags;
+
+    if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllNodeDevices",
+                          &pyobj_conn, &flags))
+        return NULL;
+    conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+
+    LIBVIRT_BEGIN_ALLOW_THREADS;
+    c_retval = virConnectListAllNodeDevices(conn, &devices, flags);
+    LIBVIRT_END_ALLOW_THREADS;
+    if (c_retval < 0)
+        return VIR_PY_NONE;
+
+    if (!(py_retval = PyList_New(c_retval)))
+        goto cleanup;
+
+    for (i = 0; i < c_retval; i++) {
+        if (!(tmp = libvirt_virNodeDevicePtrWrap(devices[i])) ||
+            PyList_SetItem(py_retval, i, tmp) < 0) {
+            Py_XDECREF(tmp);
+            Py_DECREF(py_retval);
+            py_retval = NULL;
+            goto cleanup;
+        }
+        /* python steals the pointer */
+        devices[i] = NULL;
+    }
+
+cleanup:
+    for (i = 0; i < c_retval; i++)
+        if (devices[i])
+            virNodeDeviceFree(devices[i]);
+    VIR_FREE(devices);
+    return py_retval;
+}
+
 static PyObject *
 libvirt_virNodeDeviceListCaps(PyObject *self ATTRIBUTE_UNUSED,
                               PyObject *args) {
@@ -6087,6 +6134,7 @@ static PyMethodDef libvirtMethods[] = {
     {(char *) "virEventInvokeHandleCallback", libvirt_virEventInvokeHandleCallback, METH_VARARGS, NULL},
     {(char *) "virEventInvokeTimeoutCallback", libvirt_virEventInvokeTimeoutCallback, METH_VARARGS, NULL},
     {(char *) "virNodeListDevices", libvirt_virNodeListDevices, METH_VARARGS, NULL},
+    {(char *) "virConnectListAllNodeDevices", libvirt_virConnectListAllNodeDevices, METH_VARARGS, NULL},
     {(char *) "virNodeDeviceListCaps", libvirt_virNodeDeviceListCaps, METH_VARARGS, NULL},
     {(char *) "virSecretGetUUID", libvirt_virSecretGetUUID, METH_VARARGS, NULL},
     {(char *) "virSecretGetUUIDString", libvirt_virSecretGetUUIDString, METH_VARARGS, NULL},