コード例 #1
0
ファイル: test_utils.py プロジェクト: kokasha/layer2_demo
def test_to_ipv6_subnet():
    assert "2001:db8::" == to_ipv6_subnet("2001:db8::")
    assert "2001:0db8:85a3:4242::" == to_ipv6_subnet(
        "2001:0db8:85a3:4242:0000:8a2e:0370:7334"
    )
    assert "2001:0db8:85a3:4242::" == to_ipv6_subnet(
        "2001:0db8:85a3:4242:0:8a2e:0370:7334"
    )
コード例 #2
0
def validate_ip(module, cidr_ip):
    split_addr = cidr_ip.split('/')
    if len(split_addr) == 2:
        # this_ip is a IPv4 or IPv6 CIDR that may or may not have host bits set
        # Get the network bits.
        try:
            ip = to_subnet(split_addr[0], split_addr[1])
        except ValueError:
            ip = to_ipv6_subnet(split_addr[0]) + "/" + split_addr[1]
        if ip != cidr_ip:
            module.warn("One of your CIDR addresses ({0}) has host bits set. To get rid of this warning, "
                        "check the network mask and make sure that only network bits are set: {1}.".format(cidr_ip, ip))
        return ip
    return cidr_ip
コード例 #3
0
def test_to_ipv6_subnet():
    assert '2001:db8::' == to_ipv6_subnet('2001:db8::')
    assert '2001:0db8:85a3:4242::' == to_ipv6_subnet(
        '2001:0db8:85a3:4242:0000:8a2e:0370:7334')
    assert '2001:0db8:85a3:4242::' == to_ipv6_subnet(
        '2001:0db8:85a3:4242:0:8a2e:0370:7334')