From 02db94dc33d72182201fd78651e5e5e82ab411c2 Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Wed, 23 Mar 2011 01:22:11 -0700 Subject: Earlier versions of the python libvirt binding had getVersion in the libvirt namespace, not on the connection object. Check both. --- nova/virt/libvirt_conn.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py index f264cf619..0fabec4d0 100644 --- a/nova/virt/libvirt_conn.py +++ b/nova/virt/libvirt_conn.py @@ -981,7 +981,11 @@ class LibvirtConnection(object): """ - return self._conn.getVersion() + # NOTE(justinsb): getVersion moved between libvirt versions + method = getattr(self._conn, 'getVersion', None) # Newer location + if method is None: + method = getattr(libvirt, 'getVersion') # Older location + return method() def get_cpu_info(self): """Get cpuinfo information. -- cgit From 05c4257545fb598222cb472d59d9b8be7ba9535a Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Wed, 23 Mar 2011 13:29:29 -0700 Subject: Give the user a nicer error message if they're using the Lucid libvirt --- nova/virt/libvirt_conn.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py index 0fabec4d0..26d34b367 100644 --- a/nova/virt/libvirt_conn.py +++ b/nova/virt/libvirt_conn.py @@ -982,10 +982,14 @@ class LibvirtConnection(object): """ # NOTE(justinsb): getVersion moved between libvirt versions - method = getattr(self._conn, 'getVersion', None) # Newer location + # Trying to do be compatible with older versions is a lost cause + # But ... we can at least give the user a nice message + method = getattr(self._conn, 'getVersion', None) if method is None: - method = getattr(libvirt, 'getVersion') # Older location - return method() + raise exception.Error(_("libvirt version is too old" + " (does not support getVersion)")) + + return self._conn.getVersion() def get_cpu_info(self): """Get cpuinfo information. -- cgit From d966b1989224b8ba7bf580a3f3f8fc0f04b9a566 Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Wed, 23 Mar 2011 13:34:56 -0700 Subject: Keep the fallback code - we may want to do better version checking in future --- nova/virt/libvirt_conn.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py index 26d34b367..ba794cfd8 100644 --- a/nova/virt/libvirt_conn.py +++ b/nova/virt/libvirt_conn.py @@ -988,8 +988,11 @@ class LibvirtConnection(object): if method is None: raise exception.Error(_("libvirt version is too old" " (does not support getVersion)")) + # NOTE(justinsb): If we wanted to get the version, we could: + # method = getattr(libvirt, 'getVersion', None) + # NOTE(justinsb): This would then rely on a proper version check - return self._conn.getVersion() + return method() def get_cpu_info(self): """Get cpuinfo information. -- cgit