diff --git a/src/middlewared/middlewared/plugins/vm/connection.py b/src/middlewared/middlewared/plugins/vm/connection.py index e415cb2e2b2e6..ab84cb9872147 100644 --- a/src/middlewared/middlewared/plugins/vm/connection.py +++ b/src/middlewared/middlewared/plugins/vm/connection.py @@ -65,7 +65,10 @@ def _check_connection_alive(self): if not self._is_libvirt_connection_alive(): raise CallError('Failed to connect to libvirt') - def _check_setup_connection(self): + def _safely_check_setup_connection(self, timeout: int = 10): if not self._is_connection_alive(): - self.middleware.call_sync('vm.setup_libvirt_connection', 10) + self.middleware.call_sync('vm.setup_libvirt_connection', timeout) + + def _check_setup_connection(self): + self._safely_check_setup_connection() self._check_connection_alive() diff --git a/src/middlewared/middlewared/plugins/vm/vms.py b/src/middlewared/middlewared/plugins/vm/vms.py index f9213c888009a..4c01abf071108 100644 --- a/src/middlewared/middlewared/plugins/vm/vms.py +++ b/src/middlewared/middlewared/plugins/vm/vms.py @@ -101,9 +101,11 @@ def extend_context(self, rows, extra): status = {} kvm_supported = self._is_kvm_supported() if rows and kvm_supported: - self._check_setup_connection() + self._safely_check_setup_connection(5) + + libvirt_running = self._is_connection_alive() for row in rows: - status[row['id']] = self.status_impl(row) if kvm_supported else get_default_status() + status[row['id']] = self.status_impl(row) if libvirt_running else get_default_status() return { 'status': status,