Changeset 6424


Ignore:
Timestamp:
Dec 10, 2008, 11:24:33 AM (16 years ago)
Author:
roland
Message:

Import from exodus-roland.

Location:
trunk
Files:
7 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:mergeinfo set to
      /code/exodus/branches/exodus-roland6403-6423
  • trunk/Makefile

    r6357 r6424  
    3030        @sqlite3 $(SQLDB) < debug.sql
    3131
     32dbdebug:
     33#Put debug.sql in database
     34        @sqlite3 $(SQLDB) < debug.sql
     35
     36dbclean:
     37# remove the database
     38        @rm -r $(SQLDB)
     39
    3240clean:
    3341#Remove all created data, development ground, but keep downloaded files
  • trunk/exodus/admin.py

    r6332 r6424  
    11from django.contrib import admin
    22from django.contrib import databrowse
     3from django import forms
    34from exodus.models import *
     5from exodus.forms import NodeForm
     6from exodus.contrib import ReadOnlyAdminFields
    47
     8class PublicAPInline(admin.TabularInline):
     9    model = PublicAP
     10    extra = 1
     11
     12class InterfaceInline(admin.TabularInline):
     13    model = Interface
     14    extra = 2
     15    fieldsets = (
     16        (None, {
     17            'classes': ('collapse',),
     18            'fields': ('type', 'iface', 'polar', 'antenna', 'link')
     19        }),
     20    )
     21    #inlines = [ PublicAPInline, ]
     22
     23class NodeAdmin(ReadOnlyAdminFields, admin.ModelAdmin):
     24    readonly = ('masterip', )
     25    form = NodeForm
     26    list_display = ('name', 'location','network')
     27    search_fields = ['name']
     28    list_filter = ('network',)
     29    fieldsets = (
     30        (None, {
     31            'fields' : ('name', 'status', 'location', 'network', 'masterip')
     32        }),
     33    )
     34
     35    inlines = [InterfaceInline, ]
     36
     37class NodeInline(admin.TabularInline):
     38    model = Node
     39    extra = 2
     40
     41class LocationAdmin(admin.ModelAdmin):
     42    search_fields = ['description']
     43    inlines = [ NodeInline, ]
    544
    645admin.site.register(Antenna)
    7 admin.site.register(Location)
     46admin.site.register(Location, LocationAdmin)
    847admin.site.register(DnsServer)
    948admin.site.register(Network)
    10 admin.site.register(Node)
     49admin.site.register(Node, NodeAdmin)
    1150admin.site.register(Interface)
    1251admin.site.register(PublicAP)
     
    1453
    1554databrowse.site.register(Antenna)
    16 databrowse.site.register(Location)
     55databrowse.site.register(Location, LocationAdmin)
    1756databrowse.site.register(DnsServer)
    1857databrowse.site.register(Network)
  • trunk/exodus/models.py

    r6389 r6424  
    33from django.db import models
    44from django.contrib import admin
     5from django import forms
    56
    6 # Create your models here.
    77
    88#No need to formalize it; CHOICES don't change much
     
    1313                        ('pl', 'planned'),
    1414                        )
    15 
     15       
    1616POLAR_CHOICES = (
    1717                        ('hr', 'horizontal'),
     
    3030                        )
    3131
    32 class ExtendedModel(models.Model):
    33     class Meta:
    34         abstract = True
    35         verbose_name = 'ExtendedModel'
    36 
    37     def as_list(self):
    38         meta = self._meta
    39         values = [(f.verbose_name, getattr(self, f.attname))  \
    40                 for f in meta.local_fields if f.verbose_name not in ( 'ID')]
    41         return values
    42 
    43 class Antenna(ExtendedModel):
     32class Antenna(models.Model):
    4433    type = models.CharField(max_length=20, unique=True)
    4534    gain = models.IntegerField(max_length=3)
    4635
    47     def __str__(self):
     36    class Meta:
     37        verbose_name = 'Antenna'
     38
     39    def __unicode__(self):
    4840        return self.type
    4941
    50 class Location(ExtendedModel):
     42class Location(models.Model):
    5143    description = models.CharField(max_length=200, unique=True)
    5244    longitude = models.DecimalField(max_digits=8,decimal_places=6)
     
    5648        verbose_name = 'Location'
    5749
    58     def __str__(self):
     50    def __unicode__(self):
    5951        return self.description
    6052
    6153
    6254#XXX: Name Domain perhaps?
    63 class DnsServer(ExtendedModel):
     55class DnsServer(models.Model):
    6456    ipaddress = models.IPAddressField()
    6557    domainname = models.CharField(max_length=50, unique=True)
     
    6860        verbose_name = 'Dns Server'
    6961   
    70     def __str__(self):
     62    def __unicode__(self):
    7163        return "%s, %s"% (self.domainname, self.ipaddress )
    7264
    73 
    74 class Network(ExtendedModel):
     65class Network(models.Model):
    7566        name = models.CharField(max_length=50, unique=True)
    7667        ipspacestart = models.IPAddressField()
     
    8071        verbose_name = 'Network'
    8172
    82         def __str__(self):
     73        def __unicode__(self):
    8374                return self.name
    8475
    85 
    86 class Node(ExtendedModel):
     76class Node(models.Model):
    8777    name = models.CharField(max_length=30, unique=True)
    8878    location = models.ForeignKey(Location)
    89     status = models.CharField(max_length=10, choices=STATUS_CHOICES, default=1)
     79    status = models.CharField(max_length=10, choices=STATUS_CHOICES , \
     80        default='up')
     81    network = models.ForeignKey(Network,default=1)
    9082    masterip = models.IPAddressField(unique=True)
    91     network = models.ForeignKey(Network,default=1)
    9283 
    9384    class Meta:
     
    9586        verbose_name = 'Node'
    9687
    97     def __str__(self):
     88    def __unicode__(self):
    9889        return self.name
    9990
    100 class Interface(ExtendedModel):
     91   # def save(self, force_insert=False, force_update=False):
     92   #     #XXX: could there be racing conditions?
     93   #     #XXX: Maybe move this to a model form,
     94   #     from wllogic import free_masterip
     95   #     # check if there is a masterip, if not generate one.
     96   #     # check if there is a network change, if so, generate a new masterip.
     97   #     if self.masterip:
     98   #         old = Node.objects.get(pk=self.pk)
     99   #         if old.network != self.network:
     100   #             self.masterip = free_masterip(self.network)
     101   #     else:
     102   #         self.masterip = free_masterip(self.network)
     103   #     super(Node, self).save(force_insert, force_update)
     104
     105class Interface(models.Model):
    101106        node = models.ForeignKey(Node)
    102107        type = models.CharField(max_length=10, choices=INTERFACE_TYPE_CHOICES, \
    103             default=1)
     108            default='eth')
    104109        iface = models.CharField(max_length=10, verbose_name="interface", \
    105110            default='eth0')
    106         ip = models.IPAddressField(unique=True)
     111        ip = models.IPAddressField(unique=True, blank=True)
    107112        netmask = models.IntegerField(default=30)
    108113        polar = models.CharField(blank=True, max_length=10, choices=POLAR_CHOICES)
    109114        ssid = models.CharField(max_length=30, blank=True, null=True)
    110         mode = models.CharField(max_length=10, choices=WIFI_MODE_CHOICES)
     115        mode = models.CharField(max_length=10, choices=WIFI_MODE_CHOICES, blank=True)
    111116        channel = models.IntegerField(blank=True, null=True)
    112117        antenna = models.ForeignKey(Antenna, blank=True, null=True)
     
    116121       
    117122        class Meta:
    118                 unique_together = ('node', 'iface')
     123                #unique_together = ('node', 'iface')
    119124                verbose_name = 'Interface'
    120125       
    121         def __str__(self):
     126        def __unicode__(self):
    122127                return "%s/%s" % (self.node, self.iface)
    123128
    124 class InterfaceAlias(ExtendedModel):
     129class InterfaceAlias(models.Model):
    125130        iface = models.ForeignKey(Interface,related_name='child')
    126131        ip = models.IPAddressField(unique=True)
     
    131136        link = models.ForeignKey(Interface, blank=True, null=True)
    132137       
    133         def __str__(self):
     138        def __unicode__(self):
    134139                return "Alias %s" % (self.iface)
    135140
     
    139144# be defined, all other could be calculated on the fly if needed
    140145
    141 class PublicAP(ExtendedModel):
     146class PublicAP(models.Model):
    142147    iface = models.ForeignKey(Interface,related_name='ap', verbose_name="interface")
    143148    ip = models.IPAddressField(unique=True)
     
    151156        verbose_name = "Public Access Point"
    152157
    153     def __str__(self):
     158    def __unicode__(self):
    154159        return "%s:%s" % (self.iface,self.pk)
    155160
    156 class DhcpStatic(ExtendedModel):
     161class DhcpStatic(models.Model):
    157162    hostname = models.CharField(max_length=10,unique=True)
    158163    macaddress = models.CharField(max_length=17)
     
    163168        verbose_name = "Static host"
    164169
    165     def __str__(self):
     170    def __unicode__(self):
    166171        return self.hostname
  • trunk/exodus/tests.py

    r6371 r6424  
    180180        from wllogic import addInterlinkIP
    181181        self.fail('Test not implemented')
    182    
     182
     183class Link(unittest.TestCase):
     184    def setUp(self):
     185        class link(object):
     186            def __init__(self, type, node):
     187                self.type = type
     188                self.node = node
     189
     190        self.link00 = link('eth', 1)
     191        self.link01 = link('eth', 2)
     192        self.link10 = link('11a', 1)
     193        self.link11 = link('11a', 2)
     194        self.link20 = link('11b', 1)
     195        self.link21 = link('11b', 2)
     196        self.link30 = link('11g', 1)           
     197        self.link31 = link('11g', 2)
     198
     199    def test_link_has_compat_type(self):
     200        from wllogic import link_has_compat_type
     201       
     202        # test link to self
     203        self.failUnless(link_has_compat_type(self.link00, self.link00))
     204        # test eth
     205        self.failUnless(link_has_compat_type(self.link00, self.link01))
     206        # test 11a
     207        self.failUnless(link_has_compat_type(self.link10, self.link11))
     208        # test 11b
     209        self.failUnless(link_has_compat_type(self.link20, self.link21))
     210        # test 11g
     211        self.failUnless(link_has_compat_type(self.link30, self.link31))
     212        # test 11b vs 11g
     213        self.failUnless(link_has_compat_type(self.link20, self.link30))
     214        self.failUnless(link_has_compat_type(self.link30, self.link20))
     215
     216        # test fail eth vs 11a
     217        self.failIf(link_has_compat_type(self.link00, self.link10))
     218        # test fail eth vs 11b
     219        self.failIf(link_has_compat_type(self.link00, self.link20))
     220        # test fail eth vs 11g
     221        self.failIf(link_has_compat_type(self.link00, self.link30))
     222        # test fail 11a vs 11b
     223        self.failIf(link_has_compat_type(self.link10, self.link20))
     224        # test fail 11a vs 11g
     225        self.failIf(link_has_compat_type(self.link10, self.link30))
     226   
     227    def test_link_not_same_node(self):
     228        from wllogic import link_is_not_to_itself
     229        self.failUnless(link_is_not_to_itself(self.link00, self.link01))
     230        self.failIf(link_is_not_to_itself(self.link20, self.link30))
     231   
     232    def test_link_is_wireless(self):
     233        from wllogic import link_is_wireless
     234        self.failIf(link_is_wireless(self.link00))
     235        self.failUnless(link_is_wireless(self.link10))
     236        self.failUnless(link_is_wireless(self.link20))
     237        self.failUnless(link_is_wireless(self.link30))
     238               
    183239def suite():
    184240    s = unittest.TestSuite()
    185241    s.addTest(unittest.makeSuite(AddTest))
    186242    s.addTest(unittest.makeSuite(wllogic))
     243    s.addTest(unittest.makeSuite(Link))
    187244
    188245    return s
  • trunk/exodus/urls.py

    r6357 r6424  
    99from django.contrib import admin
    1010admin.autodiscover()
    11 
    12 #
    13 # experimental databrowse code
    1411
    1512urlpatterns = patterns('',
  • trunk/exodus/wllogic.py

    r6373 r6424  
    144144       
    145145        return show_addr(i)
     146
     147def link_is_valid(link1, link2):
     148        if not link_has_compat_type(link1, link2):
     149                return False
     150
     151def link_is_wireless(link1):
     152        wireless = ('11a', '11b', '11g')
     153        if link1.type in wireless:
     154                return True
     155
     156def link_has_compat_type(link1, link2):
     157        # if this is a link to self, the link is always valid
     158        if link1 == link2:
     159                return True
     160        # link types must the same
     161        if link1.type == link2.type:
     162                return True
     163        # or link types must be compatible
     164        compat = ('11b', '11g')
     165        if link1.type in compat and link2.type in compat:
     166                return True
     167
     168def link_is_not_to_itself(link1, link2):
     169        # check if a link is not going itself
     170        if link1.node != link2.node:
     171                return True
     172
  • trunk/initial_data.json

    • Property svn:mergeinfo set to
Note: See TracChangeset for help on using the changeset viewer.