[PATCH 6/6] python: Add python bindings for virDomainStreamDisk[Info]

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

 



Enable virDomainStreamDiskInfo in the python API.  dom.StreamDiskInfo() will
return a list containing a dictionary for each active stream.  Each dictionary
contains items to report: the disk alias, the current stream offset, and the
total disk size.

virDomainStreamDisk() works with the automatic wrappers.

* python/generator.py: reenable bindings for this entry point
* python/libvirt-override-api.xml python/libvirt-override.c: the
  generator can't handle this new function, add the new binding,
  and the XML description

Signed-off-by: Adam Litke <agl@xxxxxxxxxx>
---
 python/generator.py             |    4 +--
 python/libvirt-override-api.xml |    5 ++++
 python/libvirt-override.c       |   46 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/python/generator.py b/python/generator.py
index 2477b59..d523afd 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -161,8 +161,6 @@ def enum(type, name, value):
 functions_failed = []
 functions_skipped = [
     "virConnectListDomains",
-    "virDomainStreamDisk",
-    "virDomainStreamDiskInfo",
 ]
 
 skipped_modules = {
@@ -177,7 +175,6 @@ skipped_types = {
      'virConnectDomainEventIOErrorCallback': "No function types in python",
      'virConnectDomainEventGraphicsCallback': "No function types in python",
      'virEventAddHandleFunc': "No function types in python",
-     'virStreamDiskStatePtr': "Not implemented yet",
 }
 
 #######################################################################
@@ -337,6 +334,7 @@ skip_impl = (
     'virNodeDeviceListCaps',
     'virConnectBaselineCPU',
     'virDomainRevertToSnapshot',
+    'virDomainStreamDiskInfo',
 )
 
 
diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml
index f209608..207a874 100644
--- a/python/libvirt-override-api.xml
+++ b/python/libvirt-override-api.xml
@@ -296,5 +296,10 @@
       <arg name='flags' type='unsigned int' info='flags, curently unused'/>
       <return type='int' info="0 on success, -1 on error"/>
     </function>
+    <function name='virDomainStreamDiskInfo' file='python'>
+      <info>collect information about active disk streams</info>
+      <arg name='domain' type='virDomainPtr' info='pointer to the domain'/>
+      <return type='virDomainStreamDiskInfo *' info='A list containing one dictionary of statistics for each active stream' />
+    </function> 
   </symbols>
 </api>
diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index 4a03d72..4b91279 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -3491,6 +3491,51 @@ libvirt_virConnectDomainEventDeregisterAny(ATTRIBUTE_UNUSED PyObject * self,
     return (py_retval);
 }
 
+static PyObject *
+libvirt_virDomainStreamDiskInfo(PyObject *self ATTRIBUTE_UNUSED,
+                                PyObject *args) {
+    virDomainPtr domain;
+    PyObject *pyobj_domain;
+    unsigned int nr_streams, i;
+    struct _virStreamDiskState streams[VIR_STREAM_DISK_MAX_STREAMS];
+    PyObject *ret;
+
+    if (!PyArg_ParseTuple(args, (char *)"O:virDomainStreamDiskInfo",
+                          &pyobj_domain))
+        return(NULL);
+    domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
+
+    nr_streams = virDomainStreamDiskInfo(domain, streams,
+                                         VIR_STREAM_DISK_MAX_STREAMS, 0);
+    if (nr_streams == -1)
+        return VIR_PY_NONE;
+
+    if ((ret = PyList_New(nr_streams)) == NULL)
+        return VIR_PY_NONE;
+
+    for (i = 0; i < nr_streams; i++) {
+        PyObject *dict = PyDict_New();
+        if (dict == NULL)
+            goto error;
+        PyDict_SetItem(dict, libvirt_constcharPtrWrap("path"),
+                       libvirt_constcharPtrWrap(streams[i].path));
+        PyDict_SetItem(dict, libvirt_constcharPtrWrap("offset"),
+                       libvirt_ulonglongWrap(streams[i].offset));
+        PyDict_SetItem(dict, libvirt_constcharPtrWrap("size"),
+                       libvirt_ulonglongWrap(streams[i].size));
+        PyList_SetItem(ret, i, dict);
+    }
+    return ret;
+
+error:
+    for (i = 0; i < PyList_Size(ret); i++) {
+        PyObject *item = PyList_GET_ITEM(ret, i);
+        Py_XDECREF(item);
+    }
+    Py_DECREF(ret);
+    return VIR_PY_NONE;
+}
+
 
 /************************************************************************
  *									*
@@ -3566,6 +3611,7 @@ static PyMethodDef libvirtMethods[] = {
     {(char *) "virDomainGetJobInfo", libvirt_virDomainGetJobInfo, METH_VARARGS, NULL},
     {(char *) "virDomainSnapshotListNames", libvirt_virDomainSnapshotListNames, METH_VARARGS, NULL},
     {(char *) "virDomainRevertToSnapshot", libvirt_virDomainRevertToSnapshot, METH_VARARGS, NULL},
+    {(char *) "virDomainStreamDiskInfo", libvirt_virDomainStreamDiskInfo, METH_VARARGS, NULL},
     {NULL, NULL, 0, NULL}
 };
 
-- 
1.7.3.2.164.g6f10c

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