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.
This commit is contained in:
Osier Yang 2012-09-04 23:55:21 +08:00
parent 895913dd59
commit 9cc4270112
3 changed files with 66 additions and 0 deletions

View File

@ -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'/>

View File

@ -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

View File

@ -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},