Changeset 10054 in genesis for tools/gformat.py


Ignore:
Timestamp:
Mar 7, 2012, 11:03:33 PM (13 years ago)
Author:
rick
Message:

Include proxy configuration in gformat generation

Related-To: ticket:117

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/gformat.py

    r10053 r10054  
    5656    'rc.conf.local',
    5757    'resolv.conf',
    58     'wleiden.yaml'
     58    'wleiden.yaml',
    5959    ]
    6060
     
    262262  output = generate_header("#");
    263263  output += """\
    264 hostname='%(nodetype)s%(nodename)s.%(domain)s'
     264hostname='%(autogen_fqdn)s.%(domain)s'
    265265location='%(location)s'
    266266""" % datadump
     
    278278
    279279  # Extra Proxy configuration
     280  datadump['ileiden_enable'] = 'yes' if datadump['ileiden'] else 'no'
    280281  if datadump['nodetype'] == 'Proxy':
    281     output += '\n# Disable routing\ngateway_enable="no"\n'
    282 
    283   output += '\ninternalif="%s"\n' % datadump['internalif']
    284 
    285   output += '\n'
     282    output += """
     283#
     284# PROXY Configuration
     285#
     286sshtun_enable="YES"
     287sshtun_flags="-R 22%(proxyid)02i:localhost:22"
     288
     289static_routes="wleiden"
     290route_wleiden="-net 172.16.0.0/12 %(internalroute)s"
     291
     292internalif="%(internalif)s"
     293
     294# PROXY iLeiden Configuration
     295ileiden_enable="%(ileiden_enable)s"
     296gateway_enable="%(ileiden_enable)s"
     297firewall_enable="%(ileiden_enable)s"
     298firewall_script="/etc/ipfw.sh"
     299firewall_nat_enable="%(ileiden_enable)s"
     300""" % datadump
     301
     302  if datadump['nodetype'] == 'CNode' and datadump['ileiden']:
     303    output += """
     304# NODE iLeiden Configuration
     305ileiden_enable="%(ileiden_enable)s"
     306
     307captive_portal_whitelist=""
     308captive_portal_interfaces="%(autogen_dhcp_interfaces)s"
     309""" % datadump
     310
    286311  # lo0 configuration:
    287312  # - 172.32.255.1/32 is the proxy.wleiden.net deflector
     
    299324    addrs_list['lo0'].append(datadump['masterip'] + "/32")
    300325
    301   wlan_count = 0
    302326  for iface_key in datadump['iface_keys']:
    303327    ifacedump = datadump[iface_key]
     
    320344    # XXX: Might want to deduct type directly from interface name
    321345    if ifacedump['type'] in ['11a', '11b', '11g', 'wireless']:
    322       # Create wlanX interface
    323       ifacedump['wlanif'] ="wlan%i" % wlan_count
    324       iface_map[interface] = ifacedump['wlanif']
    325       wlan_count += 1
    326 
    327346      # Default to station (client) mode
    328347      ifacedump['wlanmode'] = "sta"
     
    344363        ifacedump['extra'] = 'regdomain ETSI country NL'
    345364
    346       output += "wlans_%(interface)s='%(wlanif)s'\n" % ifacedump
    347       output += ("create_args_%(wlanif)s='wlanmode %(wlanmode)s mode " +\
     365      output += "wlans_%(interface)s='%(autogen_ifname)s'\n" % ifacedump
     366      output += ("create_args_%(autogen_ifname)s='wlanmode %(wlanmode)s mode " +\
    348367        "%(mode)s ssid %(ssid)s %(extra)s channel %(channel)s'\n") % ifacedump
    349368
     
    372391  datadump = yaml.load(f,Loader=Loader)
    373392  datadump['autogen_iface_keys'] = get_interface_keys(datadump)
     393
     394  wlan_count=0
     395  for key in datadump['autogen_iface_keys']:
     396    if datadump[key]['type'] in ['11a', '11b', '11g', 'wireless']:
     397      datadump[key]['autogen_ifname'] = 'wlan%i' % wlan_count
     398      wlan_count += 1
     399    else:
     400      datadump[key]['autogen_ifname'] = datadump[key]['interface']
     401
     402
     403  dhcp_interfaces = [datadump[key]['autogen_ifname'] for key in datadump['autogen_iface_keys'] if datadump[key]['dhcp'] != 'no']
     404  datadump['autogen_dhcp_interfaces'] = ' '.join(dhcp_interfaces)
    374405  datadump['autogen_item'] = item
     406  datadump['autogen_fqdn'] = get_fqdn(datadump)
    375407  f.close()
    376408
     
    399431def get_interface_keys(config):
    400432  """ Quick hack to get all interface keys, later stage convert this to a iterator """
    401   return [elem for elem in config.keys() if (elem.startswith('iface_') and not "lo0" in elem)]
     433  return sorted([elem for elem in config.keys() if (elem.startswith('iface_') and not "lo0" in elem)])
    402434
    403435
     
    485517    if key.startswith('autogen_'):
    486518      del datadump[key]
     519    # Interface autogen cleanups
     520    elif type(datadump[key]) == dict:
     521      for key2 in datadump[key].keys():
     522        if key2.startswith('autogen_'):
     523          del datadump[key][key2]
     524     
    487525
    488526  output = generate_header("#")
Note: See TracChangeset for help on using the changeset viewer.