list: Expose virConnectListAllInterfaces 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:
  * New file, includes implementation of listAllInterfaces.

python/libvirt-override.c: Implementation for the wrapper.
This commit is contained in:
Osier Yang 2012-09-05 00:10:19 +08:00
parent 3c2e6472d8
commit ec448fbf17
3 changed files with 66 additions and 0 deletions

View File

@ -416,6 +416,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='virConnectListAllInterfaces' file='python'>
<info>returns list of all interfaces</info>
<arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
<arg name='flags' type='unsigned int' info='optional flags'/>
<return type='interface *' info='the list of interfaces or None in case of error'/>
</function>
<function name='virConnectBaselineCPU' file='python'>
<info>Computes the most feature-rich CPU which is compatible with all given host CPUs.</info>
<return type='char *' info='XML description of the computed CPU or NULL on error.'/>

View File

@ -230,3 +230,15 @@
retlist.append(virNetwork(self, _obj=netptr))
return retlist
def listAllInterfaces(self, flags):
"""Returns a list of interface objects"""
ret = libvirtmod.virConnectListAllInterfaces(self._o, flags)
if ret is None:
raise libvirtError("virConnectListAllInterfaces() failed", conn=self)
retlist = list()
for ifaceptr in ret:
retlist.append(virInterface(self, _obj=ifaceptr))
return retlist

View File

@ -3827,6 +3827,53 @@ libvirt_virConnectListDefinedInterfaces(PyObject *self ATTRIBUTE_UNUSED,
}
static PyObject *
libvirt_virConnectListAllInterfaces(PyObject *self ATTRIBUTE_UNUSED,
PyObject *args)
{
PyObject *pyobj_conn;
PyObject *py_retval = NULL;
PyObject *tmp = NULL;
virConnectPtr conn;
virInterfacePtr *ifaces = NULL;
int c_retval = 0;
int i;
unsigned int flags;
if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllInterfaces",
&pyobj_conn, &flags))
return NULL;
conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
LIBVIRT_BEGIN_ALLOW_THREADS;
c_retval = virConnectListAllInterfaces(conn, &ifaces, 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_virInterfacePtrWrap(ifaces[i])) ||
PyList_SetItem(py_retval, i, tmp) < 0) {
Py_XDECREF(tmp);
Py_DECREF(py_retval);
py_retval = NULL;
goto cleanup;
}
/* python steals the pointer */
ifaces[i] = NULL;
}
cleanup:
for (i = 0; i < c_retval; i++)
if (ifaces[i])
virInterfaceFree(ifaces[i]);
VIR_FREE(ifaces);
return py_retval;
}
static PyObject *
libvirt_virConnectBaselineCPU(PyObject *self ATTRIBUTE_UNUSED,
PyObject *args) {
@ -6053,6 +6100,7 @@ static PyMethodDef libvirtMethods[] = {
{(char *) "virConnectListNWFilters", libvirt_virConnectListNWFilters, METH_VARARGS, NULL},
{(char *) "virConnectListInterfaces", libvirt_virConnectListInterfaces, METH_VARARGS, NULL},
{(char *) "virConnectListDefinedInterfaces", libvirt_virConnectListDefinedInterfaces, METH_VARARGS, NULL},
{(char *) "virConnectListAllInterfaces", libvirt_virConnectListAllInterfaces, METH_VARARGS, NULL},
{(char *) "virConnectBaselineCPU", libvirt_virConnectBaselineCPU, METH_VARARGS, NULL},
{(char *) "virDomainGetJobInfo", libvirt_virDomainGetJobInfo, METH_VARARGS, NULL},
{(char *) "virDomainSnapshotListNames", libvirt_virDomainSnapshotListNames, METH_VARARGS, NULL},