Changeset 6601 for trunk


Ignore:
Timestamp:
Jan 13, 2009, 9:50:17 PM (16 years ago)
Author:
roland
Message:

Script imports just one antenna type, namely exodus import with 0 gain.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/exodus/scripts/genesis_to_exodus.py

    r6565 r6601  
    6969    return intfmodel.id
    7070
    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].id
    76     else:
    77         newantenna = Antenna(type=antenna['type'], gain=antenna['gain'])
    78         newantenna.save()
    79         return newantenna.id
    80 
    8171def run():
    8272    """Import script for genesis data."""
     
    8878    dataform ={'name' : 'Foo8', 'location' : '1', 'status' : 'up', 
    8979            '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)
    9082    networks = {}
    9183    ethernet = []
    9284    conn = sqlite3.connect(':memory:')
    9385    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))')
    9588    config = ConfigParser.SafeConfigParser(dataform)
    9689    # last cmdline argument is supposed to be the config file to use
     
    154147                                    config.has_option(cfgsection, 'mode') and \
    155148                                    config.get(cfgsection, 'mode') == 'ms':
    156                                 interface['direction'] = config.get(cfgsection, 'compass-direction')
     149                                interface['direction'] = config.get(
     150                                        cfgsection, 'compass-direction')
    157151                            else:
    158152                                interface['direction'] = ''
     
    160154                            if config.has_option(cfgsection, 'extra_type'):                                     interface['ethernet_to_wifi'] = 1
    161155
    162                             # XXX: The genesis data is complete, the type of
    163                             #      antenna needs to be passed on.
    164                             #      it's probably better to define the types
    165                             #      beforehand.
    166 
    167156                            # 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
    174166
    175167                            # handle wifi links
     
    182174                                    networks[ssid] = { 'links': [] }
    183175                                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)
    188178                                else:
    189179                                    networks[ssid]['links'].append(interface)
    190180                            else:
    191                                 # XXX - should we handle links on not-wifi
    192                                 # interfaces?
    193                                 # XXX: yes we should
     181                                #just import ethernet interfaces
    194182                                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               
    222207    # now we have already created all nodes and master interfaces...
    223208    # 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
    234220    for ssid in networks:
    235221        for interface in networks[ssid]['links']:
     
    239225            else:
    240226                print "No master defined for network " + ssid
    241     pass
Note: See TracChangeset for help on using the changeset viewer.