Changeset 8584 in genesis
- Timestamp:
- Oct 20, 2010, 8:02:47 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
nodes/gformat.py
r8575 r8584 14 14 import sys 15 15 import time 16 from pprint import pprint 16 17 try: 17 18 import yaml … … 139 140 """ Display IPv4 addr in (dotted) CIDR notation """ 140 141 return "%d.%d.%d.%d" % ((a >> 24) & 0xff, (a >> 16) & 0xff, (a >> 8) & 0xff, a & 0xff) 142 143 144 def is_member(ip, mask, canidate): 145 """ Return True if canidate is part of ip/mask block""" 146 ip_addr = gformat.parseaddr(ip) 147 ip_canidate = gformat.parseaddr(canidate) 148 mask = int(mask) 149 ip_addr = ip_addr & ~((1 << (32 - mask)) - 1) 150 ip_canidate = ip_canidate & ~((1 << (32 - mask)) - 1) 151 return ip_addr == ip_canidate 152 141 153 142 154 … … 524 536 f.write(generate_config(node, config, datadump)) 525 537 f.close() 538 elif sys.argv[1] == "dns": 539 items = dict() 540 # hostname is key, IP is value 541 wleiden_zone = dict() 542 wleiden_cname = dict() 543 pool = dict() 544 for node in get_hostlist(): 545 datadump = get_yaml(node) 546 547 # Proxy naming convention is special 548 if datadump['nodetype'] == 'Proxy': 549 fqdn = datadump['nodename'] 550 else: 551 # By default the full name is listed and also a shortname CNAME for easy use. 552 fqdn = datadump['nodetype'] + datadump['nodename'] 553 wleiden_cname[datadump['nodename']] = fqdn 554 wleiden_zone[fqdn] = datadump['masterip'] 555 556 #items['node'] = node 557 #items['wdir'] = "./static/%(node)s" % items 558 #if not os.path.isdir(items['wdir']): 559 # os.makedirs(items['wdir']) 560 for iface_key in get_interface_keys(datadump): 561 iface_name = datadump[iface_key]['interface'].replace(':',"_alias_") 562 (ip, netmask) = datadump[iface_key]['ip'].split('/') 563 try: 564 (dhcp_start, dhcp_stop) = datadump[iface_key]['dhcp'].split('-') 565 datadump[iface_key]['subnet'] = netmask2subnet(netmask) 566 dhcp_part = ".".join(ip.split('.')[0:3]) 567 wleiden_zone["dhcp-gateway-%s.%s" % (iface_name, fqdn)] = ip 568 for i in range(int(dhcp_start), int(dhcp_stop) + 1): 569 wleiden_zone["dhcp-%s-%s.%s" % (i, iface_name, fqdn)] = "%s.%s" % (dhcp_part, i) 570 except (AttributeError, ValueError): 571 # First push it into a pool, to indentify the counter-part later on 572 addr = parseaddr(ip) 573 netmask = int(netmask) 574 addr = addr & ~((1 << (32 - netmask)) - 1) 575 if pool.has_key(addr): 576 pool[addr] += [(iface_name, fqdn, ip)] 577 else: 578 pool[addr] = [(iface_name, fqdn, ip)] 579 continue 580 581 # wleiden_zone["2%s-%s.%s" % ("unused", iface_name, fqdn)] = ip 582 # #XXX: automatic naming convention namely 2 + remote.lower() 583 for (key,value) in pool.iteritems(): 584 if len(value) == 1: 585 (iface_name, fqdn, ip) = value[0] 586 wleiden_zone["2unused-%s.%s" % (iface_name, fqdn)] = ip 587 elif len(value) == 2: 588 (a_iface_name, a_fqdn, a_ip) = value[0] 589 (b_iface_name, b_fqdn, b_ip) = value[1] 590 wleiden_zone["2%s.%s" % (b_fqdn,a_fqdn)] = a_ip 591 wleiden_zone["2%s.%s" % (a_fqdn,b_fqdn)] = b_ip 592 else: 593 pool_members = [k[1] for k in value] 594 for item in value: 595 (iface_name, fqdn, ip) = item 596 pool_name = "2pool-" + showaddr(key).replace('.','-') + "-" + "_".join(sorted(list(set(pool_members) - set([fqdn])))) 597 wleiden_zone["%s.%s" % (pool_name, fqdn)] = ip 598 599 600 #pprint(pool) 601 pprint(wleiden_zone) 602 #for config in files: 603 # items['config'] = config 604 # print "## Generating %(node)s %(config)s" % items 605 # f = open("%(wdir)s/%(config)s" % items, "w") 606 # f.write(generate_config(node, config, datadump)) 607 # f.close() 526 608 else: 527 609 usage()
Note:
See TracChangeset
for help on using the changeset viewer.