[Libvir] [PATCH] Add Python binding for virGetVersion

Richard W.M. Jones rjones at redhat.com
Wed May 23 15:50:35 UTC 2007

Richard W.M. Jones wrote:
> Daniel P. Berrange wrote:
>> On Wed, May 23, 2007 at 03:58:02PM +0100, Richard W.M. Jones wrote:
>>> This patch adds a Python binding for the virGetVersion call (called 
>>> libvirt.getVersion).
>> Looks good to me.
> Actually, it contains a subtle error.  Improved patch coming up ...

The error was in the handling of the case where you pass None to the 
function.  Previously that would pass a NULL type and non-NULL typeVer 
to the underlying C function, which the underlying C function would 
interpret as a request to get the version of the Xen driver.

Bad idea if libvirt is compiled --without-xen.

The new version treats None as meaning that we just want to get the 
version of the main library.

The semantics of the new version are described in the Python documentation:

+    """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 only the first element of the
+    tuple (library version) is meaningful.  The second element will
+    be zero.
+    If the name passed refers to a non-existent driver, then you
+    will get the exception 'no support for hypervisor'.
+    Versions are 1000000*major + 1000*minor + release."""

and shown in the example below:

$ 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, 0)
 >>> libvirt.getVersion ("Xen");
(2002, 3000001)
 >>> libvirt.getVersion ("QEMU");
(2002, 2002)
 >>> 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 102, in getVersion
     if ret is None: raise libvirtError ("virGetVersion() failed")
libvirt.libvirtError: virGetVersion() failed no support for hypervisor


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libvirt-python-version-20070523-2.patch
Type: text/x-patch
Size: 3600 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20070523/12bb3444/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3237 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20070523/12bb3444/attachment-0003.bin>

More information about the libvir-list mailing list