qubes/vm: fix handling dynamic netvm change

Correctly detach network before attaching new one.
This commit is contained in:
Marek Marczykowski-Górecki 2016-09-06 13:36:07 +02:00
parent c534b68665
commit f6bc61997a
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -217,7 +217,7 @@ class NetVMMixin(qubes.events.Emitter):
raise qubes.exc.QubesVMNotRunningError(self) raise qubes.exc.QubesVMNotRunningError(self)
assert self.netvm is not None assert self.netvm is not None
self.libvirt_domain.attachDevice( self.libvirt_domain.detachDevice(
self.app.env.get_template('libvirt/devices/net.xml').render( self.app.env.get_template('libvirt/devices/net.xml').render(
vm=self)) vm=self))
@ -273,23 +273,25 @@ class NetVMMixin(qubes.events.Emitter):
def on_property_pre_set_netvm(self, event, name, new_netvm, old_netvm=None): def on_property_pre_set_netvm(self, event, name, new_netvm, old_netvm=None):
''' Run sanity checks before setting a new NetVM ''' ''' Run sanity checks before setting a new NetVM '''
# pylint: disable=unused-argument # pylint: disable=unused-argument
if new_netvm is None: if new_netvm is not None:
return if not new_netvm.provides_network:
raise qubes.exc.QubesValueError(
'The {!s} qube does not provide network'.format(new_netvm))
if not new_netvm.provides_network: if new_netvm is self \
raise qubes.exc.QubesValueError( or new_netvm in self.app.domains.get_vms_connected_to(self):
'The {!s} qube does not provide network'.format(new_netvm)) raise qubes.exc.QubesValueError(
'Loops in network are unsupported')
if new_netvm is self \ if not self.app.vmm.offline_mode \
or new_netvm in self.app.domains.get_vms_connected_to(self): and self.is_running() and not new_netvm.is_running():
raise qubes.exc.QubesValueError('Loops in network are unsupported') raise qubes.exc.QubesVMNotStartedError(new_netvm,
'Cannot dynamically attach to stopped NetVM: {!r}'.format(
new_netvm))
if not self.app.vmm.offline_mode and self.is_running() \ if old_netvm is not None:
and not new_netvm.is_running(): if self.is_running():
self.detach_network()
raise qubes.exc.QubesVMNotStartedError(new_netvm,
'Cannot dynamically attach to stopped NetVM: {!r}'.format(
new_netvm))
@qubes.events.handler('property-set:netvm') @qubes.events.handler('property-set:netvm')
def on_property_set_netvm(self, event, name, new_netvm, old_netvm=None): def on_property_set_netvm(self, event, name, new_netvm, old_netvm=None):
@ -298,10 +300,6 @@ class NetVMMixin(qubes.events.Emitter):
''' '''
# pylint: disable=unused-argument # pylint: disable=unused-argument
if self.netvm is not None:
if self.is_running():
self.detach_network()
if new_netvm is None: if new_netvm is None:
return return