- Timestamp:
- Dec 8, 2008, 4:57:03 PM (16 years ago)
- Location:
- branches/exodus-roland/exodus
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/exodus-roland/exodus/admin.py
r6411 r6420 29 29 fieldsets = ( 30 30 (None, { 31 'fields' : ( ('name', 'status'), 'location', 'network', 'masterip')31 'fields' : ('name', 'status', 'location', 'network', 'masterip') 32 32 }), 33 33 ) 34 inlines = [InterfaceInline, ] 34 35 #inlines = [InterfaceInline, ] 35 36 36 37 class NodeInline(admin.TabularInline): -
branches/exodus-roland/exodus/forms.py
r6404 r6420 5 5 6 6 class NodeForm(forms.ModelForm): 7 masterip = forms.IPAddressField()8 7 class Meta: 9 8 model = Node 10 #def clean(self):11 # self.data['masterip'] = \12 # self.cleaned_data['masterip'] = \13 # free_masterip(self.cleaned_data['network'])14 # return super(NodeForm, self).clean()15 -
branches/exodus-roland/exodus/models.py
r6411 r6420 37 37 verbose_name = 'Antenna' 38 38 39 def __ str__(self):39 def __unicode__(self): 40 40 return self.type 41 41 … … 48 48 verbose_name = 'Location' 49 49 50 def __ str__(self):50 def __unicode__(self): 51 51 return self.description 52 52 … … 60 60 verbose_name = 'Dns Server' 61 61 62 def __ str__(self):62 def __unicode__(self): 63 63 return "%s, %s"% (self.domainname, self.ipaddress ) 64 65 64 66 65 class Network(models.Model): … … 72 71 verbose_name = 'Network' 73 72 74 def __ str__(self):73 def __unicode__(self): 75 74 return self.name 76 75 … … 87 86 verbose_name = 'Node' 88 87 89 def __ str__(self):88 def __unicode__(self): 90 89 return self.name 91 90 91 def save(self, force_insert=False, force_update=False): 92 #XXX: Maybe move this to a model form, 93 from wllogic import free_masterip 94 # check if there is a masterip, if not generate one. 95 # check if there is a network change, if so, generate a new masterip. 96 if self.masterip: 97 old = Node.objects.get(pk=self.pk) 98 if old.network != self.network: 99 self.masterip = free_masterip(self.network) 100 else: 101 self.masterip = free_masterip(self.network) 102 super(Node, self).save(force_insert, force_update) 92 103 93 104 class Interface(models.Model): … … 112 123 verbose_name = 'Interface' 113 124 114 def __ str__(self):125 def __unicode__(self): 115 126 return "%s/%s" % (self.node, self.iface) 116 127 … … 124 135 link = models.ForeignKey(Interface, blank=True, null=True) 125 136 126 def __ str__(self):137 def __unicode__(self): 127 138 return "Alias %s" % (self.iface) 128 139 … … 144 155 verbose_name = "Public Access Point" 145 156 146 def __ str__(self):157 def __unicode__(self): 147 158 return "%s:%s" % (self.iface,self.pk) 148 159 … … 156 167 verbose_name = "Static host" 157 168 158 def __ str__(self):169 def __unicode__(self): 159 170 return self.hostname -
branches/exodus-roland/exodus/tests.py
r6411 r6420 181 181 self.fail('Test not implemented') 182 182 183 class Manager(unittest.TestCase): 184 def test_interface_manager(self): 185 class link(object): 186 def __init__(self, type): 187 self.type = type 188 from exodus.manager import InterfaceManager 189 11a_link = 190 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 191 239 def suite(): 192 240 s = unittest.TestSuite() 193 241 s.addTest(unittest.makeSuite(AddTest)) 194 242 s.addTest(unittest.makeSuite(wllogic)) 243 s.addTest(unittest.makeSuite(Link)) 195 244 196 245 return s -
branches/exodus-roland/exodus/wllogic.py
r6373 r6420 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
Note:
See TracChangeset
for help on using the changeset viewer.