def _allocate_specific_ip(self, session, ip_address,
                              allocation_pool_id=None,
                              auto_generated=False):
        # Return immediately for EUI-64 addresses. For this
        # class of subnets availability ranges do not apply
        if ipv6_utils.is_eui64_address(ip_address):
            return

        LOG.debug("Removing %(ip_address)s from availability ranges for "
                  "subnet id:%(subnet_id)s",
                  {'ip_address': ip_address,
                   'subnet_id': self.subnet_manager.neutron_id})
        # Netaddr's IPRange and IPSet objects work very well even with very
        # large subnets, including IPv6 ones.
        final_ranges = []
        ip_in_pools = False
        if allocation_pool_id:
            av_ranges = self.subnet_manager.list_ranges_by_allocation_pool(
                session, allocation_pool_id)
        else:
            av_ranges = self.subnet_manager.list_ranges_by_subnet_id(session)
        for db_range in av_ranges:
            initial_ip_set = netaddr.IPSet(netaddr.IPRange(
                db_range['first_ip'], db_range['last_ip']))
            final_ip_set = initial_ip_set - netaddr.IPSet([ip_address])
            if not final_ip_set:
                ip_in_pools = True
                # Range exhausted - bye bye
                if not self.subnet_manager.delete_range(session, db_range):
                    raise db_exc.RetryRequest(ipam_exc.IPAllocationFailed())
                continue
            if initial_ip_set == final_ip_set:
                # IP address does not fall within the current range, move
                # to the next one
                final_ranges.append(db_range)
                continue
            ip_in_pools = True
            for new_range in final_ip_set.iter_ipranges():
                # store new range in database
                # use netaddr.IPAddress format() method which is equivalent
                # to str(...) but also enables us to use different
                # representation formats (if needed) for IPv6.
                first_ip = netaddr.IPAddress(new_range.first)
                last_ip = netaddr.IPAddress(new_range.last)
                if (db_range['first_ip'] == first_ip.format() or
                        db_range['last_ip'] == last_ip.format()):
                    rows = self.subnet_manager.update_range(
                        session, db_range, first_ip=first_ip, last_ip=last_ip)
                    if not rows:
                        raise db_exc.RetryRequest(
                            ipam_exc.IPAllocationFailed())
                    LOG.debug("Adjusted availability range for pool %s",
                              db_range['allocation_pool_id'])
                    final_ranges.append(db_range)
                else:
                    new_ip_range = self.subnet_manager.create_range(
                        session,
                        db_range['allocation_pool_id'],
                        first_ip.format(),
                        last_ip.format())
                    LOG.debug("Created availability range for pool %s",
                              new_ip_range['allocation_pool_id'])
                    final_ranges.append(new_ip_range)

        # If ip is autogenerated it should be present in allocation pools,
        # so retry if it is not there
        if auto_generated and not ip_in_pools:
            raise db_exc.RetryRequest(ipam_exc.IPAllocationFailed())
        # Most callers might ignore this return value, which is however
        # useful for testing purposes
        LOG.debug("Availability ranges for subnet id %(subnet_id)s "
                  "modified: %(new_ranges)s",
                  {'subnet_id': self.subnet_manager.neutron_id,
                   'new_ranges': ", ".join(["[%s; %s]" %
                                            (r['first_ip'], r['last_ip']) for
                                            r in final_ranges])})
        return final_ranges
Django doesn't particularly understand REST.
dataset/ETHPy150Open openstack/neutron/neutron/ipam/drivers/neutrondb_ipam/driver.py/NeutronDbSubnet._allocate_specific_ip--crossover with--dataset/ETHPy150Open ionyse/ionyweb/ionyweb/utils.py/coerce_delete_post