'Rescue the given instance.'

@check_instance_lock
@check_instance_state(vm_state=[vm_states.ACTIVE, vm_states.STOPPED, vm_states.ERROR])
def rescue(self, context, instance, rescue_password=None, rescue_image_ref=None, clean_shutdown=True):

    bdms = objects.BlockDeviceMappingList.get_by_instance_uuid(context, instance.uuid)
    for bdm in bdms:
        if bdm.volume_id:
            vol = self.volume_api.get(context, bdm.volume_id)
            self.volume_api.check_attached(context, vol)
    if compute_utils.is_volume_backed_instance(context, instance, bdms):
        reason = _('Cannot    rescue    a    volume-backed    instance')
        raise exception.InstanceNotRescuable(instance_id=instance.uuid, reason=reason)
    instance.task_state = task_states.RESCUING
    instance.save(expected_task_state=[None])
    self._record_action_start(context, instance, instance_actions.RESCUE)
    self.compute_rpcapi.rescue_instance(context, instance=instance, rescue_password=rescue_password, rescue_image_ref=rescue_image_ref, clean_shutdown=clean_shutdown)
