def _build_excludes(self):
self._validate_allocation_pools()
subnet_net = netaddr.IPNetwork(self._subnet_cidr)
version = subnet_net.version
cidrset = netaddr.IPSet(
netaddr.IPRange(
netaddr.IPAddress(subnet_net.first, version=version),
netaddr.IPAddress(subnet_net.last, version=version)).cidrs())
if isinstance(self._alloc_pools, list):
for p in self._alloc_pools:
start = netaddr.IPAddress(p["start"])
end = netaddr.IPAddress(p["end"])
cidrset -= netaddr.IPSet(netaddr.IPRange(
netaddr.IPAddress(start),
netaddr.IPAddress(end)).cidrs())
elif self._alloc_pools is None:
# Empty list is completely unallocatable, None is fully
# allocatable
cidrset = netaddr.IPSet()
for p in self._policies:
cidrset.add(netaddr.IPNetwork(p))
self._exclude_cidrs = cidrset
评论列表
文章目录