Changeset 6473
- Timestamp:
- Dec 21, 2008, 2:20:33 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/exodus/scripts/genesis_to_exodus.py
r6466 r6473 1 # 2 # Usage: django runscript genesis_to_exodus /path/to/nodes/py.conf 3 # 4 1 5 from exodus.forms import NodeForm, LocationForm, InterfaceForm 2 from exodus.models import Node, Location, Interface 6 from exodus.models import Node, Location, Interface, Antenna 3 7 import ConfigParser 4 8 from sys import argv … … 8 12 if len(locsearch): 9 13 locmodel = locsearch[0] 10 location = LocationForm(instance=locmodel)14 # XXX - should we update an existing location with new lat/lon data ? 11 15 else: 12 16 location = LocationForm({ 'description': location['descr'], 13 17 'latitude': location['lat'], 'longitude': location['lon'] }) 18 locmodel = location.save() 14 19 print 'Location ' + location['descr'] + 'created' 15 locmodel = location.save()16 20 if not location.is_valid(): 17 21 print location._errors … … 27 31 form = NodeForm(node) 28 32 if form.is_valid(): 33 nodemodel = form.save() 29 34 print 'Node '+node['name']+' created' 30 nodemodel = form.save()31 35 else: 32 36 print form._errors … … 46 50 else: 47 51 print 'Can\'t import interface '+interface['iface'] 48 print form._errors 52 print form._errors # XXX - outputs html but this is supposed to be a console script 49 53 return None 50 54 return intfmodel.id 51 55 56 def import_antenna(antenna): 57 antsearch = Antenna.objects.filter(type__exact=antenna['type'], gain__exact=antenna['gain']) 58 if len(antsearch): 59 return antsearch[0].id 60 else: 61 newantenna = Antenna(type=antenna['type'], gain=antenna['gain']) 62 newantenna.save() 63 return newantenna.id 52 64 53 65 def run(): … … 58 70 dataform ={'name' : 'Foo8', 'location' : '1', 'status' : 'up', 'network' : '1', 'masterip' : '127.0.0.1' } 59 71 72 networks = { } 60 73 config = ConfigParser.SafeConfigParser(dataform) 61 74 config.read(argv[len(argv)-1]) # last cmdline argument is supposed to be the config file to use … … 81 94 interfaces = config.get(s, 'interfaces') 82 95 for intf in interfaces.split(','): 83 cfgsection = node['name']+'/'+intf 84 if config.has_section(cfgsection): # check for an interface-specific block 85 # interface defaults 86 interface = { 'iface': intf, 'netmask': 24, 'ip': '127.0.0.1', 'mode': 'ms' } 96 if intf.find(':') == -1: # alias interface 97 cfgsection = node['name']+'/'+intf 98 if config.has_section(cfgsection): # check for an interface-specific block 99 # interface defaults 100 interface = { 'iface': intf, 'netmask': 24, 'ip': '127.0.0.1', 'mode': 'ms', 'polar': '', 'type': 'eth', 'accesspoint': False } 87 101 88 if config.has_option(cfgsection, 'ip'): 89 ip = config.get(cfgsection, 'ip') 90 if ip.find('/') >= 0: 91 interface['ip'] = ip.split('/')[0] 92 interface['netmask'] = ip.split('/')[1] 93 else: 94 interface['ip'] = ip 95 for key in [ 'type', 'desc', 'ssid', 'channel', 'mode']: 96 if (config.has_option(cfgsection, key)): 97 interface[key] = config.get(cfgsection, key) 98 if interface['mode'] == 'master': 99 interface['accesspoint'] = 1 100 interface['node'] = nodeid 101 import_interface(interface) 102 if config.has_option(cfgsection, 'ip'): 103 ip = config.get(cfgsection, 'ip') 104 if ip.find('/') >= 0: 105 interface['ip'] = ip.split('/')[0] 106 interface['netmask'] = ip.split('/')[1] 107 else: 108 interface['ip'] = ip 109 for key in [ 'type', 'desc', 'ssid', 'channel', 'mode', 'polar' ]: 110 if (config.has_option(cfgsection, key)): 111 interface[key] = config.get(cfgsection, key) 112 interface['node'] = nodeid 102 113 114 # handle Antenna 115 # XXX - disabled because it seems to me that genesis doesn't have complete info on equipped antennas 116 #if config.has_option(cfgsection, 'antenna') and config.has_option(cfgsection, 'gain'): 117 # antenna = config.get(cfgsection, 'antenna') 118 # gain = config.get(cfgsection, 'gain') 119 # if antenna and gain: # ensure we have both antenna type and gain otherwise model will complain 120 # interface['antenna'] = import_antenna({ 'type': antenna, 'gain': gain }) 121 122 # handle wifi links 123 if config.has_option(cfgsection, 'ssid'): 124 ssid = interface['ssid'] 125 if ssid not in networks: 126 networks[ssid] = { 'links': [] } 127 if interface['mode'] == 'ms': 128 interface['accesspoint'] = 1 129 networks[ssid]['master'] = import_interface(interface) 130 else: 131 networks[ssid]['links'].append(interface); 132 else: # XXX - should we handle links on not-wifi interfaces? 133 import_interface(interface) 134 135 # now we have already created all nodes and master interfaces... 136 # let's continue configuring all wifi links! 137 # XXX - Note we need to add links later to ensure having all 'master nodes' 138 # already configured and their interfaces (id) can be used to define the link. 139 # if done while processing the input file , it could happens to process managed 140 # interfaces sooner than their master ones and it's more convenient to just add 141 # links later (once we have already configured all master interfaces) instead of 142 # trying to update interfaces progressively 143 for ssid in networks: 144 for interface in networks[ssid]['links']: 145 if 'master' in networks[ssid]: 146 interface['link'] = networks[ssid]['master'] 147 import_interface(interface) 148 else: 149 print "No master defined for network " + ssid 103 150 pass
Note:
See TracChangeset
for help on using the changeset viewer.