summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOsier Yang <jyang@redhat.com>2012-09-04 23:55:21 +0800
committerOsier Yang <jyang@redhat.com>2012-09-11 18:35:14 +0800
commit4b8444d8921c9276e0ae638cad2a07ea2df5879e (patch)
treea7ee490d85f5332c3444a456e35eb9d2cf67692e
parent849f4b05c2842fab80a4f5e828d0127bc87865d9 (diff)
downloadlibvirt-python-v6-4b8444d8921c9276e0ae638cad2a07ea2df5879e.tar.gz
libvirt-python-v6-4b8444d8921c9276e0ae638cad2a07ea2df5879e.tar.xz
libvirt-python-v6-4b8444d8921c9276e0ae638cad2a07ea2df5879e.zip
list: Expose virConnectListAllNetworks 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: Implement listAllNetworks. python/libvirt-override.c: Implementation for the wrapper.
-rw-r--r--libvirt-override-api.xml6
-rw-r--r--libvirt-override-virConnect.py12
-rw-r--r--libvirt-override.c48
3 files changed, 66 insertions, 0 deletions
diff --git a/libvirt-override-api.xml b/libvirt-override-api.xml
index 8a228fb..5f51fc7 100644
--- a/libvirt-override-api.xml
+++ b/libvirt-override-api.xml
@@ -37,6 +37,12 @@
<arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
<return type='str *' info='the list of Names or None in case of error'/>
</function>
+ <function name='virConnectListAllNetworks' file='python'>
+ <info>returns list of all networks</info>
+ <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
+ <arg name='flags' type='unsigned int' info='optional flags'/>
+ <return type='network *' info='the list of networks or None in case of error'/>
+ </function>
<function name='virDomainLookupByUUID' file='python'>
<info>Try to lookup a domain on the given hypervisor based on its UUID.</info>
<return type='virDomainPtr' info='a new domain object or NULL in case of failure'/>
diff --git a/libvirt-override-virConnect.py b/libvirt-override-virConnect.py
index 87a737f..85db5fe 100644
--- a/libvirt-override-virConnect.py
+++ b/libvirt-override-virConnect.py
@@ -218,3 +218,15 @@
retlist.append(virStoragePool(self, _obj=poolptr))
return retlist
+
+ def listAllNetworks(self, flags):
+ """Returns a list of network objects"""
+ ret = libvirtmod.virConnectListAllNetworks(self._o, flags)
+ if ret is None:
+ raise libvirtError("virConnectListAllNetworks() failed", conn=self)
+
+ retlist = list()
+ for netptr in ret:
+ retlist.append(virNetwork(self, _obj=netptr))
+
+ return retlist
diff --git a/libvirt-override.c b/libvirt-override.c
index c1f8938..75bacff 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -2594,6 +2594,53 @@ libvirt_virConnectListDefinedNetworks(PyObject *self ATTRIBUTE_UNUSED,
return py_retval;
}
+static PyObject *
+libvirt_virConnectListAllNetworks(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args)
+{
+ PyObject *pyobj_conn;
+ PyObject *py_retval = NULL;
+ PyObject *tmp = NULL;
+ virConnectPtr conn;
+ virNetworkPtr *nets = NULL;
+ int c_retval = 0;
+ int i;
+ unsigned int flags;
+
+ if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllNetworks",
+ &pyobj_conn, &flags))
+ return NULL;
+ conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ c_retval = virConnectListAllNetworks(conn, &nets, 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_virNetworkPtrWrap(nets[i])) ||
+ PyList_SetItem(py_retval, i, tmp) < 0) {
+ Py_XDECREF(tmp);
+ Py_DECREF(py_retval);
+ py_retval = NULL;
+ goto cleanup;
+ }
+ /* python steals the pointer */
+ nets[i] = NULL;
+ }
+
+cleanup:
+ for (i = 0; i < c_retval; i++)
+ if (nets[i])
+ virNetworkFree(nets[i]);
+ VIR_FREE(nets);
+ return py_retval;
+}
+
static PyObject *
libvirt_virNetworkGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
@@ -5943,6 +5990,7 @@ static PyMethodDef libvirtMethods[] = {
{(char *) "virConnGetLastError", libvirt_virConnGetLastError, METH_VARARGS, NULL},
{(char *) "virConnectListNetworks", libvirt_virConnectListNetworks, METH_VARARGS, NULL},
{(char *) "virConnectListDefinedNetworks", libvirt_virConnectListDefinedNetworks, METH_VARARGS, NULL},
+ {(char *) "virConnectListAllNetworks", libvirt_virConnectListAllNetworks, METH_VARARGS, NULL},
{(char *) "virNetworkGetUUID", libvirt_virNetworkGetUUID, METH_VARARGS, NULL},
{(char *) "virNetworkGetUUIDString", libvirt_virNetworkGetUUIDString, METH_VARARGS, NULL},
{(char *) "virNetworkLookupByUUID", libvirt_virNetworkLookupByUUID, METH_VARARGS, NULL},