[PATCH] Add Python binding for virGetVersion

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

 



This patch adds a Python binding for the virGetVersion call (called libvirt.getVersion).

$ python
Python 2.4.4 (#1, Oct 23 2006, 13:58:18)
[GCC 4.1.1 20061011 (Red Hat 4.1.1-30)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import libvirt;
>>> libvirt.getVersion (None);
(2002, 3000001)
>>> libvirt.getVersion ("QEMU");
(2002, 2002)

It also gives you a way to detect if a particular driver is compiled in, which I guess could be quite useful:

>>> libvirt.getVersion ("not_here");
libvir: error : no support for hypervisor
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
File "/home/rjones/local/lib/python2.4/site-packages/libvirt.py", line 95, in getVersion
    if ret is None: raise libvirtError ("virGetVersion() failed")
libvirt.libvirtError: virGetVersion() failed no support for hypervisor

Rich.

--
Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom.  Registered in
England and Wales under Company Registration No. 03798903
Index: python/generator.py
===================================================================
RCS file: /data/cvs/libvirt/python/generator.py,v
retrieving revision 1.20
diff -u -r1.20 generator.py
--- python/generator.py	16 Apr 2007 12:37:59 -0000	1.20
+++ python/generator.py	23 May 2007 14:54:53 -0000
@@ -287,6 +287,8 @@
         return 1
     if name == "vshRunConsole":
         return 1
+    if name == "virGetVersion":
+        return 1
     return 0
 
 def print_function_wrapper(name, output, export, include):
Index: python/libvir.c
===================================================================
RCS file: /data/cvs/libvirt/python/libvir.c,v
retrieving revision 1.21
diff -u -r1.21 libvir.c
--- python/libvir.c	10 Apr 2007 23:15:58 -0000	1.21
+++ python/libvir.c	23 May 2007 14:54:53 -0000
@@ -179,6 +179,26 @@
  ************************************************************************/
 
 static PyObject *
+libvirt_virGetVersion (PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
+{
+    char *type;
+    unsigned long libVer, typeVer;
+    int c_retval;
+
+    if (!PyArg_ParseTuple (args, (char *) "z", &type))
+        return NULL;
+
+    LIBVIRT_BEGIN_ALLOW_THREADS;
+    c_retval = virGetVersion (&libVer, type, &typeVer);
+    LIBVIRT_END_ALLOW_THREADS;
+    if (c_retval == -1) {
+        Py_INCREF(Py_None);
+        return (Py_None);
+    }
+    return Py_BuildValue ((char *) "kk", libVer, typeVer);
+}
+
+static PyObject *
 libvirt_virDomainFree(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
     PyObject *py_retval;
     int c_retval;
@@ -628,6 +648,7 @@
  ************************************************************************/
 static PyMethodDef libvirtMethods[] = {
 #include "libvirt-export.c"
+    {(char *) "virGetVersion", libvirt_virGetVersion, METH_VARARGS, NULL},
     {(char *) "virDomainFree", libvirt_virDomainFree, METH_VARARGS, NULL},
     {(char *) "virConnectClose", libvirt_virConnectClose, METH_VARARGS, NULL},
     {(char *) "virConnectListDomainsID", libvirt_virConnectListDomainsID, METH_VARARGS, NULL},
@@ -664,3 +685,17 @@
 
     initialized = 1;
 }
+
+/*
+ * vim: set tabstop=4:
+ * vim: set shiftwidth=4:
+ * vim: set expandtab:
+ */
+/*
+ * Local variables:
+ *  indent-tabs-mode: nil
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ *  tab-width: 4
+ * End:
+ */
Index: python/libvir.py
===================================================================
RCS file: /data/cvs/libvirt/python/libvir.py,v
retrieving revision 1.4
diff -u -r1.4 libvir.py
--- python/libvir.py	16 Apr 2007 12:37:59 -0000	1.4
+++ python/libvir.py	23 May 2007 14:54:53 -0000
@@ -83,6 +83,19 @@
        Returns 1 in case of success."""
     return libvirtmod.virRegisterErrorHandler(f,ctx)
 
+#
+# Return library version.
+#
+def getVersion (name):
+    """Return a tuple containing the version of the library and
+    a version of the driver with the given name.  If the name
+    passed is None then the version of the Xen driver is given,
+    if it exists.  Versions are 1000000*major + 1000*minor + release."""
+    ret = libvirtmod.virGetVersion (name);
+    if ret is None: raise libvirtError ("virGetVersion() failed")
+    return ret
+
+
 # WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
 #
 # Everything before this line comes from libvir.py

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


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