aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorPeter Krempa <pkrempa@redhat.com>2012-05-20 16:20:11 +0200
committerPeter Krempa <pkrempa@redhat.com>2012-06-18 21:24:13 +0200
commitbd34cc8c451b03a044e98d2f68e25620e15c4831 (patch)
tree3305aca5dd08aa61ab0b872411199e0f87bab015 /python
parentlib: Add public api to enable atomic listing of guest (diff)
downloadlibvirt-bd34cc8c451b03a044e98d2f68e25620e15c4831.tar.gz
libvirt-bd34cc8c451b03a044e98d2f68e25620e15c4831.tar.bz2
libvirt-bd34cc8c451b03a044e98d2f68e25620e15c4831.zip
python: add API exports for virConnectListAllDomains()
This patch adds export of the new API function virConnectListAllDomains() to the libvirt-python bindings. The virConnect object now has method "listAllDomains" that takes only the flags parameter and returns a python list of virDomain object corresponding to virDomainPtrs returned by the underlying api. The implementation is done manually as the generator does not support wrapping list of virDomainPtrs into virDomain objects.
Diffstat (limited to 'python')
-rw-r--r--python/libvirt-override-api.xml12
-rw-r--r--python/libvirt-override-virConnect.py12
-rw-r--r--python/libvirt-override.c50
3 files changed, 70 insertions, 4 deletions
diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml
index 0bafd21e8..2fd6dec4e 100644
--- a/python/libvirt-override-api.xml
+++ b/python/libvirt-override-api.xml
@@ -19,17 +19,23 @@
<function name='virConnectListDefinedDomains' file='python'>
<info>list the defined domains, stores the pointers to the names in @names</info>
<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'/>
+ <return type='str *' info='the list of Names or None in case of error'/>
+ </function>
+ <function name='virConnectListAllDomains' file='python'>
+ <info>returns list of all defined domains</info>
+ <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
+ <arg name='flags' type='unsigned int' info='optional flags'/>
+ <return type='domain *' info='the list of domains or None in case of error'/>
</function>
<function name='virConnectListNetworks' file='python'>
<info>list the networks, stores the pointers to the names in @names</info>
<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'/>
+ <return type='str *' info='the list of Names or None in case of error'/>
</function>
<function name='virConnectListDefinedNetworks' file='python'>
<info>list the defined networks, stores the pointers to the names in @names</info>
<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'/>
+ <return type='str *' info='the list of Names 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>
diff --git a/python/libvirt-override-virConnect.py b/python/libvirt-override-virConnect.py
index 811e16bbf..ecb568053 100644
--- a/python/libvirt-override-virConnect.py
+++ b/python/libvirt-override-virConnect.py
@@ -185,3 +185,15 @@
raise libvirtError ('virConnectDomainEventRegisterAny() failed', conn=self)
self.domainEventCallbackID[ret] = opaque
return ret
+
+ def listAllDomains(self, flags):
+ """List all domains and returns a list of domain objects"""
+ ret = libvirtmod.virConnectListAllDomains(self._o, flags)
+ if ret is None:
+ raise libvirtError("virConnectListAllDomains() failed", conn=self)
+
+ retlist = list()
+ for domptr in ret:
+ retlist.append(virDomain(self, _obj=domptr))
+
+ return retlist
diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index 676002c4b..cfbf254a0 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -1938,7 +1938,7 @@ libvirt_virConnectGetLibVersion (PyObject *self ATTRIBUTE_UNUSED,
static PyObject *
libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED,
- PyObject *args) {
+ PyObject *args) {
PyObject *py_retval;
int *ids = NULL, c_retval, i;
virConnectPtr conn;
@@ -1980,6 +1980,53 @@ libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED,
}
static PyObject *
+libvirt_virConnectListAllDomains(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args)
+{
+ PyObject *pyobj_conn;
+ PyObject *py_retval = NULL;
+ PyObject *tmp = NULL;
+ virConnectPtr conn;
+ virDomainPtr *doms = NULL;
+ int c_retval = 0;
+ int i;
+ unsigned int flags;
+
+ if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllDomains",
+ &pyobj_conn, &flags))
+ return NULL;
+ conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ c_retval = virConnectListAllDomains(conn, &doms, 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_virDomainPtrWrap(doms[i])) ||
+ PyList_SetItem(py_retval, i, tmp) < 0) {
+ Py_XDECREF(tmp);
+ Py_DECREF(py_retval);
+ py_retval = NULL;
+ goto cleanup;
+ }
+ /* python steals the pointer */
+ doms[i] = NULL;
+ }
+
+cleanup:
+ for (i = 0; i < c_retval; i++)
+ if (doms[i])
+ virDomainFree(doms[i]);
+ VIR_FREE(doms);
+ return py_retval;
+}
+
+static PyObject *
libvirt_virConnectListDefinedDomains(PyObject *self ATTRIBUTE_UNUSED,
PyObject *args) {
PyObject *py_retval;
@@ -5634,6 +5681,7 @@ static PyMethodDef libvirtMethods[] = {
{(char *) "virConnectOpenAuth", libvirt_virConnectOpenAuth, METH_VARARGS, NULL},
{(char *) "virConnectListDomainsID", libvirt_virConnectListDomainsID, METH_VARARGS, NULL},
{(char *) "virConnectListDefinedDomains", libvirt_virConnectListDefinedDomains, METH_VARARGS, NULL},
+ {(char *) "virConnectListAllDomains", libvirt_virConnectListAllDomains, METH_VARARGS, NULL},
{(char *) "virConnectDomainEventRegister", libvirt_virConnectDomainEventRegister, METH_VARARGS, NULL},
{(char *) "virConnectDomainEventDeregister", libvirt_virConnectDomainEventDeregister, METH_VARARGS, NULL},
{(char *) "virConnectDomainEventRegisterAny", libvirt_virConnectDomainEventRegisterAny, METH_VARARGS, NULL},