From ff753cd608973f5d72a80aef0f9fb8a646fccc3f Mon Sep 17 00:00:00 2001 From: David Subiros Date: Wed, 16 Nov 2011 17:31:29 +0000 Subject: Vm state management and error states this implements the blueprint nova-vm-state-management It implements the following functionalities: - Filter compute api calls according to state of the VM (defined in compute/state_checker). - Sets error state if the scheduler cannot allocate the VM in any host - Handles the create/delete concurrency in the compute manager Change-Id: Ie6d016b7d4781f70bb5967f204fa88a6412bd727 --- nova/scheduler/manager.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'nova/scheduler') diff --git a/nova/scheduler/manager.py b/nova/scheduler/manager.py index 5aadc6e82..38dda9931 100644 --- a/nova/scheduler/manager.py +++ b/nova/scheduler/manager.py @@ -25,12 +25,13 @@ import functools from nova.compute import vm_states from nova import db +from nova import exception from nova import flags from nova import log as logging from nova import manager from nova import rpc -from nova import utils from nova.scheduler import zone_manager +from nova import utils LOG = logging.getLogger('nova.scheduler.manager') FLAGS = flags.FLAGS @@ -101,17 +102,24 @@ class SchedulerManager(manager.Manager): # Scheduler methods are responsible for casting. try: return real_meth(*args, **kwargs) - except Exception as e: - # If this affects a particular instance, move that - # instance to the ERROR state - if 'instance_id' in kwargs: - instance_id = kwargs['instance_id'] - LOG.warning(_("Failed to %(driver_method)s: %(e)s. " - "Putting instance %(instance_id)s into " + except exception.NoValidHost as ex: + self._set_instance_error(method, context, ex, *args, **kwargs) + except Exception as ex: + with utils.save_and_reraise_exception(): + self._set_instance_error(method, context, ex, *args, **kwargs) + + # NOTE (David Subiros) : If the exception is raised ruing run_instance + # method, the DB record probably does not exist yet. + def _set_instance_error(self, method, context, ex, *args, **kwargs): + """Sets VM to Error state""" + LOG.warning(_("Failed to schedule_%(method)s: %(ex)s") % locals()) + if method == "start_instance" or method == "run_instance": + instance_id = kwargs['instance_id'] + if instance_id: + LOG.warning(_("Setting instance %(instance_id)s to " "ERROR state.") % locals()) - db.instance_update(context, kwargs['instance_id'], - dict(vm_state=vm_states.ERROR)) - raise + db.instance_update(context, instance_id, + {'vm_state': vm_states.ERROR}) # NOTE (masumotok) : This method should be moved to nova.api.ec2.admin. # Based on bexar design summit discussion, -- cgit