'Revert a volume to a snapshot.
The process of reverting to snapshot consists of several steps:
1.   create a snapshot for backup (in case of data loss)
2.1. use driver\'s specific logic to revert volume
2.2. try the generic way to revert volume if driver\'s method is missing
3.   delete the backup snapshot'

def revert_to_snapshot(self, context, volume, snapshot):

    backup_snapshot = None
    try:
        LOG.info('Start    to    perform    revert    to    snapshot    process.')
        backup_snapshot = self._create_backup_snapshot(context, volume)
        self._revert_to_snapshot(context, volume, snapshot)
    except Exception as error:
        with excutils.save_and_reraise_exception():
            self._notify_about_volume_usage(context, volume, 'revert.end')
            self._notify_about_snapshot_usage(context, snapshot, 'revert.end')
            msg = 'Volume    %(v_id)s    revert    to    snapshot    %(s_id)s    failed    with    %(error)s.'
            msg_args = {'v_id': volume.id, 's_id': snapshot.id, 'error': six.text_type(error)}
            v_res = volume.update_single_status_where('error', 'reverting')
            if (not v_res):
                msg_args = {'id': volume.id, 'status': 'error'}
                msg += ('Failed    to    reset    volume    %(id)s    status    to    %(status)s.' % msg_args)
            s_res = snapshot.update_single_status_where(fields.SnapshotStatus.AVAILABLE, fields.SnapshotStatus.RESTORING)
            if (not s_res):
                msg_args = {'id': snapshot.id, 'status': fields.SnapshotStatus.ERROR}
                msg += ('Failed    to    reset    snapshot    %(id)s    status    to    %(status)s.' % msg_args)
            LOG.exception(msg, msg_args)
    v_res = volume.update_single_status_where('available', 'reverting')
    if (not v_res):
        msg_args = {'id': volume.id, 'status': 'available'}
        msg = (_('Revert    finished,    but    failed    to    reset    volume    %(id)s    status    to    %(status)s,    please    manually    reset    it.') % msg_args)
        raise exception.BadResetResourceStatus(message=msg)
    s_res = snapshot.update_single_status_where(fields.SnapshotStatus.AVAILABLE, fields.SnapshotStatus.RESTORING)
    if (not s_res):
        msg_args = {'id': snapshot.id, 'status': fields.SnapshotStatus.AVAILABLE}
        msg = (_('Revert    finished,    but    failed    to    reset    snapshot    %(id)s    status    to    %(status)s,    please    manually    reset    it.') % msg_args)
        raise exception.BadResetResourceStatus(message=msg)
    if backup_snapshot:
        self.delete_snapshot(context, backup_snapshot, handle_quota=False)
    msg = 'Volume    %(v_id)s    reverted    to    snapshot    %(snap_id)s    successfully.'
    msg_args = {'v_id': volume.id, 'snap_id': snapshot.id}
    LOG.info(msg, msg_args)
