'Returns a map of zones and the records that belong
in them'

def __reverse_zones(self):

    zones = {}
    reverse_zones = self.settings.manage_reverse_zones
    if (not isinstance(reverse_zones, list)):
        reverse_zones = [reverse_zones]
    for zone in reverse_zones:
        if (':' in zone):
            zone = self.__expand_IPv6((zone + '::1'))[:19]
        zones[zone] = {}
    for system in self.systems:
        for (name, interface) in system.interfaces.iteritems():
            host = interface['dns_name']
            ip = interface['ip_address']
            ipv6 = interface['ipv6_address']
            ipv6_sec_addrs = interface['ipv6_secondaries']
            if (not system.is_management_supported(cidr_ok=False)):
                continue
            if ((not host) or ((not ip) and (not ipv6))):
                continue
            if ip:
                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 != ''):
                    ip = ip.replace(best_match, '', 1)
                    if (ip[0] == '.'):
                        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):
                    long_ipv6 = self.__expand_IPv6(each_ipv6)
                    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
