Пример #1
0
 def subnetentry(x):
     """
     Generate a subnet declaration block given an IPv6 prefix string
     for inclusion in the RADVD config file.
     """
     if x.find(":") >= 0:
         net = Ipv6Prefix(x)
         return str(net)
     else:
         return ""
Пример #2
0
 def addrstr(x):
     if x.find(":") >= 0:
         net = Ipv6Prefix(x)
     else:
         net = Ipv4Prefix(x)
     if net.max_addr() == net.min_addr():
         return ""
     else:
         if os.uname()[0] == "Linux":
             rtcmd = "ip route add default via"
         else:
             raise Exception("unknown platform")
         return "%s %s" % (rtcmd, net.min_addr())
Пример #3
0
 def routestr(x):
     if x.find(":") >= 0:
         net = Ipv6Prefix(x)
         dst = "3ffe:4::/64"
     else:
         net = Ipv4Prefix(x)
         dst = "10.9.8.0/24"
     if net.max_addr() == net.min_addr():
         return ""
     else:
         if os.uname()[0] == "Linux":
             rtcmd = "#/sbin/ip route add %s via" % dst
         else:
             raise Exception("unknown platform")
         return "%s %s" % (rtcmd, net.min_addr())
Пример #4
0
    def __init__(self, ip4_prefix=None, ip6_prefix=None):
        """
        Creates an IpPrefixes object.

        :param str ip4_prefix: ip4 prefix to use for generation
        :param str ip6_prefix: ip6 prefix to use for generation
        :raises ValueError: when both ip4 and ip6 prefixes have not been provided
        """
        if not ip4_prefix and not ip6_prefix:
            raise ValueError("ip4 or ip6 must be provided")

        self.ip4 = None
        if ip4_prefix:
            self.ip4 = Ipv4Prefix(ip4_prefix)
        self.ip6 = None
        if ip6_prefix:
            self.ip6 = Ipv6Prefix(ip6_prefix)
Пример #5
0
 def addrstr(x):
     if x.find(":") >= 0:
         net = Ipv6Prefix(x)
         fam = "inet6 ::"
     else:
         net = Ipv4Prefix(x)
         fam = "inet 0.0.0.0"
     if net.max_addr() == net.min_addr():
         return ""
     else:
         if os.uname()[0] == "Linux":
             rtcmd = "ip route add default via"
         elif os.uname()[0] == "FreeBSD":
             rtcmd = "route add -%s" % fam
         else:
             raise Exception, "unknown platform"
         return "%s %s" % (rtcmd, net.min_addr())