Changeset 10907 in genesis


Ignore:
Timestamp:
May 18, 2012, 10:30:26 PM (13 years ago)
Author:
rick
Message:

Make the motd output look more pretty.

While here: Sync up motd processing quite a bit, by removing the heavy duplicate call to
rc_conf_local.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/gformat.py

    r10906 r10907  
    526526
    527527
     528interface_list_cache = {}
     529def make_interface_list(datadump):
     530  if interface_list_cache.has_key(datadump['autogen_item']):
     531    return (interface_list_cache[datadump['autogen_item']])
     532  # lo0 configuration:
     533  # - 172.32.255.1/32 is the proxy.wleiden.net deflector
     534  # - masterip is special as it needs to be assigned to at
     535  #   least one interface, so if not used assign to lo0
     536  addrs_list = { 'lo0' : [("127.0.0.1/8", "LocalHost"), ("172.31.255.1/32","Proxy IP")] }
     537  dhclient_if = {'lo0' : False}
     538
     539  # XXX: Find some way of send this output nicely
     540  output = ''
     541
     542  masterip_used = False
     543  for iface_key in datadump['autogen_iface_keys']:
     544    if datadump[iface_key]['ip'].startswith(datadump['masterip']):
     545      masterip_used = True
     546      break
     547  if not masterip_used:
     548    addrs_list['lo0'].append((datadump['masterip'] + "/32", 'Master IP Not used in interface'))
     549
     550  for iface_key in datadump['autogen_iface_keys']:
     551    ifacedump = datadump[iface_key]
     552    ifname = ifacedump['autogen_ifname']
     553
     554    # Flag dhclient is possible
     555    dhclient_if[ifname] = dhcp_type(ifacedump) == DHCP_CLIENT
     556
     557    # Add interface IP to list
     558    item = (ifacedump['ip'], ifacedump['comment'])
     559    if addrs_list.has_key(ifname):
     560      addrs_list[ifname].append(item)
     561    else:
     562      addrs_list[ifname] = [item]
     563
     564    # Alias only needs IP assignment for now, this might change if we
     565    # are going to use virtual accesspoints
     566    if "alias" in iface_key:
     567      continue
     568
     569    # XXX: Might want to deduct type directly from interface name
     570    if ifacedump['type'] in ['11a', '11b', '11g', 'wireless']:
     571      # Default to station (client) mode
     572      ifacedump['autogen_wlanmode'] = "sta"
     573      if ifacedump['mode'] in ['master', 'master-wds', 'ap', 'ap-wds']:
     574        ifacedump['autogen_wlanmode'] = "ap"
     575      # Default to 802.11b mode
     576      ifacedump['mode'] = '11b'
     577      if ifacedump['type'] in ['11a', '11b' '11g']:
     578        ifacedump['mode'] = ifacedump['type']
     579
     580      if not ifacedump.has_key('channel'):
     581        if ifacedump['type'] == '11a':
     582          ifacedump['channel'] = 36
     583        else:
     584          ifacedump['channel'] = 1
     585
     586      # Allow special hacks at the back like wds and stuff
     587      if not ifacedump.has_key('extra'):
     588        ifacedump['autogen_extra'] = 'regdomain ETSI country NL'
     589      else:
     590        ifacedump['autogen_extra'] = ifacedump['extra']
     591       
     592      output += "wlans_%(autogen_ifbase)s='%(autogen_ifname)s'\n" % ifacedump
     593      output += ("create_args_%(autogen_ifname)s='wlanmode %(autogen_wlanmode)s mode " +\
     594        "%(mode)s ssid %(ssid)s %(autogen_extra)s channel %(channel)s'\n") % ifacedump
     595
     596    elif ifacedump['type'] in ['ethernet', 'eth']:
     597      # No special config needed besides IP
     598      pass
     599    else:
     600      assert False, "Unknown type " + ifacedump['type']
     601
     602  store = (addrs_list, dhclient_if, output)
     603  interface_list_cache[datadump['autogen_item']] = store
     604  return(store)
     605
     606
     607
    528608ileiden_proxies = []
    529609normal_proxies = []
    530610rc_conf_local_cache = {}
    531 
    532611def generate_rc_conf_local(datadump):
    533612  """ Generate configuration file '/etc/rc.conf.local' """
     
    690769""")
    691770
    692   # lo0 configuration:
    693   # - 172.32.255.1/32 is the proxy.wleiden.net deflector
    694   # - masterip is special as it needs to be assigned to at
    695   #   least one interface, so if not used assign to lo0
    696   addrs_list = { 'lo0' : [("127.0.0.1/8", "LocalHost"), ("172.31.255.1/32","Proxy IP")] }
    697   iface_map = {'lo0' : 'lo0'}
    698   dhclient_if = {'lo0' : False}
    699 
    700   masterip_used = False
    701   for iface_key in datadump['autogen_iface_keys']:
    702     if datadump[iface_key]['ip'].startswith(datadump['masterip']):
    703       masterip_used = True
    704       break
    705   if not masterip_used:
    706     addrs_list['lo0'].append((datadump['masterip'] + "/32", 'Master IP Not used in interface'))
    707 
    708   for iface_key in datadump['autogen_iface_keys']:
    709     ifacedump = datadump[iface_key]
    710     ifname = ifacedump['autogen_ifname']
    711 
    712     # Flag dhclient is possible
    713     dhclient_if[ifname] = dhcp_type(ifacedump) == DHCP_CLIENT
    714 
    715     # Add interface IP to list
    716     item = (ifacedump['ip'], ifacedump['comment'])
    717     if addrs_list.has_key(ifname):
    718       addrs_list[ifname].append(item)
    719     else:
    720       addrs_list[ifname] = [item]
    721 
    722     # Alias only needs IP assignment for now, this might change if we
    723     # are going to use virtual accesspoints
    724     if "alias" in iface_key:
    725       continue
    726 
    727     # XXX: Might want to deduct type directly from interface name
    728     if ifacedump['type'] in ['11a', '11b', '11g', 'wireless']:
    729       # Default to station (client) mode
    730       ifacedump['autogen_wlanmode'] = "sta"
    731       if ifacedump['mode'] in ['master', 'master-wds', 'ap', 'ap-wds']:
    732         ifacedump['autogen_wlanmode'] = "ap"
    733       # Default to 802.11b mode
    734       ifacedump['mode'] = '11b'
    735       if ifacedump['type'] in ['11a', '11b' '11g']:
    736         ifacedump['mode'] = ifacedump['type']
    737 
    738       if not ifacedump.has_key('channel'):
    739         if ifacedump['type'] == '11a':
    740           ifacedump['channel'] = 36
    741         else:
    742           ifacedump['channel'] = 1
    743 
    744       # Allow special hacks at the back like wds and stuff
    745       if not ifacedump.has_key('extra'):
    746         ifacedump['autogen_extra'] = 'regdomain ETSI country NL'
    747       else:
    748         ifacedump['autogen_extra'] = ifacedump['extra']
    749        
    750 
    751       output += "wlans_%(autogen_ifbase)s='%(autogen_ifname)s'\n" % ifacedump
    752       output += ("create_args_%(autogen_ifname)s='wlanmode %(autogen_wlanmode)s mode " +\
    753         "%(mode)s ssid %(ssid)s %(autogen_extra)s channel %(channel)s'\n") % ifacedump
    754 
    755     elif ifacedump['type'] in ['ethernet', 'eth']:
    756       # No special config needed besides IP
    757       pass
    758     else:
    759       assert False, "Unknown type " + ifacedump['type']
     771  (addrs_list, dhclient_if, extra_ouput) = make_interface_list(datadump)
     772  output += extra_ouput
    760773
    761774  # Print IP address which needs to be assigned over here
     
    927940""").render(datadump)
    928941
    929   # XXX: This is a hacky way to get the required data
    930   for line in generate_rc_conf_local(datadump).split('\n'):
    931     if '||' in line and not line[1:].split()[0] in ['lo0', 'ath0'] :
    932       output += " - %s \n" % line[1:]
     942  (addrs_list, dhclient_if, extra_ouput) = make_interface_list(datadump)
     943  # Just nasty hack to make the formatting looks nice
     944  iface_len = max(map(len,addrs_list.keys()))
     945  addr_len = max(map(len,[x[0] for x in [x[0] for x in addrs_list.values()]]))
     946  for iface,addrs in sorted(addrs_list.iteritems()):
     947    if iface in ['lo0']:
     948      continue
     949    for addr, comment in sorted(addrs,key=lambda x: parseaddr(x[0].split('/')[0])):
     950      output += " - %s || %s || %s\n" % (iface.ljust(iface_len), addr.ljust(addr_len), comment)
     951
     952  output += '\n'
    933953  output += """\
    934954Attached bridges:
    935955"""
     956  has_item = False
    936957  for iface_key in datadump['autogen_iface_keys']:
    937958    ifacedump = datadump[iface_key]
    938959    if ifacedump.has_key('ns_ip'):
     960      has_item = True
    939961      output += " - %(autogen_ifname)s || %(mode)s || %(ns_ip)s\n" % ifacedump
     962  if not has_item:
     963    output += " - none\n"
    940964
    941965  return output
Note: See TracChangeset for help on using the changeset viewer.