Changeset 6507
- Timestamp:
- Dec 29, 2008, 10:09:18 PM (16 years ago)
- Location:
- trunk/exodus
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/exodus/admin.py ¶
r6496 r6507 4 4 from exodus.models import Location, Node, Network, Interface, Antenna, \ 5 5 DnsServer, DhcpStatic 6 from exodus.forms import NodeForm, InterfaceForm 6 from exodus.forms import NodeForm, InterfaceForm, DhcpStaticForm 7 7 from exodus.contrib import ReadOnlyAdminFields 8 8 … … 42 42 js = ("/exodus/media/js/admin/CollapsedFieldsets.js", 43 43 "/static/showandhide.js", ) 44 45 class DhcpStaticAdmin(ReadOnlyAdminFields, admin.ModelAdmin): 46 readonly = ('ipaddress',) 47 form = DhcpStaticForm 48 ordering = ('accesspoint__node', 'accesspoint') 49 search_fields = ('hostname', 'macaddress') 44 50 45 51 … … 50 56 advanced_admin.register(Node, NodeAdmin) 51 57 advanced_admin.register(Interface, InterfaceAdmin) 52 advanced_admin.register(DhcpStatic )58 advanced_admin.register(DhcpStatic, DhcpStaticAdmin) 53 59 54 60 plain_admin.register(Antenna) -
TabularUnified trunk/exodus/forms.py ¶
r6496 r6507 1 1 from django import forms 2 from exodus.models import Location, Node, Interface 2 from exodus.models import Location, Node, Interface, DhcpStatic 3 3 from exodus.wllogic import free_master_ip, link_has_compat_type, \ 4 4 link_is_wireless, new_ssid, new_ssid_for_existing_interface 5 from exodus.wllogic import MASTER, MANAGED, calc_subnet 5 from exodus.wllogic import MASTER, MANAGED, calc_subnet, network, show_addr 6 6 from exodus.settings import AP_NETMASK 7 7 from exodus.wlipcalc import IPCalc 8 import re 8 9 9 10 class LocationForm(forms.ModelForm): … … 14 15 class Meta: 15 16 model = Node 17 18 def clean_name(self): 19 name = self.cleaned_data.get('name') 20 re_name = re.compile('[0-9a-zA-Z-]+') 21 if not name == re_name.match(name).group(): 22 raise forms.ValidationError( 23 'Not a valid name. Use letters, digits and -.') 24 return name 16 25 17 26 def clean_masterip(self): … … 25 34 masterip = self.cleaned_data.get('masterip') 26 35 else: 27 #XXX: Need to update ipconfigurations for depending interfaces28 #XXX: Need to set netmask for interfaces29 36 masterip = free_master_ip(new_network) 30 37 masterlinks = ( i for i in self.instance.interface_set.all() … … 55 62 j.save() 56 63 i.save() 64 # update the static hosts on this interface 65 for j in i.dhcpstatic_set.all(): 66 ip_size = int(pow(2,32-netmask)) 67 networkaddrL = network(i.ip, i.netmask) 68 # 1, -1 compensate for network and broadcast addr. 69 iplist = [show_addr(networkaddrL + k) for k in 70 xrange(1, ip_size-1)] 71 import pdb; pdb.set_trace() ; 72 for k in i.interface_set.all(): 73 iplist.remove(k.ip) 74 #remove used dhcpstatic ips, beware that interfaces 75 #that haven't been updated yet have ipaddress that 76 #are not in iplist. 77 for k in i.dhcpstatic_set.all(): 78 try: 79 iplist.remove(k.ipaddress) 80 except ValueError: 81 pass 82 iplist.reverse() 83 j.ipaddress = iplist.pop() 84 j.save() 57 85 return masterip 58 86 … … 60 88 class Meta: 61 89 model = Interface 90 91 def clean_iface(self): 92 iface = self.cleaned_data.get('iface') 93 re_iface = re.compile('[a-z]+[0-9]+') 94 if not re_iface.match(iface) or \ 95 re_iface.match(iface).group() != iface: 96 raise forms.ValidationError("Please enter a valid interface name") 97 return iface 62 98 63 99 def clean_polar(self): … … 116 152 elif self.cleaned_data.get('accesspoint') and \ 117 153 self.instance.pk != link.pk: 118 raise forms.ValidationError( "A link can't be made to another interface when this interface has an accesspoint.") 154 raise forms.ValidationError( "A link can't be made to another" 155 " interface when this interface has an accesspoint.") 119 156 120 157 # if link is referenced to itself, link is master and linkable … … 170 207 elif len(link.link.interface_set.all()) > 2 or \ 171 208 link.link.accesspoint: 172 raise forms.ValidationError( 173 "The other interface is inmanaged mode, and can't be changed to master.")209 raise forms.ValidationError( "The other interface is in" 210 " managed mode, and can't be changed to master.") 174 211 # We shouldn't come here, because all link possibilities are 175 212 # accounted for. … … 206 243 if not link: 207 244 if not ap: 208 self.data['netmask'] = 32209 245 try: 210 246 new_ip = IPCalc(node, 32) … … 215 251 216 252 if ap: 217 self.data['netmask'] = AP_NETMASK218 253 try: 219 254 new_ip = IPCalc(node, AP_NETMASK) … … 248 283 link.save() 249 284 ip = new_ip.ips.pop() 250 self.data['netmask'] = netmask251 285 # filter out own and master interface 252 286 for i in (i for i in all_links if not i.id in (pk, link.id)): … … 275 309 new_ip.ips.reverse() 276 310 ip = new_ip.ips.pop() 277 self.data['netmask'] = netmask278 311 for i in (i for i in all_links if not i.id == pk): 279 312 i.ip = new_ip.ips.pop() … … 324 357 # iface is saved for the first time 325 358 if not edit and not link: 326 return new_ssid(node , iface, accesspoint, direction)359 return new_ssid(node.network, node, iface, accesspoint, direction) 327 360 328 361 # iface is in managed mode … … 336 369 if self.instance.link_id != link.id or \ 337 370 self.instance.accesspoint != accesspoint: 338 return new_ssid(node , iface, accesspoint, direction)371 return new_ssid(node.network, node, iface, accesspoint, direction) 339 372 340 373 # else, don't change ssid and return original … … 355 388 356 389 return MANAGED 390 391 class DhcpStaticForm(forms.ModelForm): 392 class Meta: 393 model = DhcpStatic 394 395 def clean_hostname(self): 396 hostname = self.cleaned_data.get('hostname') 397 re_hostname = re.compile('[0-9a-zA-Z-]+') 398 if not hostname == re_hostname.match(hostname).group(): 399 raise forms.ValidationError( 400 'Not a valid hostname. Use letters, digits and -.') 401 return hostname 402 403 def clean_macaddress(self): 404 macaddress = self.cleaned_data.get('macaddress') 405 re_mac = re.compile('([0-9a-fA-F]{2}[:]){5}[0-9a-fA-F]{2}') 406 if not re_mac.match(macaddress): 407 raise forms.ValidationError( "Please enter a valid macaddress in" 408 " the form of : XX:XX:XX:XX:XX:XX") 409 return macaddress 410 411 def clean_accesspoint(self): 412 accesspoint = self.cleaned_data.get('accesspoint') 413 if not accesspoint.accesspoint: 414 raise forms.ValidationError("Please choose an accesspoint that is" 415 " enabled as an accesspoint") 416 return accesspoint 417 418 def clean_ipaddress(self): 419 # XXX: don't forget to update this address when changing ips. 420 accesspoint = self.cleaned_data.get('accesspoint') 421 ip = accesspoint.ip 422 netmask = accesspoint.netmask 423 ip_size = int(pow(2,32-netmask)) 424 networkaddrL = network(ip, netmask) 425 # 1, -1 compensate for network and broadcast addr. 426 iplist = [show_addr(networkaddrL + i) for i in xrange(1, ip_size-1)] 427 for i in accesspoint.interface_set.all(): 428 iplist.remove(i.ip) 429 [iplist.remove(i.ipaddress) for i in 430 accesspoint.dhcpstatic_set.all() if not 431 i.pk == self.instance.pk] 432 iplist.reverse() 433 return iplist.pop() -
TabularUnified trunk/exodus/models.py ¶
r6491 r6507 136 136 hostname = models.CharField(max_length=10,unique=True) 137 137 macaddress = models.CharField(max_length=17) 138 a ddress = models.IPAddressField()139 public_accesspoint = models.ForeignKey(Interface)138 accesspoint = models.ForeignKey(Interface) 139 ipaddress = models.IPAddressField(unique=True, blank=True) 140 140 141 141 class Meta: … … 143 143 144 144 def __unicode__(self): 145 return self.hostname 145 return "%s.%s.%s %s" % (self.hostname, self.accesspoint.node.name, 146 self.accesspoint.node.network.name, self.macaddress)
Note:
See TracChangeset
for help on using the changeset viewer.