From 250230b32364b1e36ae6d62ec4bb8c3285c59401 Mon Sep 17 00:00:00 2001 From: Andrew Laski Date: Tue, 15 Jan 2013 17:24:49 -0500 Subject: Record instance actions and events Record when an action is initiated on an instance, and the underlying events related to completing that action. Actions will typically occur at the API level and should match what a user intended to do with an instance. Events will typically track what happens behind the scenes and may include things that would be unclear for a user if exposed, but should be beneficial to an admin/deployer. Adds a new wrapper to the compute manager. The wrapper will record when an event begins and finishes from the point of view of the compute manager. It will also record errors if they occur. Blueprint instance-actions Change-Id: I801f3e796d091e146413f84c2ccfab95ad2e1af4 --- nova/scheduler/manager.py | 77 ++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 35 deletions(-) (limited to 'nova/scheduler/manager.py') diff --git a/nova/scheduler/manager.py b/nova/scheduler/manager.py index e6bf1a293..a129a1b6d 100644 --- a/nova/scheduler/manager.py +++ b/nova/scheduler/manager.py @@ -104,22 +104,26 @@ class SchedulerManager(manager.Manager): """Tries to call schedule_run_instance on the driver. Sets instance vm_state to ERROR on exceptions """ - try: - return self.driver.schedule_run_instance(context, - request_spec, admin_password, injected_files, - requested_networks, is_first_time, filter_properties) - except exception.NoValidHost as ex: - # don't re-raise - self._set_vm_state_and_notify('run_instance', - {'vm_state': vm_states.ERROR, - 'task_state': None}, - context, ex, request_spec) - except Exception as ex: - with excutils.save_and_reraise_exception(): + instance_uuids = request_spec['instance_uuids'] + with compute_utils.EventReporter(context, conductor_api.LocalAPI(), + 'schedule', *instance_uuids): + try: + return self.driver.schedule_run_instance(context, + request_spec, admin_password, injected_files, + requested_networks, is_first_time, filter_properties) + + except exception.NoValidHost as ex: + # don't re-raise self._set_vm_state_and_notify('run_instance', - {'vm_state': vm_states.ERROR, + {'vm_state': vm_states.ERROR, 'task_state': None}, - context, ex, request_spec) + context, ex, request_spec) + except Exception as ex: + with excutils.save_and_reraise_exception(): + self._set_vm_state_and_notify('run_instance', + {'vm_state': vm_states.ERROR, + 'task_state': None}, + context, ex, request_spec) def prep_resize(self, context, image, request_spec, filter_properties, instance, instance_type, reservations): @@ -127,32 +131,35 @@ class SchedulerManager(manager.Manager): Sets instance vm_state to ACTIVE on NoHostFound Sets vm_state to ERROR on other exceptions """ - try: - kwargs = { - 'context': context, - 'image': image, - 'request_spec': request_spec, - 'filter_properties': filter_properties, - 'instance': instance, - 'instance_type': instance_type, - 'reservations': reservations, - } - return self.driver.schedule_prep_resize(**kwargs) - except exception.NoValidHost as ex: - self._set_vm_state_and_notify('prep_resize', - {'vm_state': vm_states.ACTIVE, - 'task_state': None}, - context, ex, request_spec) - if reservations: - QUOTAS.rollback(context, reservations) - except Exception as ex: - with excutils.save_and_reraise_exception(): + instance_uuid = instance['uuid'] + with compute_utils.EventReporter(context, conductor_api.LocalAPI(), + 'schedule', instance_uuid): + try: + kwargs = { + 'context': context, + 'image': image, + 'request_spec': request_spec, + 'filter_properties': filter_properties, + 'instance': instance, + 'instance_type': instance_type, + 'reservations': reservations, + } + return self.driver.schedule_prep_resize(**kwargs) + except exception.NoValidHost as ex: self._set_vm_state_and_notify('prep_resize', - {'vm_state': vm_states.ERROR, + {'vm_state': vm_states.ACTIVE, 'task_state': None}, context, ex, request_spec) if reservations: QUOTAS.rollback(context, reservations) + except Exception as ex: + with excutils.save_and_reraise_exception(): + self._set_vm_state_and_notify('prep_resize', + {'vm_state': vm_states.ERROR, + 'task_state': None}, + context, ex, request_spec) + if reservations: + QUOTAS.rollback(context, reservations) def _set_vm_state_and_notify(self, method, updates, context, ex, request_spec): -- cgit