Changeset 11513 in genesis for tools/node-editor
- Timestamp:
- Sep 30, 2012, 7:12:43 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/node-editor
r11510 r11513 20 20 def rlprompt(prompt, prefill=''): 21 21 ''' Get line with some boring default ''' 22 prompt = "%s [%s]: " % (prompt, prefill) 22 23 if DEBUG: 24 print prompt 23 25 return prefill 24 return raw_input( "%s%s: " % (prompt, ' [' + str(prefill) + ']' if prefill else '')) or prefill26 return raw_input(prompt) or prefill 25 27 26 28 def rlinput(prompt, prefill=''): 27 29 ''' Get line with some editable boring default ''' 28 30 if DEBUG: 31 print "%s [%s]:" % (prompt, prefill) 29 32 return prefill 30 33 readline.set_startup_hook(lambda: readline.insert_text(prefill)) … … 45 48 def rlinput_choices(prompt, choices, prefill=''): 46 49 if DEBUG: 50 print '%s [%s]:' % (prompt, prefill) 47 51 return prefill 48 52 while True: 49 filtered_choices = [x for x in choices if (str(prefill).lower() in str(x).lower())]53 filtered_choices = sorted(list(set([x for x in choices if (str(prefill).lower() in str(x).lower())]))) 50 54 if len(filtered_choices) == 1: 51 55 return filtered_choices[0] … … 81 85 datadump['master_ip'] = master_ip 82 86 83 if rlprompt("Add ath0 Accesspoint", "yes") == "yes":87 def new_access_point(): 84 88 ifname = rlinput("Interface name", "ath0") 85 89 datadump['iface_' + ifname] = { … … 95 99 } 96 100 97 if_nr = 0 98 while rlprompt("Add Interlink", "yes") == "yes": 99 ifname = rlinput("Interface name", "vr%i" % if_nr) 100 if_nr = if_nr + 1 101 remote = rlinput_choices("Create interlink", gformat.get_hostlist(),'HybridCeTIM2') 102 remote_datadump = gformat.get_yaml(remote) 103 print "Available remote interfaces:" 104 for ifkey in remote_datadump['autogen_iface_keys']: 105 ifdump = remote_datadump[ifkey] 106 print " - %4s" % ifdump['autogen_ifbase'], '- %30s' % ifdump['comment'], 107 if ifdump.has_key('ssid'): 108 print '-', ifdump['ssid'] 109 else: 110 print '' 111 iface = rlinput_choices("Interface Used", remote_datadump['autogen_iface_keys'], "vr1") 101 newNode.if_nr = 0 102 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 112 105 netmask = 28 113 print "Generating the Interlink IP range..." 114 link_network = getrange.get_ranges(True, netmask, 1)[0] 115 106 if link_mode == 'station': 107 remote = rlinput_choices("Create interlink with (remote host)", gformat.get_hostlist(),'Hybrid') 108 remote_datadump = gformat.get_yaml(remote) 109 print "Available remote interfaces:" 110 if_choices = [] 111 for ifkey in remote_datadump['autogen_iface_keys']: 112 ifdump = remote_datadump[ifkey] 113 # Could only do this if all meta information is correct 114 #if link_type == 'wireless' and link_mode == 'station': 115 # basedump = remote_datadump['iface_' + ifdump['autogen_ifbase']] 116 # if not basedump.has_key('mode') or basedump['mode'] != 'ap-wds': 117 # continue 118 if_choices.append(ifdump['autogen_ifbase']) 119 print " - %4s" % ifdump['autogen_ifbase'], '- %20s' % ifdump['ip'], '- %30s' % ifdump['comment'], 120 if ifdump.has_key('ssid'): 121 print '-', ifdump['ssid'] 122 else: 123 print '' 124 iface = rlinput_choices("Remote interface", if_choices) 125 ifdump = remote_datadump['iface_%s' % iface] 126 127 #make_alias = rlprompt("Create Alias", "no") == "yes" 128 link_network = gformat.network(ifdump['ip']) 129 elif link_mode == 'master': 130 remote = rlinput("Interlink is planned for (remote host)", 'Unused%s' % newNode.if_nr) 131 print "Generating the Interlink IP range..." 132 link_network = getrange.get_ranges(True, netmask, 1)[0] 133 134 print "Using Network %s/%s" % (gformat.showaddr(link_network), netmask) 135 136 # XXX: Create remote linking 137 # XXX: This does not handle IP pools 138 139 # Common part 116 140 datadump['iface_%s' % ifname] = { 117 141 'comment': rlinput(" - Comment", "Link naar " + remote), 118 142 'sdesc': rlinput(" - Short Description", "2" + remote), 119 'ssid': rlinput(" - SSID", 'il-X.wleiden.net'), 143 'type': "eth", 144 'status': 'up', 120 145 'dhcp': 'False', 121 'mode': "ap-wds",122 'ip': rlinput(" - IP", getrange.showaddr(link_network + 1) + "/" + str(netmask)),123 'type': "eth",124 'ns_ip': rlinput(" - NS IP", getrange.showaddr(link_network + 2) + "/" + str(netmask)),125 'ns_mac': rlinput(" - NS MAC", "00:27:22:"),126 'bridge_type': rlinput(' - Bridge Type', 'NanoStation5M'),127 'status': 'up',128 146 } 129 break 130 147 if link_type == 'wireless': 148 compass = rlprompt("Compass direction", 'n') 149 datadump['iface_%s' % ifname].update({ 150 'ns_mac': rlinput(" - NS MAC", "00:27:22:"), 151 'bridge_type': rlinput(' - Bridge Type', 'NanoStation5M'), 152 'compass': compass, 153 }) 154 if link_mode == 'master': 155 datadump['iface_%s' % ifname].update({ 156 'ssid': rlinput(" - SSID", 'il-%s.%s.wleiden.net' % (compass, datadump['nodename'])), 157 'ip': rlinput(" - IP", getrange.showaddr(link_network + 1) + "/" + str(netmask)), 158 'ns_ip': rlinput(" - NS IP", getrange.showaddr(link_network + 2) + "/" + str(netmask)), 159 'mode': "ap-wds", 160 }) 161 elif link_mode == 'station': 162 datadump['iface_%s' % ifname].update({ 163 'ssid': rlinput(" - SSID", ifdump['ssid']), 164 'ip': rlinput(" - IP", getrange.showaddr(link_network + 3) + "/" + str(netmask)), 165 'ns_ip': rlinput(" - NS IP", getrange.showaddr(link_network + 4) + "/" + str(netmask)), 166 'mode': "station-wds", 167 }) 168 elif link_type == 'wired': 169 if link_mode == 'master': 170 datadump['iface_%s' % ifname].update({ 171 'ip': rlinput(" - IP", getrange.showaddr(link_network + 1) + "/" + str(netmask)), 172 }) 173 elif link_mode == 'station': 174 datadump['iface_%s' % ifname].update({ 175 'ip': rlinput(" - IP", getrange.showaddr(link_network + 2) + "/" + str(netmask)), 176 }) 177 178 def printMenu(): 179 print '''\ 180 ========================================== 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) 188 9) Finish and Save 189 ========================================== 190 ''' 191 192 choice = 5 193 while choice != 9: 194 printMenu() 195 choice = int(rlprompt("Choice", choice)) 196 if choice == 1: 197 new_access_point() 198 elif choice == 2: 199 new_interlink('wired', 'station') 200 elif choice == 3: 201 new_interlink('wired', 'master') 202 elif choice == 4: 203 new_interlink('wireless', 'station') 204 elif choice == 5: 205 new_interlink('wireless', 'master') 206 else: 207 print "Invalid choice!" 208 209 # Output final result 131 210 print datadump 211 132 212 #os.mkdir(datadump['autogen_item']) 133 213 #gformat.store_yaml(datadump) … … 137 217 if __name__ == '__main__': 138 218 def printMenu(): 139 print '''Node File Editor by Rick van der Zwet 219 print '''\ 220 ========================================== 221 Node File Editor by Rick van der Zwet 140 222 141 223 1) New Node 142 224 9) Quit 225 ========================================== 143 226 ''' 144 227
Note:
See TracChangeset
for help on using the changeset viewer.