Changeset 6432 for trunk


Ignore:
Timestamp:
Dec 10, 2008, 7:00:12 PM (16 years ago)
Author:
RIck van der Zwet
Message:

Renamed functions
for FILE in *.py; do sed -e 's/newSSIDName/new_ssid/g' -e 's/getSubnet/get_subnet/g' -e 's/getNetwork/get_network/g' -e 's/getBroadcast/get_broadcast/g' -e 's/free_masterip/free_master_ip/g' -e 's/freePublicAPIP/free_publicap_ip/g' -e 's/freeInterlinkIP/free_interlink_ip/g' -e 's/addInterlinkIP/add_interlink_ip/g' $FILE > $FILE.new; mv $FILE.new $FILE; done

Location:
trunk/exodus
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/exodus/forms.py

    r6424 r6432  
    11from django import forms
    22from exodus.models import Node
    3 from exodus.wllogic import free_masterip
     3from exodus.wllogic import free_master_ip, free_interlinkip, add_interlinkip
    44from exodus.contrib import ReadOnlyWidget
    55
     
    1212        import pdb; pdb.set_trace() ;
    1313        new_network = self.cleaned_data.get('network')
    14         #XXX: racing conditions with free_masterip and save()?
     14        #XXX: racing conditions with free_master_ip and save()?
    1515        # self.instnace.pk is only available when Node has been save before.
    1616        if self.instance.pk is None:
    17             masterip = free_masterip(new_network)
     17            masterip = free_master_ip(new_network)
    1818        else:
    1919            # check if network has changed
     
    2323            else:
    2424                #XXX: Need to update ipconfigurations for depending interfaces
    25                 masterip = free_masterip(new_network)
     25                masterip = free_master_ip(new_network)
    2626        raise forms.ValidationError("Foutmelding van Rick en Roland")
    2727        return masterip       
  • trunk/exodus/models.py

    r6431 r6432  
    1 # (c) Roland van Laar 2006
     1#(c) Roland van Laar 2006
    22# vi:et:ts=4
    33from django.db import models
     
    8989   #     #XXX: could there be racing conditions?
    9090   #     #XXX: Maybe move this to a model form,
    91    #     from wllogic import free_masterip
     91   #     from wllogic import free_master_ip
    9292   #     # check if there is a masterip, if not generate one.
    9393   #     # check if there is a network change, if so, generate a new masterip.
     
    9595   #         old = Node.objects.get(pk=self.pk)
    9696   #         if old.network != self.network:
    97    #             self.masterip = free_masterip(self.network)
     97   #             self.masterip = free_master_ip(self.network)
    9898   #     else:
    99    #         self.masterip = free_masterip(self.network)
     99   #         self.masterip = free_master_ip(self.network)
    100100   #     super(Node, self).save(force_insert, force_update)
    101101
  • trunk/exodus/tests.py

    r6424 r6432  
    8989        nic = 'ath0'
    9090        desc = '2cope'
    91         from exodus.wllogic import newSSIDName
    92         ssid = newSSIDName(node(), nic, desc)       
     91        from exodus.wllogic import new_ssid
     92        ssid = new_ssid(node(), nic, desc)       
    9393       
    9494        self.failUnless(ssid, '2cope-ath0.CeTIM.wleiden.net')
     
    118118        self.failUnlessEqual(str(valid_subnet), '17179869180')
    119119   
    120     def test_getSubnet(self):
    121         from wllogic import getSubnet
    122         self.failUnlessRaises(ValueError, getSubnet, -1)
    123         self.failUnlessRaises(ValueError, getSubnet, 33)
    124        
    125         valid_netmask = getSubnet(30)
     120    def test_get_subnet(self):
     121        from wllogic import get_subnet
     122        self.failUnlessRaises(ValueError, get_subnet, -1)
     123        self.failUnlessRaises(ValueError, get_subnet, 33)
     124       
     125        valid_netmask = get_subnet(30)
    126126        self.failUnless(valid_netmask, '255.255.255.252')
    127127   
     
    142142        self.failUnlessRaises(ValueError, broadcast, '172.16.5.1', 33)
    143143   
    144     def test_getNetwork(self):
    145         from wllogic import getNetwork
    146         network_addr = getNetwork('172.17.2.2', 30)
     144    def test_get_network(self):
     145        from wllogic import get_network
     146        network_addr = get_network('172.17.2.2', 30)
    147147        self. failUnlessEqual(network_addr, '172.17.2.0')
    148148
    149         self.failUnlessRaises(ValueError, getNetwork, '172.17.2.0', -1)
    150         self.failUnlessRaises(ValueError, getNetwork, '172.17.2.0', 33)
    151 
    152     def test_getBroadcast(self):
    153         from wllogic import getBroadcast
    154         broadcast_addr = getBroadcast('172.17.2.2', 24)
     149        self.failUnlessRaises(ValueError, get_network, '172.17.2.0', -1)
     150        self.failUnlessRaises(ValueError, get_network, '172.17.2.0', 33)
     151
     152    def test_get_broadcast(self):
     153        from wllogic import get_broadcast
     154        broadcast_addr = get_broadcast('172.17.2.2', 24)
    155155        self.failUnlessEqual(broadcast_addr, '172.17.2.255')
    156156       
    157         self.failUnlessRaises(ValueError, getBroadcast, '172.17.2.0', -1)
    158         self.failUnlessRaises(ValueError, getBroadcast, '172.17.2.0', 33)
    159 
    160     def test_free_masterip(self):
    161         from wllogic import free_masterip
     157        self.failUnlessRaises(ValueError, get_broadcast, '172.17.2.0', -1)
     158        self.failUnlessRaises(ValueError, get_broadcast, '172.17.2.0', 33)
     159
     160    def test_free_master_ip(self):
     161        from wllogic import free_master_ip
    162162        from exodus.models import Node, Network
    163163
     
    165165                masterip = '172.16.0.1', name = 'testnode')
    166166        network = Network.objects.get(pk=1)
    167         ip = free_masterip(network)
     167        ip = free_master_ip(network)
    168168        self.failIfEqual(ip, '172.16.0.1')
    169169        self.failUnlessEqual(ip, '172.16.1.1')
    170170       
    171     def test_freePublicAPIP(self):
    172         from wllogic import freePublicAPIP
     171    def test_free_publicap_ip(self):
     172        from wllogic import free_publicap_ip
    173173        self.fail('test not implemented')
    174174
    175     def test_freeInterlinkIP(self):
    176         from wllogic import freeInterlinkIP
     175    def test_free_interlink_ip(self):
     176        from wllogic import free_interlink_ip
    177177        self.fail('Test not implemented')
    178178
    179     def test_addInterlinkIP(self):
    180         from wllogic import addInterlinkIP
     179    def test_add_interlink_ip(self):
     180        from wllogic import add_interlink_ip
    181181        self.fail('Test not implemented')
    182182
  • trunk/exodus/views.py

    r6431 r6432  
    88
    99from exodus.models import *
    10 from exodus.wllogic import free_masterip, newSSIDName, addInterlinkIP, \
    11         freeInterlinkIP
     10from exodus.wllogic import free_master_ip, new_ssid, add_interlink_ip, \
     11        free_interlink_ip
    1212
    1313from exodus.utils import pdebug
     
    150150#        _instance = self.form.save(commit=False)
    151151#        # Find IP range inside interface range with disired size/subnet
    152 #        _instance.ip = freePublicAPIP(_instance.iface, _instance.netmask)
     152#        _instance.ip = free_publicap_ip(_instance.iface, _instance.netmask)
    153153#        _instance.dhcpstart = 1
    154154#        _instance.dhcpstop = 2
    155155#        # If wireless generate ssid name
    156 #        _instance.ssid = newSSIDName(_instance.iface.node, _instance.iface, \
     156#        _instance.ssid = new_ssid(_instance.iface.node, _instance.iface, \
    157157#                'omni')
    158158#        _instance.save()
     
    196196            raise ValueError,'Type of local and remote interface needs to match'
    197197        if str(_instance.type) != "eth":
    198             _instance.ssid = newSSIDName(_instance.node, _instance.iface, \
     198            _instance.ssid = new_ssid(_instance.node, _instance.iface, \
    199199                    'unused')
    200200            _instance.channel = '1'
     
    205205                self.is_changed.has_key('netmask'):
    206206            if not _instance.link:
    207                 _instance.ip = freeInterlinkIP(_instance)
     207                _instance.ip = free_interlink_ip(_instance)
    208208            else:
    209                 _instance.ip = addInterlinkIP(_instance.link)
     209                _instance.ip = add_interlink_ip(_instance.link)
    210210
    211211        # XXX: Change in netmask requires full range of netmask changes \
     
    242242        # input a valid master ip into new_data
    243243        _instance  = self.form.save(commit=False)
    244         _instance.masterip = free_masterip(_instance.network)
     244        _instance.masterip = free_master_ip(_instance.network)
    245245        _instance.save()
    246246        self.response = HttpResponseRedirect(reverse('exodus.views.viewNode', \
  • trunk/exodus/wllogic.py

    r6431 r6432  
    44from exodus.settings import MASTERIP_NETMASK
    55
    6 def newSSIDName(node, nic, desc):
     6def new_ssid(node, nic, desc):
    77        """Generates a new ssid name for a new wifi NIC"""
    88
     
    3535        return (0xffffffff << (32 - s))
    3636
    37 def getSubnet(netmask):
     37def get_subnet(netmask):
    3838        return(show_addr(netmask2subnet(netmask)))
    3939
     
    4848        return(parse_addr(address) | 0xffffffff >> netmask)
    4949
    50 def getNetwork(address, netmask):
     50def get_network(address, netmask):
    5151        return(show_addr(network(address,netmask)))
    5252
    53 def getBroadcast(address, netmask):
     53def get_broadcast(address, netmask):
    5454        return(show_addr(broadcast(address,netmask)))
    5555
    56 #XXX: free_masterip/addInterlinkIP should be more general by writing a function
     56#XXX: free_master_ip/add_interlink_ip should be more general by writing a function
    5757#     which finds a range based on a given range, taken ip/netmask and
    5858#     requested subnet
    5959
    60 def free_masterip(city_network, netmask = None):
     60def free_master_ip(city_network, netmask = None):
    6161        if netmask == None:
    6262                netmask = MASTERIP_NETMASK
     
    8282
    8383#
    84 # XXX: Needs merging with freeInterlinkIP as interface could have both AP,
     84# XXX: Needs merging with free_interlink_ip as interface could have both AP,
    8585# interlink defined on one link
    86 #def freePublicAPIP(masterLink, netmask):
     86#def free_publicap_ip(masterLink, netmask):
    8787#       taken = {}
    8888#
     
    112112#       return show_addr(i)
    113113#
    114 def freeInterlinkIP(masterLink):
     114def free_interlink_ip(masterLink):
    115115        taken = {}
    116116       
     
    129129        return show_addr(i)
    130130
    131 def addInterlinkIP(masterLink):
     131def add_interlink_ip(masterLink):
    132132        taken = {}
    133133       
Note: See TracChangeset for help on using the changeset viewer.