Changeset 11514 in genesis


Ignore:
Timestamp:
Sep 30, 2012, 8:34:43 PM (12 years ago)
Author:
rick
Message:

Nasty hack for calling function multiple times without the need of:

1) parsing all config files all the time.
2) Remembering the previous spit out entries.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/getrange.py

    r10052 r11514  
    2626
    2727
    28 def get_ranges(interlink, size, aantal):
     28bezet_cache = None
     29def get_ranges(interlink, size, aantal, use_history=False):
     30  global bezet_cache
    2931  numaddrs = 1 << (32 - size)
    3032 
    31   bezet = {}
    32   substs = {}
    33   def add_ip(address):
    34     if '/' not in address:
    35       address += "/32"
     33  if not use_history or (use_history and not bezet_cache):
     34    bezet = {}
     35    substs = {}
     36    def add_ip(address):
     37      if '/' not in address:
     38        address += "/32"
    3639
    37     addr, mask = address.split('/')
    38     if addr in substs:
    39       addr = substs[addr]
    40     try:
    41       addr = parseaddr(addr)
    42       mask = int(mask)
    43       addr = addr & ~((1 << (32 - mask)) - 1)
    44       for i in range(0, (1 << (32 - mask))):
    45         bezet[addr + i] = 1
    46     except ValueError, e:
    47       print "[FOUT] in address %s node %s" % (address, node)
     40      addr, mask = address.split('/')
     41      if addr in substs:
     42        addr = substs[addr]
     43      try:
     44        addr = parseaddr(addr)
     45        mask = int(mask)
     46        addr = addr & ~((1 << (32 - mask)) - 1)
     47        for i in range(0, (1 << (32 - mask))):
     48          bezet[addr + i] = 1
     49      except ValueError, e:
     50        print "[FOUT] in address %s node %s" % (address, node)
     51   
     52    for node in gformat.get_hostlist():
     53      datadump = gformat.get_yaml(node)
     54
     55      add_ip(datadump['masterip'])
     56      for key in datadump['autogen_iface_keys']:
     57        add_ip(datadump[key]['ip'])
     58
     59    # Fetching smallest in use IP
     60    # XXX: Currently not used for anything
     61    i = parseaddr("255.255.255.255")
     62    for k in bezet.keys():
     63      if k < i:
     64        i = k
     65  else:
     66    bezet = bezet_cache
    4867 
    49   for node in gformat.get_hostlist():
    50     datadump = gformat.get_yaml(node)
    51 
    52     add_ip(datadump['masterip'])
    53     for key in datadump['autogen_iface_keys']:
    54       add_ip(datadump[key]['ip'])
    55 
    56   # Fetching smallest in use IP
    57   # XXX: Currently not used for anything
    58   i = parseaddr("255.255.255.255")
    59   for k in bezet.keys():
    60     if k < i:
    61       i = k
    62  
     68 
    6369  # Interlinks are living in special ranges usually
    6470  if interlink:
     
    8490    bezet[i] = 1
    8591
     92  bezet_cache = bezet
    8693  return ranges
    8794
Note: See TracChangeset for help on using the changeset viewer.