'Creates allocation records for the supplied instance UUID against
the supplied resource providers.
We check to see if resources have already been claimed for this
consumer. If so, we assume that a move operation is underway and the
scheduler is attempting to claim resources against the new (destination
host). In order to prevent compute nodes currently performing move
operations from being scheduled to improperly, we create a "doubled-up"
allocation that consumes resources on *both* the source and the
destination host during the move operation. When the move operation
completes, the destination host (via _allocate_for_instance()) will
end up setting allocations for the instance only on the destination
host thereby freeing up resources on the source host appropriately.
:note: This method will attempt to retry a claim that fails with a
concurrent update up to 3 times
:param consumer_uuid: The instance\'s UUID.
:param alloc_request: The JSON body of the request to make to the
placement\'s PUT /allocations API
:param project_id: The project_id associated with the allocations.
:param user_id: The user_id associated with the allocations.
:param attempt: The attempt at claiming this allocation request (used
in recursive retries)
:returns: True if the allocations were created, False otherwise.'

@safe_connect
def claim_resources(self, consumer_uuid, alloc_request, project_id, user_id, attempt=0):

    ar = copy.deepcopy(alloc_request)
    url = ('/allocations/%s' % consumer_uuid)
    payload = ar
    r = self.get(url)
    if (r.status_code == 200):
        current_allocs = r.json()['allocations']
        if current_allocs:
            payload = _move_operation_alloc_request(current_allocs, ar)
    payload['project_id'] = project_id
    payload['user_id'] = user_id
    r = self.put(url, payload, version='1.10')
    if (r.status_code != 204):
        if ((attempt < 3) and ('concurrently    updated' in r.text)):
            LOG.debug('Another    process    changed    the    resource    providers    involved    in    our    claim    attempt.    Retrying    claim.')
            return self.claim_resources(consumer_uuid, alloc_request, project_id, user_id, attempt=(attempt + 1))
        LOG.warning('Unable    to    submit    allocation    for    instance    %(uuid)s    (%(code)i    %(text)s)', {'uuid': consumer_uuid, 'code': r.status_code, 'text': r.text})
    return (r.status_code == 204)
