def get_public_network_ip(ips, public_subnet): """ Given a public subnet, chose the one IP from the remote host that exists within the subnet range. """ for ip in ips: if net.ip_in_subnet(ip, public_subnet): return ip msg = "IPs (%s) are not valid for any of subnet specified %s" % (str(ips), str(public_subnet)) raise RuntimeError(msg)
def ip_in_one_subnet(ips, subnet): """ ensure an ip exists in at least one subnet """ for ip in ips: if net.ip_in_subnet(ip, subnet): return True return False
def test_correct_for_10_0_0_255(self, ip): assert net.ip_in_subnet(ip, "10.0.0.0/16")
def test_false_for_24_subnets(self, ip): assert net.ip_in_subnet(ip, "10.9.1.0/24") is False
def test_true_for_16_subnets(self, ip): assert net.ip_in_subnet(ip, "10.9.1.0/16") is True
def test_false_for_172_addresses(self, ip): assert net.ip_in_subnet(ip, "172.3.0.0/16") is False
def test_false_for_255_addresses(self, ip): assert net.ip_in_subnet(ip, "10.9.1.0/16") is False
def test_false_for_10_0_0_255(self, ip): assert net.ip_in_subnet(ip, "10.2.0.0/24") is False