Changeset 6441


Ignore:
Timestamp:
Dec 11, 2008, 9:05:17 PM (16 years ago)
Author:
roland
Message:

Almost complete add interlink code, and a small update to the website
so that we can have some valuable user input.

Location:
trunk/exodus
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/exodus/forms.py

    r6440 r6441  
    11from django import forms
    22from exodus.models import Node, Interface
    3 from exodus.wllogic import free_master_ip, link_has_compat_type
     3from exodus.wllogic import free_master_ip, link_has_compat_type, \
     4        link_is_wireless, new_ssid
     5from exodus.wllogic import MASTER, MANAGED
    46
    57class NodeForm(forms.ModelForm):
     
    2022            else:
    2123                #XXX: Need to update ipconfigurations for depending interfaces
    22                 #XXX: Need to set netmask
     24                #XXX: Need to set netmask for interfaces
    2325                masterip = free_master_ip(new_network)
    2426        return masterip       
     
    3133        import pdb; pdb.set_trace() ;
    3234        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           
    3450        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 \
    4661                    self.instance.pk != link.pk:
    4762                raise forms.ValidationError( "A link can't be made to another interface when this interface has an accesspoint.")
    4863
     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
    4970            # 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:
    5172                return link
    5273
    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).
    5580            # And check if that master has only 2, including himself, links
    5681            # 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.
    5785            elif len(link.link.interface_set.all()) == 2 and not \
    5886                    link.link.accesspoint:
    59                 import pdb; pdb.set_trace()
    60                 # convert master to slave
    61                 #XXX: update mode
    62                 #XXX: update ssids
    63                 old_slave = link
    64                 old_master = old_slave.link
    65                 old_master.link = old_slave
    66                 old_slave.link = old_slave
    6787
     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
    68102                #XXX: do ip address switch stuff
    69103                #
    70104                # Save
    71                 old_slave.save()
    72                 old_master.save()
     105                new_master.save()
     106                new_slave.save()
    73107                return link
    74108
    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  
    3939class Location(models.Model):
    4040    description = models.CharField(max_length=200, unique=True)
     41    latitude = models.DecimalField(max_digits=8,decimal_places=6)
    4142    longitude = models.DecimalField(max_digits=8,decimal_places=6)
    42     latitude = models.DecimalField(max_digits=8,decimal_places=6)
    4343
    4444    class Meta:
  • trunk/exodus/settings.py

    r6435 r6441  
    1212MANAGERS = ADMINS
    1313
     14# WL specific settings
    1415# Nodes get a /24
    1516MASTERIP_NETMASK = 24
     17# these are wirelesstypes
     18WIRELESS = ('11a', '11b', '11g')
     19# Theses types are compatibale
     20COMPAT = ('11b', '11g')
    1621
    1722
  • trunk/exodus/templates/exodus-template.html

    r6424 r6441  
    1414          <A name="top"><img width="130" height="82" alt="logo" src="{% url static path="logo.png" %}" border=0></A><br>
    1515          <img width="130" height="97" alt="foto" src="{% url static path="foto.jpg" %}"/><br>
     16       
    1617          &nbsp;&nbsp;<A class="menu" href="{% url root %}">Exodus</a><br>
     18          &nbsp;&nbsp;<A class="menu" href="{% url advanced_admin exodus %}">Admin</a><br>
    1719          &nbsp;&nbsp;<A class="menu" href="{% url exodus.views.viewNodelist %}">Node List</a><br>
    18           &nbsp;&nbsp;<A class="menu" href="{% url exodus.views.genericModel "add" "location" "new" %}">Add Location</a><br>
    19           &nbsp;&nbsp;<A class="menu" href="{% url exodus.views.genericNode "add" "new" %}">Add Node</a><br>
    20           <center>--- Admin ---</center>
    21           &nbsp;&nbsp;<A class="menu" href="{% url exodus.views.viewList "location" %}">Location List</a><br>
    22           &nbsp;&nbsp;<A class="menu" href="{% url exodus.views.viewList "network" %}">Network List</a><br>
    23           &nbsp;&nbsp;<A class="menu" href="{% url exodus.views.viewList "dnsServer" %}">DNS List</a><br>
    2420          </div>
    2521        </td>
  • trunk/exodus/tests.py

    r6440 r6441  
    4141
    4242    def test_new_ssid(self):
    43         class node(object):
    44             name = 'CeTIM'
    45             class network(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'
    4949        from exodus.wllogic import new_ssid
    50         ssid = new_ssid(node(), 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')
    5353
    5454    def test_parse_show_addr(self):
     
    142142        n = [128, 64, 32, 16, 8, 4, 1, 0, 1]
    143143        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')
    144149       
    145150class Link(unittest.TestCase):
  • trunk/exodus/urls.py

    r6431 r6441  
    2828        (r'^databrowse/(.*)', databrowse.site.root),
    2929
    30     (r'^admin/(.*)', advanced_admin.root),
     30    url(r'^admin/(.*)', advanced_admin.root, name="advanced_admin"),
    3131    (r'^plain-admin/(.*)', plain_admin.root),
    3232)
  • trunk/exodus/wllogic.py

    r6440 r6441  
    11# (c) Roland van Laar
    22
    3 from exodus.models import Node, Interface
    4 from exodus.settings import MASTERIP_NETMASK
     3from exodus.models import Node, Interface, WIFI_MODE_CHOICES
     4from exodus.settings import MASTERIP_NETMASK, WIRELESS, COMPAT
    55from math import ceil, log
    66
    7 def new_ssid(node, nic, desc):
     7# define variables taken from CHOICES in models.py
     8MASTER = WIFI_MODE_CHOICES[0][0]
     9MANAGED = WIFI_MODE_CHOICES[1][0]
     10
     11def new_ssid(nic):
    812        """Generates a new ssid name for a new wifi NIC"""
    913
     
    1115        # instead of object nic.
    1216
    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)
    1418
    1519#
     
    144148        return show_addr(i)
    145149
    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
     150def link_is_wireless(iface):
     151        """Check if the interface is wireless"""
     152        return iface.type in WIRELESS
    154153
    155154def link_has_compat_type(type1, type2):
     
    158157                return True
    159158        # 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:
    162160                return True
    163161
Note: See TracChangeset for help on using the changeset viewer.