def generate_pools(cidr, gateway_ip):
 net = netaddr.IPNetwork(cidr)
 ip_version = net.version
 first = netaddr.IPAddress(net.first, ip_version)
 last = netaddr.IPAddress(net.last, ip_version)
 if (first == last):
  return [netaddr.IPRange(first, last)]
 first_ip = (first + 1)
 last_ip = (last - (ip_version == 4))
 if (first_ip >= last_ip):
  return []
 ipset = netaddr.IPSet(netaddr.IPRange(first_ip, last_ip))
 if gateway_ip:
  ipset.remove(netaddr.IPAddress(gateway_ip, ip_version))
 return list(ipset.iter_ipranges())

def generate_pools ( cidr , gateway_ip ) : net = netaddr . IPNetwork ( cidr ) ip_version = net . version first = netaddr . IPAddress ( net . first , ip_version ) last = netaddr . IPAddress ( net . last , ip_version ) if ( first == last ) : return [ netaddr . IPRange ( first , last ) ] first_ip = ( first + 1 ) last_ip = ( last - ( ip_version == 4 ) ) if ( first_ip >= last_ip ) : return [ ] ipset = netaddr . IPSet ( netaddr . IPRange ( first_ip , last_ip ) ) if gateway_ip : ipset . remove ( netaddr . IPAddress ( gateway_ip , ip_version ) ) return list ( ipset . iter_ipranges ( ) )
create ip allocation pools for a specified subnet the neutron api defines a subnets allocation pools as a list of iprange objects for defining the pool range .