[libvirt] [PATCH 5/5] list: Expose virConnectListAllInterfaces to Python binding
Laine Stump
laine at laine.org
Mon Sep 10 17:49:35 UTC 2012
On 09/04/2012 12:10 PM, Osier Yang wrote:
> The implementation is done manually as the generator does not support
> wrapping lists of C pointers into Python objects.
Same comment as for the virNetwork series that maybe the generator
should be taught how to do this automatically. Failing that, ACK.
>
> 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.
> ---
> python/libvirt-override-api.xml | 6 ++++
> python/libvirt-override-virConnect.py | 12 ++++++++
> python/libvirt-override.c | 48 +++++++++++++++++++++++++++++++++
> 3 files changed, 66 insertions(+), 0 deletions(-)
>
> diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml
> index 5f51fc7..ab6f407 100644
> --- a/python/libvirt-override-api.xml
> +++ b/python/libvirt-override-api.xml
> @@ -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.'/>
> diff --git a/python/libvirt-override-virConnect.py b/python/libvirt-override-virConnect.py
> index 85db5fe..ffa1a3c 100644
> --- a/python/libvirt-override-virConnect.py
> +++ b/python/libvirt-override-virConnect.py
> @@ -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
> diff --git a/python/libvirt-override.c b/python/libvirt-override.c
> index 3426560..0675545 100644
> --- a/python/libvirt-override.c
> +++ b/python/libvirt-override.c
> @@ -3824,6 +3824,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) {
> PyObject *pyobj_conn;
> @@ -6049,6 +6096,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},
More information about the libvir-list
mailing list