Changeset 11515 in genesis


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

Almost able to generate new nodes with the tips of a few clicks. Aliases how-ever are a big PITA.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/node-editor

    r11513 r11515  
    1212import readline
    1313import sys
     14import pyproj
     15
     16
     17def latlon2rd(lon, lat):
     18  p1 = pyproj.Proj(proj='latlon',datum='WGS84')
     19  p2 = pyproj.Proj(init='EPSG:28992')
     20  RDx, RDy = pyproj.transform(p1,p2, lon, lat)
     21  return (int(RDx), int(RDy))
    1422
    1523
     
    1725
    1826DEBUG =  "-g" in sys.argv
     27
     28# Global variable, because this is dirty code.
     29datadump = None
    1930
    2031def rlprompt(prompt, prefill=''):
     
    4051  while True:
    4152    try:
    42       prefill = rlinput(prompt, prefill)
     53      prefill = rlinput(prompt, str(prefill))
    4354      return float(prefill)
    4455    except ValueError:
     
    7889  datadump['latitude'] =  rlinput_float("Latitude", datadump['latitude'])
    7990  datadump['longitude'] = rlinput_float("Longitude", datadump['longitude'])
     91  (datadump['rdnap_x'], datadump['rdnap_y']) = latlon2rd(datadump['longitude'], datadump['latitude'])
    8092  datadump['autogen_item'] =  datadump['nodetype'] + datadump['nodename']
    8193 
     
    8395  master_network = getrange.get_ranges(False, 24, 1)[0]
    8496  master_ip = getrange.showaddr(master_network + 1)
    85   datadump['master_ip'] = master_ip
    86 
    87   def new_access_point():
    88     ifname = rlinput("Interface name", "ath0")
    89     datadump['iface_' + ifname] = {
    90       'ip' : rlinput(" - IP", master_ip + "/26"),
    91       'dhcp' : rlinput(" - DHCP range", "10-60"),
    92       'ssid' : rlinput(" - SSID", "ap-WirelessLeiden-" + datadump['nodename']),
    93       'mode' : 'ap',
    94       'type' : '11b',
    95       'comment' : rlinput(" - Comment", "Omni voor de Buurt"),
    96       'sdesc': rlinput(" - Short Description", "2buurt"),
    97       'channel' : rlprompt(" - Channel", "10"),
    98       'status' : 'up',
    99     }
    100 
     97  datadump['masterip'] = master_ip
     98
     99  if os.path.exists(datadump['autogen_item']):
     100    print "Warning Node does already exists, overwriting!"
     101
     102
     103  # Secret global state variable
    101104  newNode.if_nr = 0
     105  def next_ifnr():
     106    if_nr = newNode.if_nr
     107    newNode.if_nr = newNode.if_nr + 1
     108    return if_nr
     109
     110  def new_access_point(link_type='wireless'):
     111    if link_type == 'wireless':
     112      ifname = rlinput("Interface name", "ath0")
     113      datadump['iface_' + ifname] = {
     114        'ip' : rlinput(" - IP", master_ip + "/26"),
     115        'dhcp' : rlinput(" - DHCP range", "10-60"),
     116        'ssid' : rlinput(" - SSID", "ap-WirelessLeiden-" + datadump['nodename']),
     117        'mode' : 'ap',
     118        'type' : '11b',
     119        'comment' : rlinput(" - Comment", "Omni voor de Buurt"),
     120        'sdesc': rlinput(" - Short Description", "2buurt"),
     121        'channel' : rlprompt(" - Channel", "10"),
     122        'status' : 'up',
     123      }
     124    elif link_type == 'wired':
     125      if_nr = next_ifnr()
     126      ifname = rlinput("Interface name", "vr%i" % if_nr)
     127      netmask = int(rlinput_float("Netmask", 24))
     128      print "Generating the Master IP range..."
     129      link_network = getrange.get_ranges(False, netmask, 1, use_history=True)[0]
     130      datadump['iface_' + ifname] = {
     131        'ip' : rlinput(" - IP", gformat.showaddr(link_network + 1) + "/" + str(netmask)),
     132        'dhcp' : rlinput(" - DHCP range", "10-60"),
     133        'ssid' : rlinput(" - SSID", "ap-WirelessLeiden-" + datadump['nodename'] + '-' + ifname),
     134        'comment' : rlinput(" - Comment", "Omni voor de Buurt"),
     135        'type' : 'eth',
     136        'sdesc': rlinput(" - Short Description", "2buurt"),
     137        'channel' : rlprompt(" - Channel", "10"),
     138        'status' : 'up',
     139        'mode': "ap",
     140        'bridge_type': rlinput(' - Bridge Type', 'NanoStation5M'),
     141        'ns_ip': rlinput(" - NS IP", getrange.showaddr(link_network + 2) + "/" + str(netmask)),
     142        'ns_mac': rlinput(" - NS MAC", "00:27:22:"),
     143      }
     144
    102145  def new_interlink(link_type='wireless', link_mode='station'):
    103     ifname = rlinput("Interface name", "vr%i" % newNode.if_nr)
    104     newNode.if_nr = newNode.if_nr + 1
     146    if_nr = next_ifnr()
     147    remote_datadump = None
     148    ifname = rlinput("Interface name", "vr%i" % if_nr)
    105149    netmask = 28
    106150    if link_mode == 'station':
     
    122166        else:
    123167          print ''
    124       iface = rlinput_choices("Remote interface", if_choices)
    125       ifdump = remote_datadump['iface_%s' % iface]
     168      remote_ifname = rlinput_choices("Remote interface", if_choices)
     169      remote_ifdump = remote_datadump['iface_%s' % remote_ifname]
    126170
    127171      #make_alias = rlprompt("Create Alias", "no") == "yes"
    128       link_network = gformat.network(ifdump['ip'])
     172      link_network = gformat.network(remote_ifdump['ip'])
    129173    elif link_mode == 'master':
    130       remote = rlinput("Interlink is planned for (remote host)", 'Unused%s' % newNode.if_nr)
     174      remote = rlinput("Interlink is planned for (remote host)", 'Unused%s' % if_nr)
    131175      print "Generating the Interlink IP range..."
    132       link_network = getrange.get_ranges(True, netmask, 1)[0]
     176      link_network = getrange.get_ranges(True, netmask, 1, use_history=True)[0]
    133177
    134178    print "Using Network %s/%s" % (gformat.showaddr(link_network), netmask)
     
    161205      elif link_mode == 'station':
    162206        datadump['iface_%s' % ifname].update({
    163           'ssid': rlinput(" - SSID", ifdump['ssid']),
     207          'ssid': rlinput(" - SSID", remote_ifdump['ssid']),
    164208          'ip': rlinput(" - IP", getrange.showaddr(link_network + 3) + "/" + str(netmask)),
    165209          'ns_ip': rlinput(" - NS IP", getrange.showaddr(link_network + 4) + "/" + str(netmask)),
    166210          'mode': "station-wds",
    167211        })
     212        remote_datadump['iface_' + remote_ifname]['comment'] = 'Link naar %s' % datadump['nodename']
     213        remote_datadump['iface_' + remote_ifname]['sdesc'] = '2%s' % datadump['nodename']
     214
    168215    elif link_type == 'wired':
    169216      if link_mode == 'master':
     
    175222          'ip': rlinput(" - IP", getrange.showaddr(link_network + 2) + "/" + str(netmask)),
    176223        })
     224        remote_datadump['iface_' + remote_ifname]['comment'] = 'Link naar %s' % datadump['nodename']
     225        remote_datadump['iface_' + remote_ifname]['sdesc'] = '2%s' % datadump['nodename']
     226
     227    if remote_datadump:
     228      # Alter remote side of interfaces
     229      gformat.store_yaml(remote_datadump)
     230   
    177231
    178232  def printMenu():
    179233    print '''\
    180234==========================================
    181  Create Interfaces
    182  
    183   1) New Accesspoint (ath0)
    184   2) New Wired Interlink (station)
    185   3) New Wired Interlink (master)
    186   4) New Wireless Interlink (station)
    187   5) New Wireless Interlink (master)
     235Create new Interface:
     236  === Public Access Points ===
     237  1) Accesspoint (ath0)
     238  2) Accesspoint with Bridge/Switch (vr0)
     239
     240  === Wireless Interlinks ===
     241  3) Wireless Bridge (master)
     242  4) Wireless Bridge (station)
     243
     244  === Multiple Nodes at location ===
     245  5) Ethernet Cross-connect (master)
     246  6) Ethernet Cross-connect (station)
     247
     248  === When finished adding links ===
    188249  9) Finish and Save
    189250==========================================
    190251  '''
    191252
    192   choice = 5
    193   while choice != 9:
     253  choice = ''
     254  while True:
    194255    printMenu()
    195256    choice = int(rlprompt("Choice", choice))
    196257    if choice == 1:
    197       new_access_point()
     258      new_access_point('wireless')
    198259    elif choice == 2:
    199       new_interlink('wired', 'station')
     260      new_access_point('wired')
    200261    elif choice == 3:
    201262      new_interlink('wired', 'master')
    202263    elif choice == 4:
    203       new_interlink('wireless', 'station')
     264      new_interlink('wired', 'station')
    204265    elif choice == 5:
    205266      new_interlink('wireless', 'master')
     267    elif choice == 6:
     268      new_interlink('wireless', 'station')
     269    elif choice == 9:
     270      break
    206271    else:
    207272      print "Invalid choice!"
     
    209274  # Output final result
    210275  print datadump
    211 
    212   #os.mkdir(datadump['autogen_item'])
    213   #gformat.store_yaml(datadump)
     276  if not os.path.exists(datadump['autogen_item']):
     277    os.mkdir(datadump['autogen_item'])
     278  gformat.store_yaml(datadump)
     279
     280  print "Please check changes and commit result"
    214281 
    215282
Note: See TracChangeset for help on using the changeset viewer.