'Allocate model segment from pool partially specified by filters.
Return allocated db object or None.'

def allocate_partially_specified_segment(self, context, **filters):

    network_type = self.get_type()
    (session, ctx_manager) = self._get_session(context)
    with ctx_manager:
        select = session.query(self.model).filter_by(allocated=False, **filters)
        allocs = select.limit(IDPOOL_SELECT_SIZE).all()
        if (not allocs):
            return
        alloc = random.choice(allocs)
        raw_segment = dict(((k, alloc[k]) for k in self.primary_keys))
        LOG.debug('%(type)s    segment    allocate    from    pool    started    with    %(segment)s    ', {'type': network_type, 'segment': raw_segment})
        count = session.query(self.model).filter_by(allocated=False, **raw_segment).update({'allocated': True})
        if count:
            LOG.debug('%(type)s    segment    allocate    from    pool    success    with    %(segment)s    ', {'type': network_type, 'segment': raw_segment})
            return alloc
        LOG.debug('Allocate    %(type)s    segment    from    pool    failed    with    segment    %(segment)s', {'type': network_type, 'segment': raw_segment})
        raise db_exc.RetryRequest(exc.NoNetworkFoundInMaximumAllowedAttempts())
