[PATCHv2 10/13] list: provide python bindings for snapshots

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This adds support for the new virDomainListAllSnapshots (a domain
function) and virDomainSnapshotListAllChildren (a snapshot function)
to the libvirt-python bindings.  The implementation is done manually
as the generator does not support wrapping lists of C pointers into
python objects.

* python/libvirt-override.c (libvirt_virDomainListAllSnapshots)
(libvirt_virDomainSnapshotListAllChildren): New functions.
* python/libvirt-override-api.xml: Document them.
* python/libvirt-override-virDomain.py (listAllSnapshots): New
file.
* python/libvirt-override-virDomainSnapshot.py (listAllChildren):
Likewise.
* python/Makefile.am (CLASSES_EXTRA): Ship them.
---

v2: no real change

 python/Makefile.am                           |    2 +
 python/libvirt-override-api.xml              |   16 ++++-
 python/libvirt-override-virDomain.py         |   11 +++
 python/libvirt-override-virDomainSnapshot.py |   11 +++
 python/libvirt-override.c                    |   92 ++++++++++++++++++++++++++
 5 files changed, 130 insertions(+), 2 deletions(-)
 create mode 100644 python/libvirt-override-virDomain.py
 create mode 100644 python/libvirt-override-virDomainSnapshot.py

diff --git a/python/Makefile.am b/python/Makefile.am
index 02b59eb..97f21c3 100644
--- a/python/Makefile.am
+++ b/python/Makefile.am
@@ -24,6 +24,8 @@ DOCS = ${srcdir}/TODO

 CLASSES_EXTRA = \
 	libvirt-override-virConnect.py \
+	libvirt-override-virDomain.py \
+	libvirt-override-virDomainSnapshot.py \
 	libvirt-override-virStream.py

 EXTRA_DIST =			\
diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml
index 2fd6dec..67ef36e 100644
--- a/python/libvirt-override-api.xml
+++ b/python/libvirt-override-api.xml
@@ -406,17 +406,29 @@
       <arg name='flags' type='unsigned int' info='fine-tuning flags, currently unused, pass 0.'/>
     </function>
     <function name='virDomainSnapshotListNames' file='python'>
-      <info>collect the list of snapshots for the given domain</info>
+      <info>collect the list of snapshot names for the given domain</info>
       <arg name='dom' type='virDomainPtr' info='pointer to the domain'/>
       <arg name='flags' type='unsigned int' info='flags'/>
       <return type='str *' info='the list of Names or None in case of error'/>
     </function>
+    <function name='virDomainListAllSnapshots' file='python'>
+      <info>returns the list of snapshots for the given domain</info>
+      <arg name='dom' type='virDomainPtr' info='pointer to the domain'/>
+      <arg name='flags' type='unsigned int' info='flags'/>
+      <return type='snapshot *' info='the list of snapshots or None in case of error'/>
+    </function>
     <function name='virDomainSnapshotListChildrenNames' file='python'>
-      <info>collect the list of child snapshots for the given snapshot</info>
+      <info>collect the list of child snapshot names for the given snapshot</info>
       <arg name='snapshot' type='virDomainSnapshotPtr' info='pointer to the snapshot'/>
       <arg name='flags' type='unsigned int' info='flags'/>
       <return type='str *' info='the list of Names or None in case of error'/>
     </function>
+    <function name='virDomainSnapshotListAllChildren' file='python'>
+      <info>returns the list of child snapshots for the given snapshot</info>
+      <arg name='snapshot' type='virDomainSnapshotPtr' info='pointer to the snapshot'/>
+      <arg name='flags' type='unsigned int' info='flags'/>
+      <return type='snapshot *' info='the list of snapshots or None in case of error'/>
+    </function>
     <function name='virDomainRevertToSnapshot' file='python'>
       <info>revert the domain to the given snapshot</info>
       <arg name='dom' type='virDomainPtr' info='dummy domain pointer'/>
diff --git a/python/libvirt-override-virDomain.py b/python/libvirt-override-virDomain.py
new file mode 100644
index 0000000..ccc4d5f
--- /dev/null
+++ b/python/libvirt-override-virDomain.py
@@ -0,0 +1,11 @@
+    def listAllSnapshots(self, flags):
+        """List all snapshots and returns a list of snapshot objects"""
+        ret = libvirtmod.virDomainListAllSnapshots(self._o, flags)
+        if ret is None:
+            raise libvirtError("virDomainListAllSnapshots() failed", conn=self)
+
+        retlist = list()
+        for snapptr in ret:
+            retlist.append(virDomainSnapshot(self, _obj=snapptr))
+
+        return retlist
diff --git a/python/libvirt-override-virDomainSnapshot.py b/python/libvirt-override-virDomainSnapshot.py
new file mode 100644
index 0000000..3da7bfd
--- /dev/null
+++ b/python/libvirt-override-virDomainSnapshot.py
@@ -0,0 +1,11 @@
+    def listAllChildren(self, flags):
+        """List all child snapshots and returns a list of snapshot objects"""
+        ret = libvirtmod.virDomainSnapshotListAllChildren(self._o, flags)
+        if ret is None:
+            raise libvirtError("virDomainSnapshotListAllChildren() failed", conn=self)
+
+        retlist = list()
+        for snapptr in ret:
+            retlist.append(virDomainSnapshot(self, _obj=snapptr))
+
+        return retlist
diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index 8d1ede1..4370045 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -2127,6 +2127,51 @@ cleanup:
 }

 static PyObject *
