'Write a set of allocations.
We must check that there is capacity for each allocation.
If there is not we roll back the entire set.
:raises `exception.ResourceClassNotFound` if any resource class in any
allocation in allocs cannot be found in either the standard
classes or the DB.
:raises `exception.InvalidAllocationCapacityExceeded` if any inventory
would be exhausted by the allocation.
:raises `InvalidAllocationConstraintsViolated` if any of the
`step_size`, `min_unit` or `max_unit` constraints in an
inventory will be violated by any one of the allocations.'

@oslo_db_api.wrap_db_retry(max_retries=5, retry_on_deadlock=True)
@db_api.api_context_manager.writer
def _set_allocations(self, context, allocs):

    _ensure_rc_cache(context)
    conn = context.session.connection()
    for alloc in allocs:
        if ('id' in alloc):
            raise exception.ObjectActionError(action='create', reason='already    created')
    with conn.begin():
        consumer_id = allocs[0].consumer_id
        _delete_current_allocs(conn, consumer_id)
        before_gens = _check_capacity_exceeded(conn, allocs)
        self._ensure_consumer_project_user(conn, consumer_id)
        for alloc in allocs:
            rp = alloc.resource_provider
            rc_id = _RC_CACHE.id_from_string(alloc.resource_class)
            ins_stmt = _ALLOC_TBL.insert().values(resource_provider_id=rp.id, resource_class_id=rc_id, consumer_id=alloc.consumer_id, used=alloc.used)
            result = conn.execute(ins_stmt)
            alloc.id = result.lastrowid
        for rp in before_gens:
            rp.generation = _increment_provider_generation(conn, rp)
