diff options
| author | Soren Hansen <soren.hansen@rackspace.com> | 2010-08-30 14:50:50 +0200 |
|---|---|---|
| committer | Soren Hansen <soren.hansen@rackspace.com> | 2010-08-30 14:50:50 +0200 |
| commit | f2776632fb94bd55a428bfb9272472e4bd2517bb (patch) | |
| tree | 522e65e37316645d8ac4608ba2a20b1cd4bc2abd | |
| parent | 5f14a7955b9ef90afed91bda0343130d83e15a73 (diff) | |
| download | nova-f2776632fb94bd55a428bfb9272472e4bd2517bb.tar.gz nova-f2776632fb94bd55a428bfb9272472e4bd2517bb.tar.xz nova-f2776632fb94bd55a428bfb9272472e4bd2517bb.zip | |
Detect if libvirt connection has been broken and reestablish it.
| -rw-r--r-- | nova/virt/libvirt_conn.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py index 524646ee5..1ff8175d0 100644 --- a/nova/virt/libvirt_conn.py +++ b/nova/virt/libvirt_conn.py @@ -84,10 +84,22 @@ class LibvirtConnection(object): @property def _conn(self): - if not self._wrapped_conn: + if not self._wrapped_conn or not self._test_connection(): + logging.debug('Connecting to libvirt: %s' % self.libvirt_uri) self._wrapped_conn = self._connect(self.libvirt_uri, self.read_only) return self._wrapped_conn + def _test_connection(self): + try: + self._wrapped_conn.getVersion() + return True + except libvirt.libvirtError as e: + if e.get_error_code() == libvirt.VIR_ERR_SYSTEM_ERROR and \ + e.get_error_domain() == libvirt.VIR_FROM_REMOTE: + logging.debug('Connection to libvirt broke') + return False + raise + def get_uri_and_template(self): if FLAGS.libvirt_type == 'uml': uri = FLAGS.libvirt_uri or 'uml:///system' |
