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

        network_type = self.get_type()
        with session.begin(subtransactions=True):
            select = (session.query(self.model).
                      filter_by(allocated=False, **filters))

            # Selected segment can be allocated before update by someone else,
            allocs = select.limit(IDPOOL_SELECT_SIZE).all()

            if not allocs:
                # No resource available
                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

            # Segment allocated since select
            LOG.debug("Allocate %(type)s segment from pool "
                      "failed with segment %(segment)s",
                      {"type": network_type,
                       "segment": raw_segment})
            # saving real exception in case we exceeded amount of attempts
            raise db_exc.RetryRequest(
                exc.NoNetworkFoundInMaximumAllowedAttempts())
Reset device paths to allow unmounting.
dataset/ETHPy150Open openstack/neutron/neutron/plugins/ml2/drivers/helpers.py/SegmentTypeDriver.allocate_partially_specified_segment--crossover with--dataset/ETHPy150Open BU-NU-CLOUD-SP16/Trusted-Platform-Module-nova/nova/virt/disk/mount/api.py/Mount.reset_dev