- Timestamp:
- Jan 13, 2009, 9:50:17 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/exodus/scripts/genesis_to_exodus.py
r6565 r6601 69 69 return intfmodel.id 70 70 71 def import_antenna(antenna):72 antsearch = Antenna.objects.filter(type__exact=antenna['type'],73 gain__exact=antenna['gain'])74 if len(antsearch):75 return antsearch[0].id76 else:77 newantenna = Antenna(type=antenna['type'], gain=antenna['gain'])78 newantenna.save()79 return newantenna.id80 81 71 def run(): 82 72 """Import script for genesis data.""" … … 88 78 dataform ={'name' : 'Foo8', 'location' : '1', 'status' : 'up', 89 79 'network' : '1', 'masterip' : '127.0.0.1' } 80 # define a special antenna type for genesis to exodus import 81 newantenna = Antenna.objects.create(type='exodus import', gain=0) 90 82 networks = {} 91 83 ethernet = [] 92 84 conn = sqlite3.connect(':memory:') 93 85 cursor = conn.cursor() 94 cursor.execute('CREATE TABLE ifaceip (id INTEGER PRIMARY KEY, iface VARCHAR(20), ip VARCHAR(20))') 86 cursor.execute('CREATE TABLE ifaceip (id INTEGER PRIMARY KEY, ' 87 'iface VARCHAR(20), ip VARCHAR(20))') 95 88 config = ConfigParser.SafeConfigParser(dataform) 96 89 # last cmdline argument is supposed to be the config file to use … … 154 147 config.has_option(cfgsection, 'mode') and \ 155 148 config.get(cfgsection, 'mode') == 'ms': 156 interface['direction'] = config.get(cfgsection, 'compass-direction') 149 interface['direction'] = config.get( 150 cfgsection, 'compass-direction') 157 151 else: 158 152 interface['direction'] = '' … … 160 154 if config.has_option(cfgsection, 'extra_type'): interface['ethernet_to_wifi'] = 1 161 155 162 # XXX: The genesis data is complete, the type of163 # antenna needs to be passed on.164 # it's probably better to define the types165 # beforehand.166 167 156 # handle Antenna 168 # XXX - disabled because it seems to me that genesis doesn't have complete info on equipped antennas 169 #if config.has_option(cfgsection, 'antenna') and config.has_option(cfgsection, 'gain'): 170 # antenna = config.get(cfgsection, 'antenna') 171 # gain = config.get(cfgsection, 'gain') 172 # if antenna and gain: # ensure we have both antenna type and gain otherwise model will complain 173 # interface['antenna'] = import_antenna({ 'type': antenna, 'gain': gain }) 157 if config.has_option(cfgsection, 'antenna') and \ 158 config.has_option(cfgsection, 'gain'): 159 antenna = config.get(cfgsection, 'antenna') 160 gain = config.get(cfgsection, 'gain') 161 # ensure we have both antenna type and gain 162 # otherwise model will complain 163 164 if antenna and gain: 165 interface['antenna'] = newantenna.id 174 166 175 167 # handle wifi links … … 182 174 networks[ssid] = { 'links': [] } 183 175 if interface['mode'] == 'ms': 184 #XXX: if dhcp != 'no' accesspoint = 1 185 # fixed this above. 186 #interface['accesspoint'] = 1 187 networks[ssid]['master'] = import_interface(interface) 176 networks[ssid]['master'] = \ 177 import_interface(interface) 188 178 else: 189 179 networks[ssid]['links'].append(interface) 190 180 else: 191 # XXX - should we handle links on not-wifi 192 # interfaces? 193 # XXX: yes we should 181 #just import ethernet interfaces 194 182 import_interface(interface) 195 pass 196 # 197 # #ethernet stuff 198 # for intf in interfaces.split(','): 199 # cfgsection = node['name']+'/'+intf 200 # # build a list of all ethernet interfaces 201 # if config.has_section(cfgsection) and \ 202 # config.get(cfgsection, 'type') == 'eth' and \ 203 # config.has_option(cfgsection, 'ip'): 204 # ethernet.append(cfgsection) 205 # cursor.execute('insert INTO ifaceip VALUES ' 206 # '(null, ?, ?)', ( cfgsection, 207 # config.get(cfgsection, 'ip').rsplit('/')[0])) 208 # 209 # conn.commit() 210 # 211 # non_alias = (i for i in ethernet if not ":" in i) 212 # for i in non_alias: 213 # for j in [ k for k in ethernet if k.startswith(i)]: 214 # if config.has_section(j) and \ 215 # config.has_option(j, 'point_to_point'): 216 # p2p = config.get(j, 'point_to_point') 217 # cursor.execute('SELECT iface FROM ifaceip where ip = ?', (p2p,)) 218 # print "%s has link to %s" %( j, cursor.fetchall()) 219 # 220 221 183 184 #ethernet stuff 185 for intf in interfaces.split(','): 186 cfgsection = node['name']+'/'+intf 187 # build a list of all ethernet interfaces 188 if config.has_section(cfgsection) and \ 189 config.get(cfgsection, 'type') == 'eth' and \ 190 config.has_option(cfgsection, 'ip'): 191 ethernet.append(cfgsection) 192 cursor.execute('insert INTO ifaceip VALUES ' 193 '(null, ?, ?)', ( cfgsection, 194 config.get(cfgsection, 'ip').rsplit('/')[0])) 195 196 conn.commit() 197 198 non_alias = (i for i in ethernet if not ":" in i) 199 for i in non_alias: 200 for j in [ k for k in ethernet if k.startswith(i)]: 201 if config.has_section(j) and \ 202 config.has_option(j, 'point_to_point'): 203 p2p = config.get(j, 'point_to_point') 204 cursor.execute('SELECT iface FROM ifaceip where ip = ?', (p2p,)) 205 print "%s has link to %s" %( j, cursor.fetchall()) 206 222 207 # now we have already created all nodes and master interfaces... 223 208 # let's continue configuring all wifi links! 224 # XXX - Note we need to add links later to ensure having all 'master nodes' 225 # already configured and their interfaces (id) can be used to define the link. 226 # if done while processing the input file , it could happens to process managed 227 # interfaces sooner than their master ones and it's more convenient to just add 228 # links later (once we have already configured all master interfaces) instead of 229 # trying to update interfaces progressively 230 231 # XXX: my initial thought was that you defined the ssid here, but 232 # you use it to determine who is the master and this seems to work 233 # well. 209 # Note we need to add links later to ensure having all 'master nodes' 210 # already configured and their interfaces (id) can be used to define 211 # the link. 212 # if done while processing the input file , 213 # it could happens to process managed 214 # interfaces sooner than their master ones and it's 215 # more convenient to just add 216 # links later (once we have already configured 217 # all master interfaces) instead of 218 # trying to update interfaces progressively 219 234 220 for ssid in networks: 235 221 for interface in networks[ssid]['links']: … … 239 225 else: 240 226 print "No master defined for network " + ssid 241 pass
Note:
See TracChangeset
for help on using the changeset viewer.