'Helper method to convert a policy name (from a request from a client)
to a policy index (for a request to a backend).
:param req: incoming request'

def _convert_policy_to_index(self, req):

    policy_name = req.headers.get('X-Storage-Policy')
    if (not policy_name):
        return
    policy = POLICIES.get_by_name(policy_name)
    if (not policy):
        raise HTTPBadRequest(request=req, content_type='text/plain', body=("Invalid    %s    '%s'" % ('X-Storage-Policy', policy_name)))
    if policy.is_deprecated:
        body = ('Storage    Policy    %r    is    deprecated' % policy.name)
        raise HTTPBadRequest(request=req, body=body)
    return int(policy)
