def ip_pool_remove(cidrs, version): """ Remove the given CIDRs from the IP address allocation pool. :param cidrs: The pools to remove in CIDR format, e.g. 192.168.0.0/16 :param version: 4 or 6 :return: None """ for cidr in cidrs: try: client.remove_ip_pool(version, IPNetwork(cidr)) except KeyError: print "%s is not a configured pool." % cidr
def ip_pool_remove(cidrs, version): """ Remove the given CIDRs from the IP address allocation pool. :param cidrs: The pools to remove in CIDR format, e.g. 192.168.0.0/16 :param version: 4 or 6 :return: None """ for cidr in cidrs: # Get the existing IP Pool so that we can disable it, try: pool = client.get_ip_pool_config(version, IPNetwork(cidr)) except KeyError: print "%s is not a configured pool." % cidr sys.exit(1) try: # Disable the pool to prevent any further allocation blocks from # being assigned from the pool. Existing allocation blocks will # still exist and may be allocated from until affinity is removed # from the blocks. print "Disabling IP Pool" pool.disabled = True client.set_ip_pool_config(version, pool) # Remove affinity from the allocation blocks for the pool. This # will prevent these blocks from being used for auto-allocations. # We pause before removing the affinities and the pool to allow # any in-progress IP allocations to complete - there is a known # timing window here, which can be closed but at the expense of # additional etcd reads for each affine block allocation - since # deletion of a pool is not common, it is simplest to pause in # between disabling and deleting the pool. print "Removing IPAM configuration for pool" time.sleep(3) client.release_pool_affinities(pool) client.remove_ip_pool(version, pool.cidr) print "Deleted IP Pool" except (KeyError, HostAffinityClaimedError): print_paragraph("Conflicting modifications have been made to the " "IPAM configuration for this pool. Please retry " "the command.") sys.exit(1)