[PATCH 43/48] list: Expose virConnectListAllNWFilters to Python binding

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 listAllNWFilters.

python/libvirt-override.c: Implementation for the wrapper.
---
 python/libvirt-override-api.xml       |    6 ++++
 python/libvirt-override-virConnect.py |   12 ++++++++
 python/libvirt-override.c             |   48 +++++++++++++++++++++++++++++++++
 3 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml
index a3d6bbb..b8ab823 100644
--- a/python/libvirt-override-api.xml
+++ b/python/libvirt-override-api.xml
@@ -396,6 +396,12 @@
       <arg name='conn' type='virConnectPtr' info='virConnect connection'/>
       <return type='str *' info='the list of network filter IDs or None in case of error'/>
     </function>
+    <function name='virConnectListAllNWFilters' file='python'>
+      <info>returns list of all network fitlers</info>
+      <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
+      <arg name='flags' type='unsigned int' info='optional flags'/>
+      <return type='nwfilter *' info='the list of network filters or None in case of error'/>
+    </function>
     <function name='virNWFilterLookupByUUID' file='python'>
       <info>Try to lookup a network filter on the given hypervisor based on its UUID.</info>
       <return type='virNWFilterPtr' info='a new network filter object or NULL in case of failure'/>
diff --git a/python/libvirt-override-virConnect.py b/python/libvirt-override-virConnect.py
index 0859c36..caca982 100644
--- a/python/libvirt-override-virConnect.py
+++ b/python/libvirt-override-virConnect.py
@@ -254,3 +254,15 @@
             retlist.append(virNodeDevice(self, _obj=devptr))
 
         return retlist
+
+    def listAllNWFilters(self, flags):
+        """Returns a list of network filter objects"""
+        ret = libvirtmod.virConnectListAllNWFilters(self._o, flags)
+        if ret is None:
+            raise libvirtError("virConnectListAllNWFilters() failed", conn=self)
+
+        retlist = list()
+        for filter_ptr in ret:
+            retlist.append(virNWFilter(self, _obj=filter_ptr))
+
+        return retlist
diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index 6449639..bdf5d12 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -3764,6 +3764,53 @@ libvirt_virConnectListNWFilters(PyObject *self ATTRIBUTE_UNUSED,
 }
 
 static PyObject *
+libvirt_virConnectListAllNWFilters(PyObject *self ATTRIBUTE_UNUSED,
+                                   PyObject *args)
+{
+    PyObject *pyobj_conn;
+    PyObject *py_retval = NULL;
+    PyObject *tmp = NULL;
+    virConnectPtr conn;
+    virNWFilterPtr *filters = NULL;
+    int c_retval = 0;
+    int i;
+    unsigned int flags;
+
+    if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllNWFilters",
+                          &pyobj_conn, &flags))
+        return NULL;
+    conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+
+    LIBVIRT_BEGIN_ALLOW_THREADS;
+    c_retval = virConnectListAllNWFilters(conn, &filters, 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_virNWFilterPtrWrap(filters[i])) ||
+            PyList_SetItem(py_retval, i, tmp) < 0) {
+            Py_XDECREF(tmp);
+            Py_DECREF(py_retval);
+            py_retval = NULL;
+            goto cleanup;
+        }
+        /* python steals the pointer */
+        filters[i] = NULL;
+    }
+
+cleanup:
+    for (i = 0; i < c_retval; i++)
+        if (filters[i])
+            virNWFilterFree(filters[i]);
+    VIR_FREE(filters);
+    return py_retval;
+}
+
+static PyObject *
 libvirt_virConnectListInterfaces(PyObject *self ATTRIBUTE_UNUSED,
                                  PyObject *args) {
     PyObject *py_retval;
@@ -6138,6 +6185,7 @@ static PyMethodDef libvirtMethods[] = {
     {(char *) "virNWFilterGetUUIDString", libvirt_virNWFilterGetUUIDString, METH_VARARGS, NULL},
     {(char *) "virNWFilterLookupByUUID", libvirt_virNWFilterLookupByUUID, METH_VARARGS, NULL},
     {(char *) "virConnectListNWFilters", libvirt_virConnectListNWFilters, METH_VARARGS, NULL},
+    {(char *) "virConnectListAllNWFilters", libvirt_virConnectListAllNWFilters, METH_VARARGS, NULL},
     {(char *) "virConnectListInterfaces", libvirt_virConnectListInterfaces, METH_VARARGS, NULL},
     {(char *) "virConnectListDefinedInterfaces", libvirt_virConnectListDefinedInterfaces, METH_VARARGS, NULL},
     {(char *) "virConnectListAllInterfaces", libvirt_virConnectListAllInterfaces, METH_VARARGS, NULL},
-- 
1.7.7.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]