diff options
| author | Daniel P. Berrange <berrange@redhat.com> | 2013-02-12 13:37:42 +0000 |
|---|---|---|
| committer | Daniel P. Berrange <berrange@redhat.com> | 2013-02-19 18:04:57 +0000 |
| commit | 9c9aefc62ae6422d5b7e83f4b4a0aed86be54cff (patch) | |
| tree | 1d28bed7421002b66a78980cd75f05c6949da474 | |
| parent | d63f7c1b47509f31c1e5aa8d27392d7f83e6dad2 (diff) | |
Handle lifecycle events in the compute manager
Update the compute manager to register an event handler
with the compute drivers. The initial handler will process
lifecycle event notifications, to allow prompt synchronization
of DB & hypervisor power states. This means that if a guest
admin does 'shutdown -h now' the libvirt driver in Nova will
immediately notice that and mark the guest as SHUTOFF rather
then leaving it RUNNING until the periodic task runs sometime
in the next 10 minutes
Blueprint: compute-driver-events
Change-Id: I39a6d450a6d6384b8be58aceea98e4395185cc38
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
| -rwxr-xr-x | nova/compute/manager.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 9d4fc0a46..84c56f899 100755 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -69,6 +69,7 @@ from nova import quota from nova.scheduler import rpcapi as scheduler_rpcapi from nova import utils from nova.virt import driver +from nova.virt import event as virtevent from nova.virt import storage_users from nova.virt import virtapi from nova import volume @@ -499,6 +500,40 @@ class ComputeManager(manager.SchedulerDependentManager): LOG.warning(_('Hypervisor driver does not support ' 'firewall rules'), instance=instance) + def handle_lifecycle_event(self, event): + LOG.error(_("Lifecycle event %(state)d on VM %(uuid)s") % + {'state': event.get_transition(), + 'uuid': event.get_instance_uuid()}) + context = nova.context.get_admin_context() + instance = self.conductor_api.instance_get_by_uuid( + context, event.get_instance_uuid()) + vm_power_state = None + if event.get_transition() == virtevent.EVENT_LIFECYCLE_STOPPED: + vm_power_state = power_state.SHUTDOWN + elif event.get_transition() == virtevent.EVENT_LIFECYCLE_STARTED: + vm_power_state = power_state.RUNNING + elif event.get_transition() == virtevent.EVENT_LIFECYCLE_PAUSED: + vm_power_state = power_state.PAUSED + elif event.get_transition() == virtevent.EVENT_LIFECYCLE_RESUMED: + vm_power_state = power_state.RUNNING + else: + LOG.warning(_("Unexpected power state %d") % + event.get_transition()) + + if vm_power_state is not None: + self._sync_instance_power_state(context, + instance, + vm_power_state) + + def handle_events(self, event): + if isinstance(event, virtevent.LifecycleEvent): + self.handle_lifecycle_event(event) + else: + LOG.debug(_("Ignoring event %s") % event) + + def init_virt_events(self): + self.driver.register_event_listener(self.handle_events) + def init_host(self): """Initialization for a standalone compute service.""" self.driver.init_host(host=self.host) @@ -509,6 +544,8 @@ class ComputeManager(manager.SchedulerDependentManager): if CONF.defer_iptables_apply: self.driver.filter_defer_apply_on() + self.init_virt_events() + try: # checking that instance was not already evacuated to other host self._destroy_evacuated_instances(context) |
