vm/mix/net: create vm.connected_vms dynamically

It is much less error-prone way. Previous approach didn't worked because
VMs weren't added here at 'domain-init'/'domain-loaded' event. And even
after adding such handlers it wasn't working because of
QubesOS/qubes-issues#1816.

It may be a little slower, but since it isn't used so often
(starting/stopping VM and reloading firewall), shouldn't be a problem.
This commit is contained in:
Marek Marczykowski-Górecki 2016-03-07 01:10:39 +01:00 committed by Wojtek Porczyk
parent 3e3213e7c7
commit c9cad71d03

View File

@ -27,7 +27,6 @@
import os
import shutil
import time
import weakref
import libvirt
import lxml.etree
@ -112,6 +111,11 @@ class NetVMMixin(object):
return None
return "vif{0}.+".format(self.xid)
@property
def connected_vms(self):
for vm in self.app.domains:
if vm.netvm is self:
yield vm
#
# used in both
@ -132,7 +136,6 @@ class NetVMMixin(object):
def __init__(self, *args, **kwargs):
super(NetVMMixin, self).__init__(*args, **kwargs)
self.connected_vms = weakref.WeakSet()
@qubes.events.handler('domain-started')
@ -270,7 +273,6 @@ class NetVMMixin(object):
new_netvm))
if self.netvm is not None:
self.netvm.connected_vms.remove(self)
if self.is_running():
self.detach_network()
@ -278,9 +280,6 @@ class NetVMMixin(object):
# if hasattr(self.netvm, 'post_vm_net_detach'):
# self.netvm.post_vm_net_detach(self)
if new_netvm is not None:
new_netvm.connected_vms.add(self)
if new_netvm is None:
return