diff --git a/nova/compute/api.py b/nova/compute/api.py index bfb5c61..c8888c4 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -159,6 +159,20 @@ def check_policy(context, action, target, scope='compute'): nova.policy.enforce(context, _action, target) +def restore_instance_state_on_failure(function): + """Decorator to restore instance original state on failure.""" + + @functools.wraps(function) + def inner(self, context, instance, *args, **kwargs): + try: + orig_state = instance['task_state'] + return function(self, context, instance, *args, **kwargs) + except Exception, e: + with excutils.save_and_reraise_exception(): + self.update(context, instance, task_state=orig_state) + return inner + + class API(base.Base): """API for interacting with the compute manager.""" @@ -2173,6 +2187,7 @@ class API(base.Base): return False @check_instance_state(vm_state=[vm_states.ACTIVE]) + @restore_instance_state_on_failure def live_migrate(self, context, instance, block_migration, disk_over_commit, host_name): """Migrate a server lively to a new host."""