Ejemplo n.º 1
0
    def __reverse_zones(self):
        """
        Returns a map of zones and the records that belong
        in them
        """
        zones = {}
        reverse_zones = self.settings.manage_reverse_zones
        if type(reverse_zones) != type([]):
            # gracefully handle when user inputs only a single zone
            # as a string instead of a list with only a single item
            reverse_zones = [reverse_zones]

        for zone in reverse_zones:
            zones[zone] = {}

        for sys in self.systems:
            for (name, interface) in sys.interfaces.iteritems():
                host = interface["dns_name"]
                ip = interface["ip_address"]
                if not sys.is_management_supported(cidr_ok=False):
                    continue
                if not host or not ip:
                    # gotsta have some dns_name and ip or else!
                    continue

                # match the longest zone!
                # e.g. if you have an ip 1.2.3.4
                # if manage_reverse_zones has:
                # - 1.2
                # - 1.2.3
                # then 1.2.3.4 should go in 1.2.3
                best_match = ''
                for zone in zones.keys():
                    if re.search('^%s\.' % zone,
                                 ip) and len(zone) > len(best_match):
                        best_match = zone

                if best_match == '':  # no match
                    continue

                # strip the zone off the front of the ip
                # reverse the rest of the octets
                # append the remainder + dns_name
                ip = ip.replace(best_match, '', 1)
                if ip[0] == '.':  # strip leading '.' if it's there
                    ip = ip[1:]
                tokens = ip.split('.')
                tokens.reverse()
                ip = '.'.join(tokens)
                zones[best_match][ip] = host + '.'

        return zones
Ejemplo n.º 2
0
    def __reverse_zones(self):
        """
        Returns a map of zones and the records that belong
        in them
        """
        zones = {}
        reverse_zones = self.settings.manage_reverse_zones
        if type(reverse_zones) != type([]):
           # gracefully handle when user inputs only a single zone
           # as a string instead of a list with only a single item
           reverse_zones = [reverse_zones]

        for zone in reverse_zones:
           zones[zone] = {}

        for sys in self.systems:
            for (name, interface) in sys.interfaces.iteritems():
                host = interface["dns_name"]
                ip   = interface["ip_address"]
                if not sys.is_management_supported(cidr_ok=False):
                    continue
                if not host or not ip:
                    # gotsta have some dns_name and ip or else!
                    continue

                # match the longest zone!
                # e.g. if you have an ip 1.2.3.4
                # if manage_reverse_zones has:
                # - 1.2
                # - 1.2.3
                # then 1.2.3.4 should go in 1.2.3
                best_match = ''
                for zone in zones.keys():
                   if re.search('^%s\.' % zone, ip) and len(zone) > len(best_match):
                      best_match = zone

                if best_match == '': # no match
                   continue

                # strip the zone off the front of the ip
                # reverse the rest of the octets
                # append the remainder + dns_name
                ip = ip.replace(best_match, '', 1)
                if ip[0] == '.': # strip leading '.' if it's there
                   ip = ip[1:]
                tokens = ip.split('.')
                tokens.reverse()
                ip = '.'.join(tokens)
                zones[best_match][ip] = host + '.'

        return zones
