Changeset 11515 in genesis
- Timestamp:
- Sep 30, 2012, 8:41:50 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/node-editor
r11513 r11515 12 12 import readline 13 13 import sys 14 import pyproj 15 16 17 def 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)) 14 22 15 23 … … 17 25 18 26 DEBUG = "-g" in sys.argv 27 28 # Global variable, because this is dirty code. 29 datadump = None 19 30 20 31 def rlprompt(prompt, prefill=''): … … 40 51 while True: 41 52 try: 42 prefill = rlinput(prompt, prefill)53 prefill = rlinput(prompt, str(prefill)) 43 54 return float(prefill) 44 55 except ValueError: … … 78 89 datadump['latitude'] = rlinput_float("Latitude", datadump['latitude']) 79 90 datadump['longitude'] = rlinput_float("Longitude", datadump['longitude']) 91 (datadump['rdnap_x'], datadump['rdnap_y']) = latlon2rd(datadump['longitude'], datadump['latitude']) 80 92 datadump['autogen_item'] = datadump['nodetype'] + datadump['nodename'] 81 93 … … 83 95 master_network = getrange.get_ranges(False, 24, 1)[0] 84 96 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 101 104 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 102 145 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) 105 149 netmask = 28 106 150 if link_mode == 'station': … … 122 166 else: 123 167 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] 126 170 127 171 #make_alias = rlprompt("Create Alias", "no") == "yes" 128 link_network = gformat.network( ifdump['ip'])172 link_network = gformat.network(remote_ifdump['ip']) 129 173 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) 131 175 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] 133 177 134 178 print "Using Network %s/%s" % (gformat.showaddr(link_network), netmask) … … 161 205 elif link_mode == 'station': 162 206 datadump['iface_%s' % ifname].update({ 163 'ssid': rlinput(" - SSID", ifdump['ssid']),207 'ssid': rlinput(" - SSID", remote_ifdump['ssid']), 164 208 'ip': rlinput(" - IP", getrange.showaddr(link_network + 3) + "/" + str(netmask)), 165 209 'ns_ip': rlinput(" - NS IP", getrange.showaddr(link_network + 4) + "/" + str(netmask)), 166 210 'mode': "station-wds", 167 211 }) 212 remote_datadump['iface_' + remote_ifname]['comment'] = 'Link naar %s' % datadump['nodename'] 213 remote_datadump['iface_' + remote_ifname]['sdesc'] = '2%s' % datadump['nodename'] 214 168 215 elif link_type == 'wired': 169 216 if link_mode == 'master': … … 175 222 'ip': rlinput(" - IP", getrange.showaddr(link_network + 2) + "/" + str(netmask)), 176 223 }) 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 177 231 178 232 def printMenu(): 179 233 print '''\ 180 234 ========================================== 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) 235 Create 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 === 188 249 9) Finish and Save 189 250 ========================================== 190 251 ''' 191 252 192 choice = 5193 while choice != 9:253 choice = '' 254 while True: 194 255 printMenu() 195 256 choice = int(rlprompt("Choice", choice)) 196 257 if choice == 1: 197 new_access_point( )258 new_access_point('wireless') 198 259 elif choice == 2: 199 new_ interlink('wired', 'station')260 new_access_point('wired') 200 261 elif choice == 3: 201 262 new_interlink('wired', 'master') 202 263 elif choice == 4: 203 new_interlink('wire less', 'station')264 new_interlink('wired', 'station') 204 265 elif choice == 5: 205 266 new_interlink('wireless', 'master') 267 elif choice == 6: 268 new_interlink('wireless', 'station') 269 elif choice == 9: 270 break 206 271 else: 207 272 print "Invalid choice!" … … 209 274 # Output final result 210 275 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" 214 281 215 282
Note:
See TracChangeset
for help on using the changeset viewer.