From d766b8e1106517d7281bdb4900ed9b94ed082014 Mon Sep 17 00:00:00 2001 From: Wojtek Porczyk Date: Mon, 14 Mar 2016 22:16:52 +0100 Subject: [PATCH] qubes: Fix "unify event names" --- qubes/__init__.py | 5 +++-- qubes/ext/gui.py | 6 +++--- qubes/ext/r3compatibility.py | 6 +++--- qubes/vm/appvm.py | 2 +- qubes/vm/mix/net.py | 21 ++++++++++----------- qubes/vm/qubesvm.py | 6 +++--- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/qubes/__init__.py b/qubes/__init__.py index 1742de02..658bb46a 100644 --- a/qubes/__init__.py +++ b/qubes/__init__.py @@ -473,6 +473,7 @@ class VMCollection(object): def __delitem__(self, key): vm = self[key] + self.app.fire_event_pre('domain-pre-delete', vm) del self._dict[vm.qid] self.app.fire_event('domain-delete', vm) @@ -1449,7 +1450,7 @@ class Qubes(PropertyHolder): raise KeyError(label) - @qubes.events.handler('domain-pre-deleted') + @qubes.events.handler('domain-pre-delete') def on_domain_pre_deleted(self, event, vm): # pylint: disable=unused-argument if isinstance(vm, qubes.vm.templatevm.TemplateVM): @@ -1461,7 +1462,7 @@ class Qubes(PropertyHolder): vm.name for name in sorted(appvms)))) - @qubes.events.handler('domain-deleted') + @qubes.events.handler('domain-delete') def on_domain_deleted(self, event, vm): # pylint: disable=unused-argument for propname in ( diff --git a/qubes/ext/gui.py b/qubes/ext/gui.py index 2d0b044e..14aa223c 100644 --- a/qubes/ext/gui.py +++ b/qubes/ext/gui.py @@ -31,8 +31,8 @@ import qubes.config import qubes.ext class GUI(qubes.ext.Extension): - @qubes.ext.handler('domain-start', 'domain-cmd-pre-start') - def start_guid(self, vm, start_guid, preparing_dvm=False, + @qubes.ext.handler('domain-start', 'domain-cmd-pre-run') + def start_guid(self, vm, event, preparing_dvm=False, start_guid=True, extra_guid_args=None, **kwargs): '''Launch gui daemon. @@ -78,7 +78,7 @@ class GUI(qubes.ext.Extension): @qubes.ext.handler('monitor-layout-change') - def on_monitor_layout_change(self, vm, monitor_layout): + def on_monitor_layout_change(self, vm, event, monitor_layout): # pylint: disable=no-self-use if vm.features.check_with_template('no-monitor-layout', False) \ or not vm.is_running(): diff --git a/qubes/ext/r3compatibility.py b/qubes/ext/r3compatibility.py index c5435745..ca03e7fa 100644 --- a/qubes/ext/r3compatibility.py +++ b/qubes/ext/r3compatibility.py @@ -46,8 +46,8 @@ class R3Compatibility(qubes.ext.Extension): } # noinspection PyUnusedLocal - @qubes.ext.handler('qdb-created') - def on_qdb_created(self, vm, event): + @qubes.ext.handler('domain-qdb-create') + def on_domain_qdb_create(self, vm, event): """ :param vm: VM on which QubesDB entries were just created :type vm: qubes.vm.qubesvm.QubesVM @@ -118,7 +118,7 @@ class R3Compatibility(qubes.ext.Extension): self.write_services(vm) # FIXME use event after creating Xen domain object, but before "resume" - @qubes.ext.handler('domain-started') + @qubes.ext.handler('domain-start') def on_domain_started(self, vm, event, **kwargs): if vm.netvm: self.write_iptables_qubesdb_entry(vm.netvm) diff --git a/qubes/vm/appvm.py b/qubes/vm/appvm.py index c9634fb5..aa2e3966 100644 --- a/qubes/vm/appvm.py +++ b/qubes/vm/appvm.py @@ -15,7 +15,7 @@ class AppVM(qubes.vm.qubesvm.QubesVM): def __init__(self, *args, **kwargs): super(AppVM, self).__init__(*args, **kwargs) - @qubes.events.handler('domain-loaded') + @qubes.events.handler('domain-load') def on_domain_loaded(self, event): # pylint: disable=unused-argument # Some additional checks for template based VM diff --git a/qubes/vm/mix/net.py b/qubes/vm/mix/net.py index 7557358c..a05994f4 100644 --- a/qubes/vm/mix/net.py +++ b/qubes/vm/mix/net.py @@ -138,13 +138,17 @@ class NetVMMixin(object): super(NetVMMixin, self).__init__(*args, **kwargs) - @qubes.events.handler('domain-started') - def start_net(self): - '''Connect this domain to its downstream domains. + @qubes.events.handler('domain-start') + def on_domain_started(self, event, **kwargs): + '''Connect this domain to its downstream domains. Also reload firewall + in its netvm. This is needed when starting netvm *after* its connected domains. ''' + if self.netvm: + self.netvm.reload_firewall_for_vm(self) + for vm in self.connected_vms: if not vm.is_running(): continue @@ -165,7 +169,7 @@ class NetVMMixin(object): vm.log.warning('Cannot attach network', exc_info=1) - @qubes.events.handler('pre-domain-shutdown') + @qubes.events.handler('domain-pre-shutdown') def shutdown_net(self, force=False): connected_vms = [vm for vm in self.connected_vms if vm.is_running()] if connected_vms and not force: @@ -296,17 +300,12 @@ class NetVMMixin(object): # FIXME handle in the above event? new_netvm.reload_firewall_for_vm(self) - @qubes.events.handler('qdb-created') - def on_qdb_created(self, event): + @qubes.events.handler('domain-qdb-create') + def on_domain_qdb_create(self, event): # TODO: fill firewall QubesDB entries (QubesOS/qubes-issues#1815) pass # FIXME use event after creating Xen domain object, but before "resume" - @qubes.events.handler('domain-started') - def on_domain_started(self, event, **kwargs): - if self.netvm: - self.netvm.reload_firewall_for_vm(self) - @qubes.events.handler('firewall-changed') def on_firewall_changed(self, event): if self.is_running() and self.netvm: diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index e227166c..a38fc5bb 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -477,7 +477,7 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): # event handlers # - @qubes.events.handler('domain-init', 'domain-loaded') + @qubes.events.handler('domain-init', 'domain-load') def on_domain_init_loaded(self, event): # pylint: disable=unused-argument if not hasattr(self, 'uuid'): @@ -557,7 +557,7 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): 'Failed to set autostart for VM via systemctl') - @qubes.events.handler('device-pre-attached:pci') + @qubes.events.handler('device-pre-attach:pci') def on_device_pre_attached_pci(self, event, pci): # pylint: disable=unused-argument if not os.path.exists('/sys/bus/pci/devices/0000:{}'.format(pci)): @@ -577,7 +577,7 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): ' changes will be seen after VM restart.'.format(pci), e) - @qubes.events.handler('device-pre-detached:pci') + @qubes.events.handler('device-pre-detach:pci') def on_device_pre_detached_pci(self, event, pci): # pylint: disable=unused-argument if not self.is_running():