'Update database fields related to status of a snapshot.
Intended for creation of snapshots, so snapshot state
must start as \'creating\' and be changed to \'available\',
\'creating\', or \'error\'.'

@wsgi.action('os-update_snapshot_status')
def _update_snapshot_status(self, req, id, body):

    context = req.environ['cinder.context']
    authorize(context, 'update_snapshot_status')
    LOG.debug('body:    %s', body)
    try:
        status = body['os-update_snapshot_status']['status']
    except KeyError:
        msg = _("'status'    must    be    specified.")
        raise webob.exc.HTTPBadRequest(explanation=msg)
    status_map = {fields.SnapshotStatus.CREATING: [fields.SnapshotStatus.CREATING, fields.SnapshotStatus.AVAILABLE, fields.SnapshotStatus.ERROR], fields.SnapshotStatus.DELETING: [fields.SnapshotStatus.DELETING, fields.SnapshotStatus.ERROR_DELETING]}
    current_snapshot = objects.Snapshot.get_by_id(context, id)
    if (current_snapshot.status not in status_map):
        msg = (_('Snapshot    status    %(cur)s    not    allowed    for    update_snapshot_status') % {'cur': current_snapshot.status})
        raise webob.exc.HTTPBadRequest(explanation=msg)
    if (status not in status_map[current_snapshot.status]):
        msg = (_('Provided    snapshot    status    %(provided)s    not    allowed    for    snapshot    with    status    %(current)s.') % {'provided': status, 'current': current_snapshot.status})
        raise webob.exc.HTTPBadRequest(explanation=msg)
    update_dict = {'id': id, 'status': status}
    progress = body['os-update_snapshot_status'].get('progress', None)
    if progress:
        msg = _('progress    must    be    an    integer    percentage')
        try:
            integer = int(progress[:(-1)])
        except ValueError:
            raise webob.exc.HTTPBadRequest(explanation=msg)
        if ((integer < 0) or (integer > 100) or (progress[(-1)] != '%')):
            raise webob.exc.HTTPBadRequest(explanation=msg)
        update_dict.update({'progress': progress})
    LOG.info('Updating    snapshot    %(id)s    with    info    %(dict)s', {'id': id, 'dict': update_dict})
    current_snapshot.update(update_dict)
    current_snapshot.save()
    return webob.Response(status_int=http_client.ACCEPTED)