+libvirt_virDomainListAllSnapshots(PyObject *self ATTRIBUTE_UNUSED,
+                                  PyObject *args)
+{
+    PyObject *py_retval = NULL;
+    virDomainSnapshotPtr *snaps = NULL;
+    int c_retval, i;
+    virDomainPtr dom;
+    PyObject *pyobj_dom;
+    unsigned int flags;
+    PyObject *pyobj_snap;
+
+    if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainListAllSnapshots",
+                          &pyobj_dom, &flags))
+        return NULL;
+    dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
+
+    LIBVIRT_BEGIN_ALLOW_THREADS;
+    c_retval = virDomainListAllSnapshots(dom, &snaps, 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 ((pyobj_snap = libvirt_virDomainSnapshotPtrWrap(snaps[i])) == NULL ||
+            PyList_SetItem(py_retval, i, pyobj_snap) < 0) {
+            Py_XDECREF(pyobj_snap);
+            Py_DECREF(py_retval);
+            py_retval = NULL;
+            goto cleanup;
+        }
+        snaps[i] = NULL;
+    }
+
+cleanup:
+    for (i = 0; i < c_retval; i++)
+        if (snaps[i])
+            virDomainSnapshotFree(snaps[i]);
+    VIR_FREE(snaps);
+    return py_retval;
+}
+
+static PyObject *
 libvirt_virDomainSnapshotListChildrenNames(PyObject *self ATTRIBUTE_UNUSED,
                                            PyObject *args)
 {
@@ -2181,6 +2226,51 @@ cleanup:
 }

 static PyObject *
+libvirt_virDomainSnapshotListAllChildren(PyObject *self ATTRIBUTE_UNUSED,
+                                         PyObject *args)
+{
+    PyObject *py_retval = NULL;
+    virDomainSnapshotPtr *snaps = NULL;
+    int c_retval, i;
+    virDomainSnapshotPtr parent;
+    PyObject *pyobj_parent;
+    unsigned int flags;
+    PyObject *pyobj_snap;
+
+    if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainSnapshotListAllChildren",
+                          &pyobj_parent, &flags))
+        return NULL;
+    parent = (virDomainSnapshotPtr) PyvirDomainSnapshot_Get(pyobj_parent);
+
+    LIBVIRT_BEGIN_ALLOW_THREADS;
+    c_retval = virDomainSnapshotListAllChildren(parent, &snaps, 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 ((pyobj_snap = libvirt_virDomainSnapshotPtrWrap(snaps[i])) == NULL ||
+            PyList_SetItem(py_retval, i, pyobj_snap) < 0) {
+            Py_XDECREF(pyobj_snap);
+            Py_DECREF(py_retval);
+            py_retval = NULL;
+            goto cleanup;
+        }
+        snaps[i] = NULL;
+    }
+
+cleanup:
+    for (i = 0; i < c_retval; i++)
+        if (snaps[i])
+            virDomainSnapshotFree(snaps[i]);
+    VIR_FREE(snaps);
+    return py_retval;
+}
+
+static PyObject *
 libvirt_virDomainRevertToSnapshot(PyObject *self ATTRIBUTE_UNUSED,
                                   PyObject *args) {
     int c_retval;
@@ -5763,7 +5853,9 @@ static PyMethodDef libvirtMethods[] = {
     {(char *) "virConnectBaselineCPU", libvirt_virConnectBaselineCPU, METH_VARARGS, NULL},
     {(char *) "virDomainGetJobInfo", libvirt_virDomainGetJobInfo, METH_VARARGS, NULL},
     {(char *) "virDomainSnapshotListNames", libvirt_virDomainSnapshotListNames, METH_VARARGS, NULL},
+    {(char *) "virDomainListAllSnapshots", libvirt_virDomainListAllSnapshots, METH_VARARGS, NULL},
     {(char *) "virDomainSnapshotListChildrenNames", libvirt_virDomainSnapshotListChildrenNames, METH_VARARGS, NULL},
+    {(char *) "virDomainSnapshotListAllChildren", libvirt_virDomainSnapshotListAllChildren, METH_VARARGS, NULL},
     {(char *) "virDomainRevertToSnapshot", libvirt_virDomainRevertToSnapshot, METH_VARARGS, NULL},
     {(char *) "virDomainGetBlockJobInfo", libvirt_virDomainGetBlockJobInfo, METH_VARARGS, NULL},
     {(char *) "virDomainSetBlockIoTune", libvirt_virDomainSetBlockIoTune, METH_VARARGS, NULL},
-- 
1.7.10.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]