Changeset 13321 in genesis


Ignore:
Timestamp:
Jul 28, 2015, 7:30:21 AM (8 years ago)
Author:
rick
Message:

Cosmetics move cache generation to new function

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/getrange.py

    r11514 r13321  
    2727
    2828bezet_cache = None
     29def make_cache():
     30  global bezet_cache
     31  bezet = {}
     32  substs = {}
     33  def add_ip(address):
     34    if '/' not in address:
     35      address += "/32"
     36
     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)
     48 
     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  bezet_cache = bezet
     63  return bezet
     64
     65
    2966def get_ranges(interlink, size, aantal, use_history=False):
    3067  global bezet_cache
     
    3269 
    3370  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"
    39 
    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
     71    bezet = make_cache()
    6572  else:
    6673    bezet = bezet_cache
Note: See TracChangeset for help on using the changeset viewer.