Changeset 10860 in genesis


Ignore:
Timestamp:
May 15, 2012, 12:09:50 AM (13 years ago)
Author:
rick
Message:

Use some basic caching to speedup generation of config files while doing static
runs and/or unit-testing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/gformat.py

    r10825 r10860  
    9595UNKNOWN = 90
    9696
     97datadump_cache = {}
     98
    9799def get_yaml(item):
    98100  """ Get configuration yaml for 'item'"""
     101  if datadump_cache.has_key(item):
     102    return datadump_cache[item].copy()
     103
    99104  gfile = os.path.join(NODE_DIR,item,'wleiden.yaml')
    100105
     
    136141  datadump['autogen_domain'] = datadump['domain'] if datadump.has_key('domain') else 'wleiden.net.'
    137142  datadump['autogen_fqdn'] = datadump['autogen_realname'] + '.' + datadump['autogen_domain']
     143  datadump_cache[item] = datadump.copy()
    138144  return datadump
    139145
     
    477483
    478484
     485ileiden_proxies = []
     486normal_proxies = []
     487rc_conf_local_cache = {}
    479488
    480489def generate_rc_conf_local(datadump):
    481490  """ Generate configuration file '/etc/rc.conf.local' """
     491  item = datadump['autogen_item']
     492  if rc_conf_local_cache.has_key(item):
     493    return rc_conf_local_cache[item]
     494
    482495  if not datadump.has_key('ileiden'):
    483496    datadump['autogen_ileiden_enable'] = False
     
    487500  datadump['autogen_ileiden_enable'] = switchFormat(datadump['autogen_ileiden_enable'])
    488501
    489   ileiden_proxies = []
    490   normal_proxies = []
    491   for proxy in get_proxylist():
    492     proxydump = get_yaml(proxy)
    493     if proxydump['ileiden']:
    494       ileiden_proxies.append(proxydump)
    495     else:
    496       normal_proxies.append(proxydump)
    497   for host in get_hybridlist():
    498     hostdump = get_yaml(host)
    499     if hostdump['service_proxy_ileiden']:
    500       ileiden_proxies.append(hostdump)
    501     if hostdump['service_proxy_normal']:
    502       normal_proxies.append(hostdump)
     502  if not ileiden_proxies or not normal_proxies:
     503    for proxy in get_proxylist():
     504      proxydump = get_yaml(proxy)
     505      if proxydump['ileiden']:
     506        ileiden_proxies.append(proxydump)
     507      else:
     508        normal_proxies.append(proxydump)
     509    for host in get_hybridlist():
     510      hostdump = get_yaml(host)
     511      if hostdump['service_proxy_ileiden']:
     512        ileiden_proxies.append(hostdump)
     513      if hostdump['service_proxy_normal']:
     514        normal_proxies.append(hostdump)
    503515
    504516  datadump['autogen_ileiden_proxies'] = ileiden_proxies
     
    713725      output += "ipv4_addrs_%s='%s'\n\n" % (iface, " ".join([x[0] for x in addrs]))
    714726
     727  rc_conf_local_cache[datadump['autogen_item']] = output
    715728  return output
    716729
Note: See TracChangeset for help on using the changeset viewer.