def _get_new_connection(self):
    LOG.debug('Connecting to libvirt: %s', self.uri())
    wrapped_conn = None
    try:
        wrapped_conn = self._connect(self.uri(), self.read_only)
    finally:
        disable_reason = DISABLE_REASON_UNDEFINED
        if (not wrapped_conn):
            disable_reason = 'Failed to connect to libvirt'
        self._set_host_enabled(bool(wrapped_conn), disable_reason)
    self._wrapped_conn = wrapped_conn
    self._skip_list_all_domains = False
    try:
        LOG.debug('Registering for lifecycle events %s', self)
        wrapped_conn.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_LIFECYCLE, self._event_lifecycle_callback, self)
    except Exception as e:
        LOG.warn(_LW('URI %(uri)s does not support events: %(error)s'), {'uri': self.uri(), 'error': e})
    try:
        LOG.debug('Registering for connection events: %s', str(self))
        wrapped_conn.registerCloseCallback(self._close_callback, None)
    except (TypeError, AttributeError) as e:
        LOG.debug('The version of python-libvirt does not support registerCloseCallback or is too old: %s', e)
    except libvirt.libvirtError as e:
        LOG.warn(_LW('URI %(uri)s does not support connection events: %(error)s'), {'uri': self.uri(), 'error': e})
    return wrapped_conn
def _get_new_connection(self):
    LOG.debug('Connecting to libvirt: %s', self.uri())
    wrapped_conn = None
    try:
        wrapped_conn = self._connect(self.uri(), self.read_only)
    finally:
        disable_reason = DISABLE_REASON_UNDEFINED
        if (not wrapped_conn):
            disable_reason = 'Failed to connect to libvirt'
        self._set_host_enabled(bool(wrapped_conn), disable_reason)
    self._wrapped_conn = wrapped_conn
    self._skip_list_all_domains = False
    try:
        LOG.debug('Registering for lifecycle events %s', self)
        wrapped_conn.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_LIFECYCLE, self._event_lifecycle_callback, self)
    except Exception as e:
        LOG.warn(_LW('URI %(uri)s does not support events: %(error)s'), {'uri': self.uri(), 'error': e})
    try:
        LOG.debug('Registering for connection events: %s', str(self))
        wrapped_conn.registerCloseCallback(self._close_callback, None)
    except (TypeError, AttributeError) as e:
        LOG.debug('The version of python-libvirt does not support registerCloseCallback or is too old: %s', e)
    except libvirt.libvirtError as e:
        LOG.warn(_LW('URI %(uri)s does not support connection events: %(error)s'), {'uri': self.uri(), 'error': e})
    return wrapped_conn