'Validate that the index supplied maps to a policy.
:returns: policy index from request, or None if not present
:raises HTTPBadRequest: if the supplied index is bogus'

def get_and_validate_policy_index(self, req):

    policy_index = req.headers.get('X-Backend-Storage-Policy-Index', None)
    if (policy_index is None):
        return None
    try:
        policy_index = int(policy_index)
    except ValueError:
        raise HTTPBadRequest(request=req, content_type='text/plain', body=('Invalid    X-Storage-Policy-Index    %r' % policy_index))
    policy = POLICIES.get_by_index(policy_index)
    if (policy is None):
        raise HTTPBadRequest(request=req, content_type='text/plain', body=('Invalid    X-Storage-Policy-Index    %r' % policy_index))
    return int(policy)
