[PATCH 10/10] python: Expose virStorageListAllStoragePools 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: Add listAllStoragePools
python/libvirt-override.c: Implementation for the wrapper.
---
 python/libvirt-override-api.xml       |    6 ++++
 python/libvirt-override-virConnect.py |   12 ++++++++
 python/libvirt-override.c             |   47 +++++++++++++++++++++++++++++++++
 3 files changed, 65 insertions(+), 0 deletions(-)

diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml
index 67ef36e..d16755c 100644
--- a/python/libvirt-override-api.xml
+++ b/python/libvirt-override-api.xml
@@ -306,6 +306,12 @@
       <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
       <return type='str *' info='the list of Names of None in case of error'/>
     </function>
+    <function name='virConnectListAllStoragePools' file='python'>
+      <info>returns list of all storage pools</info>
+      <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
+      <arg name='flags' type='unsigned int' info='optional flags'/>
+      <return type='pool *' info='the list of pools or None in case of error'/>
+    </function>
     <function name='virStoragePoolListVolumes' file='python'>
       <info>list the storage volumes, stores the pointers to the names in @names</info>
       <arg name='pool' type='virStoragePoolPtr' info='pointer to the storage pool'/>
diff --git a/python/libvirt-override-virConnect.py b/python/libvirt-override-virConnect.py
index 50177ab..87a737f 100644
--- a/python/libvirt-override-virConnect.py
+++ b/python/libvirt-override-virConnect.py
@@ -206,3 +206,15 @@
             retlist.append(virDomain(self, _obj=domptr))
 
         return retlist
+
+    def listAllStoragePools(self, flags):
+        """Returns a list of storage pool objects"""
+        ret = libvirtmod.virConnectListAllStoragePools(self._o, flags)
+        if ret is None:
+            raise libvirtError("virConnectListAllStoragePools() failed", conn=self)
+
+        retlist = list()
+        for poolptr in ret:
+            retlist.append(virStoragePool(self, _obj=poolptr))
+
+        return retlist
diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index 65e8c69..1e3ad89 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -2983,6 +2983,52 @@ libvirt_virConnectListDefinedStoragePools(PyObject *self ATTRIBUTE_UNUSED,
     return py_retval;
 }
 
+static PyObject *
+libvirt_virConnectListAllStoragePools(PyObject *self ATTRIBUTE_UNUSED,
+                                      PyObject *args)
+{
+    PyObject *pyobj_conn;
+    PyObject *py_retval = NULL;
+    PyObject *tmp = NULL;
+    virConnectPtr conn;
+    virStoragePoolPtr *pools = NULL;
+    int c_retval = 0;
+    int i;
+    unsigned int flags;
+
+    if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllStoragePools",
+                          &pyobj_conn, &flags))
+        return NULL;
+    conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+
+    LIBVIRT_BEGIN_ALLOW_THREADS;
+    c_retval = virConnectListAllStoragePools(conn, &pools, 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_virStoragePoolPtrWrap(pools[i])) ||
+            PyList_SetItem(py_retval, i, tmp) < 0) {
+            Py_XDECREF(tmp);
+            Py_DECREF(py_retval);
+            py_retval = NULL;
+            goto cleanup;
+        }
+        /* python steals the pointer */
+        pools[i] = NULL;
+    }
+
+cleanup:
+    for (i = 0; i < c_retval; i++)
+        if (pools[i])
+            virStoragePoolFree(pools[i]);
+    VIR_FREE(pools);
+    return py_retval;
+}
 
 static PyObject *
 libvirt_virStoragePoolListVolumes(PyObject *self ATTRIBUTE_UNUSED,
@@ -5878,6 +5924,7 @@ static PyMethodDef libvirtMethods[] = {
     {(char *) "virDomainGetVcpuPinInfo", libvirt_virDomainGetVcpuPinInfo, METH_VARARGS, NULL},
     {(char *) "virConnectListStoragePools", libvirt_virConnectListStoragePools, METH_VARARGS, NULL},
     {(char *) "virConnectListDefinedStoragePools", libvirt_virConnectListDefinedStoragePools, METH_VARARGS, NULL},
+    {(char *) "virConnectListAllStoragePools", libvirt_virConnectListAllStoragePools, METH_VARARGS, NULL},
     {(char *) "virStoragePoolGetAutostart", libvirt_virStoragePoolGetAutostart, METH_VARARGS, NULL},
     {(char *) "virStoragePoolListVolumes", libvirt_virStoragePoolListVolumes, METH_VARARGS, NULL},
     {(char *) "virStoragePoolGetInfo", libvirt_virStoragePoolGetInfo, 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]