qubes: implement offline mode

Apparently the most important (the only?) property required in offline
mode is "is_running". So let's patch it to return False and make sure
any other libvirt usage would result in failure.

Or maybe better simply returh False in vm.is_running, when libvirt
connection fails? But then it would not be possible to use offline mode
and have (some, probably unrelated) libvirtd running at the same time.

Fixes QubesOS/qubes-issues#2008
This commit is contained in:
Marek Marczykowski-Górecki 2016-05-21 03:26:39 +02:00 committed by Wojtek Porczyk
parent b119b2c36b
commit ff78b26f66
2 changed files with 7 additions and 12 deletions

View File

@ -126,25 +126,17 @@ class VirConnectWrapper(object):
class VMMConnection(object):
'''Connection to Virtual Machine Manager (libvirt)'''
def __init__(self):
def __init__(self, offline_mode=False):
self._libvirt_conn = None
self._xs = None
self._xc = None
self._offline_mode = False
self._offline_mode = offline_mode
@property
def offline_mode(self):
'''Check or enable offline mode (do not actually connect to vmm)'''
return self._offline_mode
@offline_mode.setter
def offline_mode(self, value):
if value and self._libvirt_conn is not None:
raise qubes.exc.QubesException(
'Cannot change offline mode while already connected')
self._offline_mode = value
def _libvirt_error_handler(self, ctx, error):
pass
@ -563,7 +555,7 @@ class Qubes(qubes.PropertyHolder):
default=True,
doc='check for updates inside qubes')
def __init__(self, store=None, load=True, **kwargs):
def __init__(self, store=None, load=True, offline_mode=False, **kwargs):
#: logger instance for logging global messages
self.log = logging.getLogger('app')
@ -579,7 +571,7 @@ class Qubes(qubes.PropertyHolder):
self.pools = {}
#: Connection to VMM
self.vmm = VMMConnection()
self.vmm = VMMConnection(offline_mode=offline_mode)
#: Information about host system
self.host = QubesHost(self)

View File

@ -1324,6 +1324,9 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
:rtype: bool
'''
if self.app.vmm.offline_mode:
return False
# TODO context manager #1693
return self.libvirt_domain and self.libvirt_domain.isActive()