Ejemplo n.º 3
0
    def __reverse_zones(self):
        """
        Returns a map of zones and the records that belong
        in them
        """
        zones = {}
        reverse_zones = self.settings.manage_reverse_zones
        if type(reverse_zones) != type([]):
           # gracefully handle when user inputs only a single zone
           # as a string instead of a list with only a single item
           reverse_zones = [reverse_zones]

        for zone in reverse_zones:
           # expand and IPv6 zones
           if ":" in zone:
              zone = (self.__expand_IPv6(zone + '::1'))[:19]
           zones[zone] = {}

        for sys in self.systems:
            for (name, interface) in sys.interfaces.iteritems():
                host = interface["dns_name"]
                ip   = interface["ip_address"]
                ipv6 = interface["ipv6_address"]
                ipv6_sec_addrs = interface["ipv6_secondaries"]
                if not sys.is_management_supported(cidr_ok=False):
                    continue
                if not host or ( ( not ip ) and ( not ipv6) ):
                    # gotsta have some dns_name and ip or else!
                    continue

                if ip:
                    # match the longest zone!
                    # e.g. if you have an ip 1.2.3.4
                    # if manage_reverse_zones has:
                    # - 1.2
                    # - 1.2.3
                    # then 1.2.3.4 should go in 1.2.3
                    best_match = ''
                    for zone in zones.keys():
                        if re.search('^%s\.' % zone, ip) and len(zone) > len(best_match):
                            best_match = zone

                    if best_match != '':
                        # strip the zone off the front of the ip
                        # reverse the rest of the octets
                        # append the remainder + dns_name
                        ip = ip.replace(best_match, '', 1)
                        if ip[0] == '.': # strip leading '.' if it's there
                            ip = ip[1:]
                        tokens = ip.split('.')
                        tokens.reverse()
                        ip = '.'.join(tokens)
                        zones[best_match][ip] = host + '.'

                if ipv6 or ipv6_sec_addrs:
                    ip6s = []
                    if ipv6:
                       ip6s.append(ipv6)
                    for each_ipv6 in ip6s + ipv6_sec_addrs:
                        # convert the IPv6 address to long format
                        long_ipv6 = self.__expand_IPv6(each_ipv6)
                        # All IPv6 zones are forced to have the format
                        # xxxx:xxxx:xxxx:xxxx
                        zone = long_ipv6[:19]
                        ipv6_host_part = long_ipv6[20:]
                        tokens = list(re.sub(':', '', ipv6_host_part))
                        tokens.reverse()
                        ip = '.'.join(tokens)
                        zones[zone][ip] = host + '.'

        return zones
Ejemplo n.º 4
0
    def __reverse_zones(self):
        """
        Returns a map of zones and the records that belong
        in them
        """
        zones = {}
        reverse_zones = self.settings.manage_reverse_zones
        if type(reverse_zones) != type([]):
            # gracefully handle when user inputs only a single zone
            # as a string instead of a list with only a single item
            reverse_zones = [reverse_zones]

        for zone in reverse_zones:
            # expand and IPv6 zones
            if ":" in zone:
                zone = (self.__expand_IPv6(zone + '::1'))[:19]
            zones[zone] = {}

        for sys in self.systems:
            for (name, interface) in sys.interfaces.iteritems():
                host = interface["dns_name"]
                ip = interface["ip_address"]
                ipv6 = interface["ipv6_address"]
                ipv6_sec_addrs = interface["ipv6_secondaries"]
                if not sys.is_management_supported(cidr_ok=False):
                    continue
                if not host or ((not ip) and (not ipv6)):
                    # gotsta have some dns_name and ip or else!
                    continue

                if ip:
                    # match the longest zone!
                    # e.g. if you have an ip 1.2.3.4
                    # if manage_reverse_zones has:
                    # - 1.2
                    # - 1.2.3
                    # then 1.2.3.4 should go in 1.2.3
                    best_match = ''
                    for zone in zones.keys():
                        if re.search('^%s\.' % zone,
                                     ip) and len(zone) > len(best_match):
                            best_match = zone

                    if best_match != '':
                        # strip the zone off the front of the ip
                        # reverse the rest of the octets
                        # append the remainder + dns_name
                        ip = ip.replace(best_match, '', 1)
                        if ip[0] == '.':  # strip leading '.' if it's there
                            ip = ip[1:]
                        tokens = ip.split('.')
                        tokens.reverse()
                        ip = '.'.join(tokens)
                        zones[best_match][ip] = host + '.'

                if ipv6 or ipv6_sec_addrs:
                    ip6s = []
                    if ipv6:
                        ip6s.append(ipv6)
                    for each_ipv6 in ip6s + ipv6_sec_addrs:
                        # convert the IPv6 address to long format
                        long_ipv6 = self.__expand_IPv6(each_ipv6)
                        # All IPv6 zones are forced to have the format
                        # xxxx:xxxx:xxxx:xxxx
                        zone = long_ipv6[:19]
                        ipv6_host_part = long_ipv6[20:]
                        tokens = list(re.sub(':', '', ipv6_host_part))
                        tokens.reverse()
                        ip = '.'.join(tokens)
                        zones[zone][ip] = host + '.'

        return zones