Changeset 6441
- Timestamp:
- Dec 11, 2008, 9:05:17 PM (16 years ago)
- Location:
- trunk/exodus
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/exodus/forms.py
r6440 r6441 1 1 from django import forms 2 2 from exodus.models import Node, Interface 3 from exodus.wllogic import free_master_ip, link_has_compat_type 3 from exodus.wllogic import free_master_ip, link_has_compat_type, \ 4 link_is_wireless, new_ssid 5 from exodus.wllogic import MASTER, MANAGED 4 6 5 7 class NodeForm(forms.ModelForm): … … 20 22 else: 21 23 #XXX: Need to update ipconfigurations for depending interfaces 22 #XXX: Need to set netmask 24 #XXX: Need to set netmask for interfaces 23 25 masterip = free_master_ip(new_network) 24 26 return masterip … … 31 33 import pdb; pdb.set_trace() ; 32 34 link = self.cleaned_data.get('link') 33 35 # the type of the interface, eth, 11a, 11b, 11g. 36 type = self.cleaned_data.get('type') 37 38 try: 39 # self.instance.pk only exists when this interface has been saved 40 # before. Primary Keys's always start at 1. 41 if self.instance.pk: 42 edit = True 43 # save self.instance for further reference, so that we 44 # don't have to try, except instance everytime. 45 instance_pk = self.instance.pk 46 instance_node_id = self.instance.node_id 47 except Interface.DoesNotExist: 48 edit = instance_pk = instance_node_id = None 49 34 50 if link: 35 try: 36 # if link is to self we don't need to check anything else 37 if self.instance.pk == link.pk: 38 return link 39 # Link can't be to same node. 40 if self.instance.node_id == link.node_id: 41 raise forms.ValidationError( 42 "A link can't be to another interface on the same node") 43 except Interface.DoesNotExist: 44 pass 45 if self.cleaned_data.get('accesspoint') and \ 51 # if link is to self we don't need to check anything else 52 if instance_pk == link.pk: 53 return link 54 # Link can't be to same node, unless link is to self, 55 # which we checked above. 56 elif instance_node_id == link.node_id: 57 raise forms.ValidationError( 58 "A link can't be to another interface on the same node") 59 60 elif self.cleaned_data.get('accesspoint') and \ 46 61 self.instance.pk != link.pk: 47 62 raise forms.ValidationError( "A link can't be made to another interface when this interface has an accesspoint.") 48 63 64 # check if the two links are compatible 65 elif not link_has_compat_type(link.type, type): 66 raise forms.ValidationError( 67 'Link type %s is not compatible with %s' 68 %(link.type, type)) 69 49 70 # if link is referenced to itself, link is master and linkable 50 if link.link.pk == link.pk:71 elif link.link.pk == link.pk: 51 72 return link 52 73 53 # if we get at this elif, it means that link is in managed mode 54 # but masterlink and managed can be switched 74 # if link is ethernet, don't worry about master and managed. 75 elif not link_is_wireless(link): 76 return link 77 78 # if this elif is True, it means that 'link' is in managed 79 # mode but the link of link can change modes (master/managed). 55 80 # And check if that master has only 2, including himself, links 56 81 # and is not an accesspoint himself. 82 # We don't update the netmasks because 2 links should 83 # already have a /30, and the number of links doesn't change 84 # here. 57 85 elif len(link.link.interface_set.all()) == 2 and not \ 58 86 link.link.accesspoint: 59 import pdb; pdb.set_trace()60 # convert master to slave61 #XXX: update mode62 #XXX: update ssids63 old_slave = link64 old_master = old_slave.link65 old_master.link = old_slave66 old_slave.link = old_slave67 87 88 # Define the new master and the new slave 89 new_master = link 90 new_slave = new_master.link 91 # set both links to the new master 92 new_master.link = new_master 93 new_slave.link = new_master 94 #update mode(manage/master) when an interface is wireless 95 if not link_is_wireless(new_master): 96 new_master.type = MASTER 97 new_slave.type = MANAGED 98 # update ssids 99 ssid = new_ssid(new_master) 100 new_master.ssid = ssid 101 new_slave.ssid = ssid 68 102 #XXX: do ip address switch stuff 69 103 # 70 104 # Save 71 old_slave.save()72 old_master.save()105 new_master.save() 106 new_slave.save() 73 107 return link 74 108 75 # check if the two links are compatible 76 type = self.cleaned_data.get('type') 77 if not link_has_compat_type(link.type, type): 78 raise forms.ValidationError( 79 'Link type %s is not compatible with %s' 80 %(link.type, type)) 81 82 return link 83 109 elif len(link.link.interface_set.all()) > 2 or \ 110 link.link.accesspoint: 111 raise forms.ValidationError( 112 "The other interface is in managed mode, and can't be changed to master.") 113 # We shouldn't come here, because all link possibilities are 114 # accounted for. 115 else: 116 raise forms.ValidationError( 117 "This error should never come up, please report this bug.") 118 # If this is an edit and link is not defined, we let link reference 119 # to itself. 120 elif edit: 121 link = Interface.objects.get(pk=instance_pk) 122 return link 123 # This is a new interface, can't be linked to itself because it hasn't 124 # been saved. 125 else: 126 return link -
trunk/exodus/models.py
r6437 r6441 39 39 class Location(models.Model): 40 40 description = models.CharField(max_length=200, unique=True) 41 latitude = models.DecimalField(max_digits=8,decimal_places=6) 41 42 longitude = models.DecimalField(max_digits=8,decimal_places=6) 42 latitude = models.DecimalField(max_digits=8,decimal_places=6)43 43 44 44 class Meta: -
trunk/exodus/settings.py
r6435 r6441 12 12 MANAGERS = ADMINS 13 13 14 # WL specific settings 14 15 # Nodes get a /24 15 16 MASTERIP_NETMASK = 24 17 # these are wirelesstypes 18 WIRELESS = ('11a', '11b', '11g') 19 # Theses types are compatibale 20 COMPAT = ('11b', '11g') 16 21 17 22 -
trunk/exodus/templates/exodus-template.html
r6424 r6441 14 14 <A name="top"><img width="130" height="82" alt="logo" src="{% url static path="logo.png" %}" border=0></A><br> 15 15 <img width="130" height="97" alt="foto" src="{% url static path="foto.jpg" %}"/><br> 16 16 17 <A class="menu" href="{% url root %}">Exodus</a><br> 18 <A class="menu" href="{% url advanced_admin exodus %}">Admin</a><br> 17 19 <A class="menu" href="{% url exodus.views.viewNodelist %}">Node List</a><br> 18 <A class="menu" href="{% url exodus.views.genericModel "add" "location" "new" %}">Add Location</a><br>19 <A class="menu" href="{% url exodus.views.genericNode "add" "new" %}">Add Node</a><br>20 <center>--- Admin ---</center>21 <A class="menu" href="{% url exodus.views.viewList "location" %}">Location List</a><br>22 <A class="menu" href="{% url exodus.views.viewList "network" %}">Network List</a><br>23 <A class="menu" href="{% url exodus.views.viewList "dnsServer" %}">DNS List</a><br>24 20 </div> 25 21 </td> -
trunk/exodus/tests.py
r6440 r6441 41 41 42 42 def test_new_ssid(self): 43 class n ode(object):44 name = 'CeTIM'45 class n etwork(object):46 name = ' wleiden.net'47 nic = 'ath0'48 desc = '2cope'43 class nic(object): 44 iface = 'ath0' 45 class node(object): 46 name = 'CeTIM' 47 class network(object): 48 name = 'wleiden.net' 49 49 from exodus.wllogic import new_ssid 50 ssid = new_ssid(n ode(), nic, desc)51 52 self.failUnless (ssid, '2cope-ath0.CeTIM.wleiden.net')50 ssid = new_ssid(nic()) 51 52 self.failUnlessEqual(ssid, 'ath0.CeTIM.wleiden.net') 53 53 54 54 def test_parse_show_addr(self): … … 142 142 n = [128, 64, 32, 16, 8, 4, 1, 0, 1] 143 143 self.failUnlessEqual(k,n) 144 145 def test_CHOICES(self): 146 from wllogic import MASTER, MANAGED 147 self.failUnlessEqual(MASTER, 'ms') 148 self.failUnlessEqual(MANAGED, 'mn') 144 149 145 150 class Link(unittest.TestCase): -
trunk/exodus/urls.py
r6431 r6441 28 28 (r'^databrowse/(.*)', databrowse.site.root), 29 29 30 (r'^admin/(.*)', advanced_admin.root),30 url(r'^admin/(.*)', advanced_admin.root, name="advanced_admin"), 31 31 (r'^plain-admin/(.*)', plain_admin.root), 32 32 ) -
trunk/exodus/wllogic.py
r6440 r6441 1 1 # (c) Roland van Laar 2 2 3 from exodus.models import Node, Interface 4 from exodus.settings import MASTERIP_NETMASK 3 from exodus.models import Node, Interface, WIFI_MODE_CHOICES 4 from exodus.settings import MASTERIP_NETMASK, WIRELESS, COMPAT 5 5 from math import ceil, log 6 6 7 def new_ssid(node, nic, desc): 7 # define variables taken from CHOICES in models.py 8 MASTER = WIFI_MODE_CHOICES[0][0] 9 MANAGED = WIFI_MODE_CHOICES[1][0] 10 11 def new_ssid(nic): 8 12 """Generates a new ssid name for a new wifi NIC""" 9 13 … … 11 15 # instead of object nic. 12 16 13 return "%s -%s.%s.%s" % (desc, nic, node.name,node.network.name)17 return "%s.%s.%s" % (nic.iface, nic.node.name, nic.node.network.name) 14 18 15 19 # … … 144 148 return show_addr(i) 145 149 146 def link_is_valid(link1, link2): 147 if not link_has_compat_type(link1, link2): 148 return False 149 150 def link_is_wireless(link1): 151 wireless = ('11a', '11b', '11g') 152 if link1.type in wireless: 153 return True 150 def link_is_wireless(iface): 151 """Check if the interface is wireless""" 152 return iface.type in WIRELESS 154 153 155 154 def link_has_compat_type(type1, type2): … … 158 157 return True 159 158 # or link types must be compatible 160 compat = ('11b', '11g') 161 if type1 in compat and type2 in compat: 159 if type1 in COMPAT and type2 in COMPAT: 162 160 return True 163 161
Note:
See TracChangeset
for help on using the changeset viewer.