Changeset 6459


Ignore:
Timestamp:
Dec 15, 2008, 12:17:45 PM (16 years ago)
Author:
roland
Message:

New stuff, in wlipcalc a better version and better tests, added LocationForm to forms.py.

Location:
trunk/exodus
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/exodus/forms.py

    r6454 r6459  
    11from django import forms
    2 from exodus.models import Node, Interface
     2from exodus.models import Location, Node, Interface
    33from exodus.wllogic import free_master_ip, link_has_compat_type, \
    44        link_is_wireless, new_ssid
    55from exodus.wllogic import MASTER, MANAGED
     6from exodus.wlipcalc import IPCalc
     7
     8class LocationForm(forms.ModelForm):
     9    class Meta:
     10        model = Location
    611
    712class NodeForm(forms.ModelForm):
     
    3439        type = self.cleaned_data.get('type')
    3540
    36         # self.instance raises DoesNotExist, but self.instance.[pk, ssid, polar, etc] doesn't
     41        # self.instance raises DoesNotExist,
     42        # but self.instance.[pk, ssid, polar, etc] doesn't
    3743        # Primary Keys's always start at 1.
    3844        if self.instance.pk:
     
    4551            if self.instance.pk == link.pk:
    4652                return link
     53
     54            # check if the two links are compatible
     55            elif not link_has_compat_type(link.type, type):
     56                raise forms.ValidationError(
     57                    'Link type %s is not compatible with %s'
     58                    %(link.type, type))
     59
    4760            # Link can't be to same node, unless link is to self,
    4861            # which we checked above.
     
    5467                    self.instance.pk != link.pk:
    5568                raise forms.ValidationError( "A link can't be made to another interface when this interface has an accesspoint.")
    56 
    57             # check if the two links are compatible
    58             elif not link_has_compat_type(link.type, type):
    59                 raise forms.ValidationError(
    60                     'Link type %s is not compatible with %s'
    61                     %(link.type, type))
    6269
    6370            # if link is referenced to itself, link is master and linkable
     
    93100                new_master.ssid = ssid
    94101                new_slave.ssid = ssid
    95                 #XXX: do ip address switch stuff
    96                 #
     102
     103                # calc the new ipaddresses
     104                ip = IPCalc(new_master.node, 30) 
     105                new_master.ip , new_slave.ip = ip.ips
     106                new_master.netmask = new_slave.netmask = 30
     107                   
    97108                # Save
    98109                new_master.save()
  • trunk/exodus/scripts/genesis_to_exodus.py

    r6456 r6459  
    22
    33def run():
     4    import pdb; pdb.set_trace() ;
    45    """Import script for genesis data."""
    56    print """Import script for genesis."""
  • trunk/exodus/tests.py

    r6458 r6459  
    4949
    5050    def test_ipcalc_get_used_ips(self):
    51         self.fail("Test not implemented")
     51        list = ['172.16.0.1', '172.16.0.2', '172.16.0.4', '172.16.0.5',
     52                '172.16.0.6', '172.16.0.7']
     53        used_list = self.ipcalc(30)._get_used_ips()
     54        used_list.sort()
     55        self.failUnlessEqual( list, used_list)
    5256
    5357    def test_ipcalc_get_free_network_addr(self):
    54         self.fail("Test not implemented")
     58        list = ['172.16.0.1', '172.16.0.2', '172.16.0.4', '172.16.0.5',
     59                '172.16.0.6', '172.16.0.7']
     60        network_addr = self.ipcalc(30)._get_free_network_addr(list)
     61        self.failUnlessEqual(network_addr, '172.16.0.8')
    5562
    5663    def test_ipcalc_out_of_bounds(self):
  • trunk/exodus/wlipcalc.py

    r6458 r6459  
    3131            self.network = wl.show_addr(network)
    3232 
    33         # variables for extenal calling
     33        # variables for external calling
    3434        self.netmask = free_netmask
    3535        if free_netmask == 32:
     
    4242            for i in range(1, self.new_ip_size-1):
    4343                self.ips.append(wl.show_addr(network + i))                   
     44
    4445    def _ip_size(self, netmask):
    4546        return int(pow(2,32 - netmask))
     
    7778                    return  network_addr
    7879        return None
    79 
Note: See TracChangeset for help on using the changeset viewer.