'Snapshot an instance on this host.
:param context: security context
:param image_id: glance.db.sqlalchemy.models.Image.Id
:param instance: a nova.objects.instance.Instance object'

@wrap_exception()
@reverts_task_state
@wrap_instance_fault
@delete_image_on_error
def snapshot_instance(self, context, image_id, instance):

    try:
        instance.task_state = task_states.IMAGE_SNAPSHOT
        instance.save(expected_task_state=task_states.IMAGE_SNAPSHOT_PENDING)
    except exception.InstanceNotFound:
        LOG.debug('Instance    not    found,    could    not    set    state    %s    for    instance.', task_states.IMAGE_SNAPSHOT, instance=instance)
        return
    except exception.UnexpectedDeletingTaskStateError:
        LOG.debug('Instance    being    deleted,    snapshot    cannot    continue', instance=instance)
        return
    self._snapshot_instance(context, image_id, instance, task_states.IMAGE_SNAPSHOT)
