def _try_generate_ip(self, session):
        ip_range = self.subnet_manager.get_first_range(session)
        if not ip_range:
            LOG.debug("All IPs from subnet %(subnet_id)s allocated",
                      {'subnet_id': self.subnet_manager.neutron_id})
            raise ipam_exc.IpAddressGenerationFailure(
                subnet_id=self.subnet_manager.neutron_id)
        # A suitable range was found. Return IP address.
        ip_address = ip_range['first_ip']
        LOG.debug("Allocated IP - %(ip_address)s from range "
                  "[%(first_ip)s; %(last_ip)s]",
                  {'ip_address': ip_address,
                   'first_ip': ip_address,
                   'last_ip': ip_range['last_ip']})
        return ip_address, ip_range['allocation_pool_id']
Generate an IP address from availability ranges.
dataset/ETHPy150Open openstack/neutron/neutron/ipam/drivers/neutrondb_ipam/driver.py/NeutronDbSubnet._try_generate_ip