Changeset 6477
- Timestamp:
- Dec 22, 2008, 11:43:12 PM (16 years ago)
- Location:
- trunk/exodus
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/exodus/forms.py
r6471 r6477 3 3 from exodus.wllogic import free_master_ip, link_has_compat_type, \ 4 4 link_is_wireless, new_ssid 5 from exodus.wllogic import MASTER, MANAGED 6 from exodus.settings import AP_ SUBNET5 from exodus.wllogic import MASTER, MANAGED, calc_subnet 6 from exodus.settings import AP_NETMASK 7 7 from exodus.wlipcalc import IPCalc 8 8 … … 60 60 # self.instance raises DoesNotExist, 61 61 # but self.instance.[pk, ssid, polar, etc] doesn't 62 63 62 edit = bool(self.instance.pk) 64 63 … … 159 158 We also define the netmask in this routine. 160 159 """ 161 #XXX: check if there is a free ip in the subnet162 #XXX: if not generate a new ip163 #XXX: Do we get here eventhough a validation error is raised164 160 node = self.cleaned_data.get('node') 165 161 ip = self.cleaned_data.get('ip') … … 168 164 edit = bool(self.instance.pk) 169 165 170 if not link_is_wireless(self):171 return ip172 173 166 # if we have an error, we don't calculate new ip addresses. 174 #import pdb; pdb.set_trace() ;175 167 if self._errors: 176 return ip 177 178 if ap: 179 try: 180 new_ip = IPCalc(node, AP_SUBNET, link) 181 except Exception: 182 return ip 183 ip = new_ip.ips[0] 184 if edit: 185 pass 186 self.data['netmask'] = AP_SUBNET 187 #XXX: distribute ipaddresses 188 #XXX: add ips for links to. 189 190 # if link is not defined, the link can have it's own ip. 191 #XXX: and not accespoint 192 if not link and not ap: 193 self.data['netmask'] = 32 194 try: 195 new_ip = IPCalc(node, 32) 196 except Exception: 197 return ip 198 return new_ip.ips[0] 199 200 return ip 201 168 raise forms.ValidationError( 169 "Please correct the errors in the form.") 170 171 if not link: 172 if not ap: 173 self.data['netmask'] = 32 174 try: 175 new_ip = IPCalc(node, 32) 176 except Exception: 177 raise forms.ValidationError( 178 "Not enough free ips for this node.") 179 return new_ip.ips[0] 180 181 if ap: 182 self.data['netmask'] = AP_NETMASK 183 try: 184 new_ip = IPCalc(node, AP_NETMASK) 185 except Exception: 186 raise forms.ValidationError( 187 "Not enough free ips for this node.") 188 return new_ip.ips[0] 189 190 else: 191 pk = self.instance.pk 192 # link is managed 193 if link.id != pk: 194 all_links = link.interface_set.all() 195 ip_size = len(all_links) 196 # up ip_size with one if self is not in all_links 197 if not [ i for i in all_links if i.id == pk ]: 198 ip_size += 1 199 if link.accesspoint: 200 netmask = AP_NETMASK 201 else: 202 netmask = calc_subnet(ip_size) 203 204 try: 205 new_ip = IPCalc(link.node, netmask, link.id) 206 except Exception: 207 raise forms.ValidationError( 208 "Not enough free ips for this node.") 209 new_ip.ips.reverse() 210 link.ip = new_ip.ips.pop() 211 link.netmask = netmask 212 link.save() 213 ip = new_ip.ips.pop() 214 self.data['netmask'] = netmask 215 # filter out own interface 216 for i in (i for i in all_links if not i.id == pk): 217 i.ip = new_ip.ips.pop() 218 i.netmask = netmask 219 i.save() 220 return ip 221 222 # link is master 223 if link.id == self.instance.pk: 224 all_links = link.interface_set.all() 225 if ap: 226 netmask = AP_NETMASK 227 else: 228 ip_size = len(all_links) 229 # up ip_size with one if self is not in all_links 230 if not [ x for x in all_links if x.id == pk ]: 231 ip_size += 1 232 netmask = calc_subnet(ip_size) 233 234 try: 235 new_ip = IPCalc(link.node, netmask, link.id) 236 except Exception: 237 raise forms.ValidationError( 238 "Not enough free ips for this node.") 239 import pdb; pdb.set_trace() ; 240 new_ip.ips.reverse() 241 ip = new_ip.ips.pop() 242 self.data['netmask'] = netmask 243 for i in (i for i in all_links if not i.id == pk): 244 i.ip = new_ip.ips.pop() 245 i.netmask = netmask 246 i.save() 247 return ip 248 202 249 #XXX: change SSID when iface.name changes -
trunk/exodus/models.py
r6469 r6477 97 97 link = models.ForeignKey('self', blank=True, null=True) 98 98 ip = models.IPAddressField(unique=True, blank=True) 99 netmask = models.IntegerField( default=30)99 netmask = models.IntegerField() 100 100 ssid = models.CharField(max_length=50, blank=True, null=True) 101 101 mode = models.CharField(max_length=10, choices=WIFI_MODE_CHOICES, -
trunk/exodus/settings.py
r6469 r6477 20 20 COMPAT = ('11b', '11g') 21 21 # AP subnet size 22 AP_ SUBNET= 2622 AP_NETMASK = 26 23 23 24 24 -
trunk/exodus/wlipcalc.py
r6475 r6477 35 35 self.netmask = free_netmask 36 36 if free_netmask == 32: 37 self.broadcast = self.ips = self.network 37 self.broadcast = self.network 38 self.ips = [self.network] 38 39 else: 39 40 self.broadcast = wl.get_broadcast(self.network, self.netmask) -
trunk/exodus/wllogic.py
r6469 r6477 165 165 166 166 def calc_subnet(number_ifaces): 167 """Returns the subnetmask. 167 #XXX: rename this to calc_netmask 168 """Returns the netmask. 168 169 169 170 We need the subnet with number_ifaces available in subnet. As such
Note:
See TracChangeset
for help on using the changeset viewer.