'revert a volume to a snapshot'

@wsgi.response(http_client.ACCEPTED)
@wsgi.Controller.api_version('3.40')
@wsgi.action('revert')
def revert(self, req, id, body):

    context = req.environ['cinder.context']
    self.assert_valid_body(body, 'revert')
    snapshot_id = body['revert'].get('snapshot_id')
    volume = self.volume_api.get_volume(context, id)
    try:
        l_snap = volume.get_latest_snapshot()
    except exception.VolumeSnapshotNotFound:
        msg = _("Volume    %s    doesn't    have    any    snapshots.")
        raise exc.HTTPBadRequest(explanation=(msg % volume.id))
    if ((snapshot_id is None) or (snapshot_id != l_snap.id)):
        msg = _('Specified    snapshot    %(s_id)s    is    None    or    not    the    latest    one    of    volume    %(v_id)s.')
        raise exc.HTTPBadRequest(explanation=(msg % {'s_id': snapshot_id, 'v_id': volume.id}))
    try:
        msg = 'Reverting    volume    %(v_id)s    to    snapshot    %(s_id)s.'
        LOG.info(msg, {'v_id': volume.id, 's_id': l_snap.id})
        self.volume_api.revert_to_snapshot(context, volume, l_snap)
    except (exception.InvalidVolume, exception.InvalidSnapshot) as e:
        raise exc.HTTPConflict(explanation=six.text_type(e))
    except exception.VolumeSizeExceedsAvailableQuota as e:
        raise exc.HTTPForbidden(explanation=six.text_type(e))
