Changeset 6424
- Timestamp:
- Dec 10, 2008, 11:24:33 AM (16 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to
/code/exodus/branches/exodus-roland 6403-6423
-
Property svn:mergeinfo
set to
-
trunk/Makefile
r6357 r6424 30 30 @sqlite3 $(SQLDB) < debug.sql 31 31 32 dbdebug: 33 #Put debug.sql in database 34 @sqlite3 $(SQLDB) < debug.sql 35 36 dbclean: 37 # remove the database 38 @rm -r $(SQLDB) 39 32 40 clean: 33 41 #Remove all created data, development ground, but keep downloaded files -
trunk/exodus/admin.py
r6332 r6424 1 1 from django.contrib import admin 2 2 from django.contrib import databrowse 3 from django import forms 3 4 from exodus.models import * 5 from exodus.forms import NodeForm 6 from exodus.contrib import ReadOnlyAdminFields 4 7 8 class PublicAPInline(admin.TabularInline): 9 model = PublicAP 10 extra = 1 11 12 class 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 23 class 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 37 class NodeInline(admin.TabularInline): 38 model = Node 39 extra = 2 40 41 class LocationAdmin(admin.ModelAdmin): 42 search_fields = ['description'] 43 inlines = [ NodeInline, ] 5 44 6 45 admin.site.register(Antenna) 7 admin.site.register(Location )46 admin.site.register(Location, LocationAdmin) 8 47 admin.site.register(DnsServer) 9 48 admin.site.register(Network) 10 admin.site.register(Node )49 admin.site.register(Node, NodeAdmin) 11 50 admin.site.register(Interface) 12 51 admin.site.register(PublicAP) … … 14 53 15 54 databrowse.site.register(Antenna) 16 databrowse.site.register(Location )55 databrowse.site.register(Location, LocationAdmin) 17 56 databrowse.site.register(DnsServer) 18 57 databrowse.site.register(Network) -
trunk/exodus/models.py
r6389 r6424 3 3 from django.db import models 4 4 from django.contrib import admin 5 from django import forms 5 6 6 # Create your models here.7 7 8 8 #No need to formalize it; CHOICES don't change much … … 13 13 ('pl', 'planned'), 14 14 ) 15 15 16 16 POLAR_CHOICES = ( 17 17 ('hr', 'horizontal'), … … 30 30 ) 31 31 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): 32 class Antenna(models.Model): 44 33 type = models.CharField(max_length=20, unique=True) 45 34 gain = models.IntegerField(max_length=3) 46 35 47 def __str__(self): 36 class Meta: 37 verbose_name = 'Antenna' 38 39 def __unicode__(self): 48 40 return self.type 49 41 50 class Location( ExtendedModel):42 class Location(models.Model): 51 43 description = models.CharField(max_length=200, unique=True) 52 44 longitude = models.DecimalField(max_digits=8,decimal_places=6) … … 56 48 verbose_name = 'Location' 57 49 58 def __ str__(self):50 def __unicode__(self): 59 51 return self.description 60 52 61 53 62 54 #XXX: Name Domain perhaps? 63 class DnsServer( ExtendedModel):55 class DnsServer(models.Model): 64 56 ipaddress = models.IPAddressField() 65 57 domainname = models.CharField(max_length=50, unique=True) … … 68 60 verbose_name = 'Dns Server' 69 61 70 def __ str__(self):62 def __unicode__(self): 71 63 return "%s, %s"% (self.domainname, self.ipaddress ) 72 64 73 74 class Network(ExtendedModel): 65 class Network(models.Model): 75 66 name = models.CharField(max_length=50, unique=True) 76 67 ipspacestart = models.IPAddressField() … … 80 71 verbose_name = 'Network' 81 72 82 def __ str__(self):73 def __unicode__(self): 83 74 return self.name 84 75 85 86 class Node(ExtendedModel): 76 class Node(models.Model): 87 77 name = models.CharField(max_length=30, unique=True) 88 78 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) 90 82 masterip = models.IPAddressField(unique=True) 91 network = models.ForeignKey(Network,default=1)92 83 93 84 class Meta: … … 95 86 verbose_name = 'Node' 96 87 97 def __ str__(self):88 def __unicode__(self): 98 89 return self.name 99 90 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 105 class Interface(models.Model): 101 106 node = models.ForeignKey(Node) 102 107 type = models.CharField(max_length=10, choices=INTERFACE_TYPE_CHOICES, \ 103 default= 1)108 default='eth') 104 109 iface = models.CharField(max_length=10, verbose_name="interface", \ 105 110 default='eth0') 106 ip = models.IPAddressField(unique=True )111 ip = models.IPAddressField(unique=True, blank=True) 107 112 netmask = models.IntegerField(default=30) 108 113 polar = models.CharField(blank=True, max_length=10, choices=POLAR_CHOICES) 109 114 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) 111 116 channel = models.IntegerField(blank=True, null=True) 112 117 antenna = models.ForeignKey(Antenna, blank=True, null=True) … … 116 121 117 122 class Meta: 118 unique_together = ('node', 'iface')123 #unique_together = ('node', 'iface') 119 124 verbose_name = 'Interface' 120 125 121 def __ str__(self):126 def __unicode__(self): 122 127 return "%s/%s" % (self.node, self.iface) 123 128 124 class InterfaceAlias( ExtendedModel):129 class InterfaceAlias(models.Model): 125 130 iface = models.ForeignKey(Interface,related_name='child') 126 131 ip = models.IPAddressField(unique=True) … … 131 136 link = models.ForeignKey(Interface, blank=True, null=True) 132 137 133 def __ str__(self):138 def __unicode__(self): 134 139 return "Alias %s" % (self.iface) 135 140 … … 139 144 # be defined, all other could be calculated on the fly if needed 140 145 141 class PublicAP( ExtendedModel):146 class PublicAP(models.Model): 142 147 iface = models.ForeignKey(Interface,related_name='ap', verbose_name="interface") 143 148 ip = models.IPAddressField(unique=True) … … 151 156 verbose_name = "Public Access Point" 152 157 153 def __ str__(self):158 def __unicode__(self): 154 159 return "%s:%s" % (self.iface,self.pk) 155 160 156 class DhcpStatic( ExtendedModel):161 class DhcpStatic(models.Model): 157 162 hostname = models.CharField(max_length=10,unique=True) 158 163 macaddress = models.CharField(max_length=17) … … 163 168 verbose_name = "Static host" 164 169 165 def __ str__(self):170 def __unicode__(self): 166 171 return self.hostname -
trunk/exodus/tests.py
r6371 r6424 180 180 from wllogic import addInterlinkIP 181 181 self.fail('Test not implemented') 182 182 183 class 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 183 239 def suite(): 184 240 s = unittest.TestSuite() 185 241 s.addTest(unittest.makeSuite(AddTest)) 186 242 s.addTest(unittest.makeSuite(wllogic)) 243 s.addTest(unittest.makeSuite(Link)) 187 244 188 245 return s -
trunk/exodus/urls.py
r6357 r6424 9 9 from django.contrib import admin 10 10 admin.autodiscover() 11 12 #13 # experimental databrowse code14 11 15 12 urlpatterns = patterns('', -
trunk/exodus/wllogic.py
r6373 r6424 144 144 145 145 return show_addr(i) 146 147 def link_is_valid(link1, link2): 148 if not link_has_compat_type(link1, link2): 149 return False 150 151 def link_is_wireless(link1): 152 wireless = ('11a', '11b', '11g') 153 if link1.type in wireless: 154 return True 155 156 def 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 168 def 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
-
Property svn:mergeinfo
set to
Note:
See TracChangeset
for help on using the changeset viewer.