- Timestamp:
- May 1, 2012, 8:55:33 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/gformat.py
r10627 r10642 929 929 930 930 # hostname is key, IP is value 931 wleiden_zone = d ict()931 wleiden_zone = defaultdict(list) 932 932 wleiden_cname = dict() 933 933 … … 941 941 wleiden_cname[datadump['nodename']] = fqdn 942 942 943 wleiden_zone[fqdn] = datadump['masterip']943 wleiden_zone[fqdn].append(datadump['masterip']) 944 944 945 945 # Hacking to get proper DHCP IPs and hostnames … … 952 952 dhcp_part = ".".join(ip.split('.')[0:3]) 953 953 if ip != datadump['masterip']: 954 wleiden_zone["dhcp-gateway-%s.%s" % (iface_name, fqdn)] = ip954 wleiden_zone["dhcp-gateway-%s.%s" % (iface_name, fqdn)].append(ip) 955 955 for i in range(int(dhcp_start), int(dhcp_stop) + 1): 956 wleiden_zone["dhcp-%s-%s.%s" % (i, iface_name, fqdn)] = "%s.%s" % (dhcp_part, i)956 wleiden_zone["dhcp-%s-%s.%s" % (i, iface_name, fqdn)].append("%s.%s" % (dhcp_part, i)) 957 957 except (AttributeError, ValueError): 958 958 # First push it into a pool, to indentify the counter-part later on … … 994 994 if len(value) == 1: 995 995 (iface_name, fqdn, ip) = value[0] 996 wleiden_zone["2unused-%s.%s" % (iface_name, fqdn)] = ip996 wleiden_zone["2unused-%s.%s" % (iface_name, fqdn)].append(ip) 997 997 998 998 # Device DNS names 999 999 if 'cnode' in fqdn.lower(): 1000 wleiden_zone["d-at-%s.%s" % (iface_name, fqdn)] = showaddr(parseaddr(ip) + 1)1000 wleiden_zone["d-at-%s.%s" % (iface_name, fqdn)].append(showaddr(parseaddr(ip) + 1)) 1001 1001 wleiden_cname["d-at-%s.%s" % (iface_name,sn(fqdn))] = "d-at-%s.%s" % (iface_name, fqdn) 1002 1002 … … 1004 1004 (a_iface_name, a_fqdn, a_ip) = value[0] 1005 1005 (b_iface_name, b_fqdn, b_ip) = value[1] 1006 wleiden_zone["2%s.%s" % (b_fqdn,a_fqdn)] = a_ip1007 wleiden_zone["2%s.%s" % (a_fqdn,b_fqdn)] = b_ip1006 wleiden_zone["2%s.%s" % (b_fqdn,a_fqdn)].append(a_ip) 1007 wleiden_zone["2%s.%s" % (a_fqdn,b_fqdn)].append(b_ip) 1008 1008 1009 1009 # Device DNS names 1010 1010 if 'cnode' in a_fqdn.lower() and 'cnode' in b_fqdn.lower(): 1011 wleiden_zone["d-at-%s.%s" % (a_iface_name, a_fqdn)] = showaddr(parseaddr(a_ip) + 1)1012 wleiden_zone["d-at-%s.%s" % (b_iface_name, b_fqdn)] = showaddr(parseaddr(b_ip) - 1)1011 wleiden_zone["d-at-%s.%s" % (a_iface_name, a_fqdn)].append(showaddr(parseaddr(a_ip) + 1)) 1012 wleiden_zone["d-at-%s.%s" % (b_iface_name, b_fqdn)].append(showaddr(parseaddr(b_ip) - 1)) 1013 1013 wleiden_cname["d-at-%s.%s" % (a_iface_name,sn(a_fqdn))] = "d-at-%s.%s" % (a_iface_name, a_fqdn) 1014 1014 wleiden_cname["d-at-%s.%s" % (b_iface_name,sn(b_fqdn))] = "d-at-%s.%s" % (b_iface_name, b_fqdn) … … 1021 1021 (iface_name, fqdn, ip) = item 1022 1022 pool_name = "2pool-" + showaddr(key).replace('.','-') + "-" + pool_to_name(fqdn,pool_members) 1023 wleiden_zone["%s.%s" % (pool_name, fqdn)] = ip1023 wleiden_zone["%s.%s" % (pool_name, fqdn)].append(ip) 1024 1024 1025 1025 # Include static DNS entries … … 1030 1030 ## roomburgh=CNodeRoomburgh1 1031 1031 ## apkerk1.CNodeVosko=172.17.176.8 ;this as well 1032 dns = yaml.load(open(os.path.join(NODE_DIR,'../dns/staticDNS.yaml'),'r'))1032 dns_list = yaml.load(open(os.path.join(NODE_DIR,'../dns/staticDNS.yaml'),'r')) 1033 1033 1034 1034 # Hack to allow special entries, for development 1035 wleiden_raw = dns['raw'] 1036 del dns['raw'] 1037 1038 for comment, block in dns.iteritems(): 1039 for k,v in block.iteritems(): 1040 if valid_addr(v): 1041 wleiden_zone[k] = v 1035 wleiden_raw = {} 1036 1037 for line in dns_list: 1038 k, items = line.items()[0] 1039 items = [items] if type(items) == str else items 1040 for item in items: 1041 if item.startswith('IN '): 1042 wleiden_raw[k] = item 1043 elif valid_addr(item): 1044 wleiden_zone[k].append(item) 1042 1045 else: 1043 wleiden_cname[k] = v1046 wleiden_cname[k] = item 1044 1047 1045 1048 details = dict() … … 1070 1073 f.write(dns_header % details) 1071 1074 1072 for host,ip in wleiden_zone.iteritems(): 1073 if valid_addr(ip): 1074 f.write("%s.wleiden.net. IN A %s \n" % (host.lower(), ip)) 1075 for host,ips in wleiden_zone.iteritems(): 1076 for ip in ips: 1077 if valid_addr(ip): 1078 f.write("%s.wleiden.net. IN A %s \n" % (host.lower(), ip)) 1075 1079 for source,dest in wleiden_cname.iteritems(): 1076 1080 f.write("%s.wleiden.net. IN CNAME %s.wleiden.net.\n" % (source.lower(), dest.lower())) … … 1087 1091 #XXX: Not effient, fix to proper data structure and do checks at other 1088 1092 # stages 1089 for host,ip in wleiden_zone.iteritems(): 1090 if valid_addr(ip): 1091 if int(ip.split('.')[1]) == s: 1092 rev_ip = '.'.join(reversed(ip.split('.'))) 1093 f.write("%s.in-addr.arpa. IN PTR %s.wleiden.net.\n" % (rev_ip.lower(), host.lower())) 1093 for host,ips in wleiden_zone.iteritems(): 1094 for ip in ips: 1095 if valid_addr(ip): 1096 if int(ip.split('.')[1]) == s: 1097 rev_ip = '.'.join(reversed(ip.split('.'))) 1098 f.write("%s.in-addr.arpa. IN PTR %s.wleiden.net.\n" % (rev_ip.lower(), host.lower())) 1094 1099 f.close() 1095 1100
Note:
See TracChangeset
for help on using the changeset viewer.