- Timestamp:
- Dec 10, 2008, 7:00:12 PM (16 years ago)
- Location:
- trunk/exodus
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/exodus/forms.py
r6424 r6432 1 1 from django import forms 2 2 from exodus.models import Node 3 from exodus.wllogic import free_master ip3 from exodus.wllogic import free_master_ip, free_interlinkip, add_interlinkip 4 4 from exodus.contrib import ReadOnlyWidget 5 5 … … 12 12 import pdb; pdb.set_trace() ; 13 13 new_network = self.cleaned_data.get('network') 14 #XXX: racing conditions with free_master ip and save()?14 #XXX: racing conditions with free_master_ip and save()? 15 15 # self.instnace.pk is only available when Node has been save before. 16 16 if self.instance.pk is None: 17 masterip = free_master ip(new_network)17 masterip = free_master_ip(new_network) 18 18 else: 19 19 # check if network has changed … … 23 23 else: 24 24 #XXX: Need to update ipconfigurations for depending interfaces 25 masterip = free_master ip(new_network)25 masterip = free_master_ip(new_network) 26 26 raise forms.ValidationError("Foutmelding van Rick en Roland") 27 27 return masterip -
trunk/exodus/models.py
r6431 r6432 1 # 1 #(c) Roland van Laar 2006 2 2 # vi:et:ts=4 3 3 from django.db import models … … 89 89 # #XXX: could there be racing conditions? 90 90 # #XXX: Maybe move this to a model form, 91 # from wllogic import free_master ip91 # from wllogic import free_master_ip 92 92 # # check if there is a masterip, if not generate one. 93 93 # # check if there is a network change, if so, generate a new masterip. … … 95 95 # old = Node.objects.get(pk=self.pk) 96 96 # if old.network != self.network: 97 # self.masterip = free_master ip(self.network)97 # self.masterip = free_master_ip(self.network) 98 98 # else: 99 # self.masterip = free_master ip(self.network)99 # self.masterip = free_master_ip(self.network) 100 100 # super(Node, self).save(force_insert, force_update) 101 101 -
trunk/exodus/tests.py
r6424 r6432 89 89 nic = 'ath0' 90 90 desc = '2cope' 91 from exodus.wllogic import new SSIDName92 ssid = new SSIDName(node(), nic, desc)91 from exodus.wllogic import new_ssid 92 ssid = new_ssid(node(), nic, desc) 93 93 94 94 self.failUnless(ssid, '2cope-ath0.CeTIM.wleiden.net') … … 118 118 self.failUnlessEqual(str(valid_subnet), '17179869180') 119 119 120 def test_get Subnet(self):121 from wllogic import get Subnet122 self.failUnlessRaises(ValueError, get Subnet, -1)123 self.failUnlessRaises(ValueError, get Subnet, 33)124 125 valid_netmask = get Subnet(30)120 def test_get_subnet(self): 121 from wllogic import get_subnet 122 self.failUnlessRaises(ValueError, get_subnet, -1) 123 self.failUnlessRaises(ValueError, get_subnet, 33) 124 125 valid_netmask = get_subnet(30) 126 126 self.failUnless(valid_netmask, '255.255.255.252') 127 127 … … 142 142 self.failUnlessRaises(ValueError, broadcast, '172.16.5.1', 33) 143 143 144 def test_get Network(self):145 from wllogic import get Network146 network_addr = get Network('172.17.2.2', 30)144 def test_get_network(self): 145 from wllogic import get_network 146 network_addr = get_network('172.17.2.2', 30) 147 147 self. failUnlessEqual(network_addr, '172.17.2.0') 148 148 149 self.failUnlessRaises(ValueError, get Network, '172.17.2.0', -1)150 self.failUnlessRaises(ValueError, get Network, '172.17.2.0', 33)151 152 def test_get Broadcast(self):153 from wllogic import get Broadcast154 broadcast_addr = get Broadcast('172.17.2.2', 24)149 self.failUnlessRaises(ValueError, get_network, '172.17.2.0', -1) 150 self.failUnlessRaises(ValueError, get_network, '172.17.2.0', 33) 151 152 def test_get_broadcast(self): 153 from wllogic import get_broadcast 154 broadcast_addr = get_broadcast('172.17.2.2', 24) 155 155 self.failUnlessEqual(broadcast_addr, '172.17.2.255') 156 156 157 self.failUnlessRaises(ValueError, get Broadcast, '172.17.2.0', -1)158 self.failUnlessRaises(ValueError, get Broadcast, '172.17.2.0', 33)159 160 def test_free_master ip(self):161 from wllogic import free_master ip157 self.failUnlessRaises(ValueError, get_broadcast, '172.17.2.0', -1) 158 self.failUnlessRaises(ValueError, get_broadcast, '172.17.2.0', 33) 159 160 def test_free_master_ip(self): 161 from wllogic import free_master_ip 162 162 from exodus.models import Node, Network 163 163 … … 165 165 masterip = '172.16.0.1', name = 'testnode') 166 166 network = Network.objects.get(pk=1) 167 ip = free_master ip(network)167 ip = free_master_ip(network) 168 168 self.failIfEqual(ip, '172.16.0.1') 169 169 self.failUnlessEqual(ip, '172.16.1.1') 170 170 171 def test_free PublicAPIP(self):172 from wllogic import free PublicAPIP171 def test_free_publicap_ip(self): 172 from wllogic import free_publicap_ip 173 173 self.fail('test not implemented') 174 174 175 def test_free InterlinkIP(self):176 from wllogic import free InterlinkIP175 def test_free_interlink_ip(self): 176 from wllogic import free_interlink_ip 177 177 self.fail('Test not implemented') 178 178 179 def test_add InterlinkIP(self):180 from wllogic import add InterlinkIP179 def test_add_interlink_ip(self): 180 from wllogic import add_interlink_ip 181 181 self.fail('Test not implemented') 182 182 -
trunk/exodus/views.py
r6431 r6432 8 8 9 9 from exodus.models import * 10 from exodus.wllogic import free_master ip, newSSIDName, addInterlinkIP, \11 free InterlinkIP10 from exodus.wllogic import free_master_ip, new_ssid, add_interlink_ip, \ 11 free_interlink_ip 12 12 13 13 from exodus.utils import pdebug … … 150 150 # _instance = self.form.save(commit=False) 151 151 # # Find IP range inside interface range with disired size/subnet 152 # _instance.ip = free PublicAPIP(_instance.iface, _instance.netmask)152 # _instance.ip = free_publicap_ip(_instance.iface, _instance.netmask) 153 153 # _instance.dhcpstart = 1 154 154 # _instance.dhcpstop = 2 155 155 # # If wireless generate ssid name 156 # _instance.ssid = new SSIDName(_instance.iface.node, _instance.iface, \156 # _instance.ssid = new_ssid(_instance.iface.node, _instance.iface, \ 157 157 # 'omni') 158 158 # _instance.save() … … 196 196 raise ValueError,'Type of local and remote interface needs to match' 197 197 if str(_instance.type) != "eth": 198 _instance.ssid = new SSIDName(_instance.node, _instance.iface, \198 _instance.ssid = new_ssid(_instance.node, _instance.iface, \ 199 199 'unused') 200 200 _instance.channel = '1' … … 205 205 self.is_changed.has_key('netmask'): 206 206 if not _instance.link: 207 _instance.ip = free InterlinkIP(_instance)207 _instance.ip = free_interlink_ip(_instance) 208 208 else: 209 _instance.ip = add InterlinkIP(_instance.link)209 _instance.ip = add_interlink_ip(_instance.link) 210 210 211 211 # XXX: Change in netmask requires full range of netmask changes \ … … 242 242 # input a valid master ip into new_data 243 243 _instance = self.form.save(commit=False) 244 _instance.masterip = free_master ip(_instance.network)244 _instance.masterip = free_master_ip(_instance.network) 245 245 _instance.save() 246 246 self.response = HttpResponseRedirect(reverse('exodus.views.viewNode', \ -
trunk/exodus/wllogic.py
r6431 r6432 4 4 from exodus.settings import MASTERIP_NETMASK 5 5 6 def new SSIDName(node, nic, desc):6 def new_ssid(node, nic, desc): 7 7 """Generates a new ssid name for a new wifi NIC""" 8 8 … … 35 35 return (0xffffffff << (32 - s)) 36 36 37 def get Subnet(netmask):37 def get_subnet(netmask): 38 38 return(show_addr(netmask2subnet(netmask))) 39 39 … … 48 48 return(parse_addr(address) | 0xffffffff >> netmask) 49 49 50 def get Network(address, netmask):50 def get_network(address, netmask): 51 51 return(show_addr(network(address,netmask))) 52 52 53 def get Broadcast(address, netmask):53 def get_broadcast(address, netmask): 54 54 return(show_addr(broadcast(address,netmask))) 55 55 56 #XXX: free_master ip/addInterlinkIPshould be more general by writing a function56 #XXX: free_master_ip/add_interlink_ip should be more general by writing a function 57 57 # which finds a range based on a given range, taken ip/netmask and 58 58 # requested subnet 59 59 60 def free_master ip(city_network, netmask = None):60 def free_master_ip(city_network, netmask = None): 61 61 if netmask == None: 62 62 netmask = MASTERIP_NETMASK … … 82 82 83 83 # 84 # XXX: Needs merging with free InterlinkIPas interface could have both AP,84 # XXX: Needs merging with free_interlink_ip as interface could have both AP, 85 85 # interlink defined on one link 86 #def free PublicAPIP(masterLink, netmask):86 #def free_publicap_ip(masterLink, netmask): 87 87 # taken = {} 88 88 # … … 112 112 # return show_addr(i) 113 113 # 114 def free InterlinkIP(masterLink):114 def free_interlink_ip(masterLink): 115 115 taken = {} 116 116 … … 129 129 return show_addr(i) 130 130 131 def add InterlinkIP(masterLink):131 def add_interlink_ip(masterLink): 132 132 taken = {} 133 133
Note:
See TracChangeset
for help on using the changeset viewer.