aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorOsier Yang <jyang@redhat.com>2012-09-04 23:16:33 +0800
committerOsier Yang <jyang@redhat.com>2012-09-06 22:16:11 +0800
commit9278578069033f7bd866dd2bba0b4ee2c041ba67 (patch)
tree172b260ca885f07415b5bf4998951d3107366a32 /python
parentlist: Use virConnectListAllStoragePools in virsh (diff)
downloadlibvirt-9278578069033f7bd866dd2bba0b4ee2c041ba67.tar.gz
libvirt-9278578069033f7bd866dd2bba0b4ee2c041ba67.tar.bz2
libvirt-9278578069033f7bd866dd2bba0b4ee2c041ba67.zip
python: Expose virStorageListAllStoragePools to python binding
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.
Diffstat (limited to 'python')
-rw-r--r--python/libvirt-override-api.xml6
-rw-r--r--python/libvirt-override-virConnect.py12
-rw-r--r--python/libvirt-override.c47
3 files changed, 65 insertions, 0 deletions
diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml
index 67ef36e30..d16755c26 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 50177abb4..87a737f1f 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 65e8c69dd..1e3ad89f1 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},