Changeset 6365 for trunk


Ignore:
Timestamp:
Nov 5, 2008, 11:32:49 AM (16 years ago)
Author:
roland
Message:

renaming functions and classes to be in line with python naming

Location:
trunk/exodus
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/exodus/tests.py

    r6359 r6365  
    3434        from exodus.models import Location
    3535   
    36         try:
    37             l = Location.objects.get(description = 'JohnLaan2')
    38         except Location.DoesNotExist:
    39             self.fail("Location wasn't get added.")
     36        l = Location.objects.get(description = 'JohnLaan2')
    4037        self.failUnless(str(l.longitude), '34.55')
    4138        self.failUnless(str(l.latitude), '44.55')
     
    9996    def test_parse_show_addr(self):
    10097        ip = '172.16.2.0'
    101         from exodus.wllogic import parseaddr
    102         parsed = parseaddr(ip)
     98        from exodus.wllogic import parse_addr
     99        parsed = parse_addr(ip)
    103100        self.failUnlessEqual(str(parsed), '2886730240')
    104101
    105         from exodus.wllogic import showaddr
    106         o_ip = showaddr(parsed)
     102        from exodus.wllogic import show_addr
     103        o_ip = show_addr(parsed)
    107104        self.failUnlessEqual(o_ip, ip)
    108105
    109106        # when using an address larger then 256, move 1 address up.
    110107        ip = '172.16.2.256'
    111         o_ip = showaddr(parseaddr(ip))
     108        o_ip = show_addr(parse_addr(ip))
    112109        self.failUnlessEqual(o_ip, '172.16.3.0')
    113110
     
    131128    def test_network(self):
    132129        from wllogic import network
    133         from wllogic import showaddr
    134         network_addr = showaddr(network('172.18.5.10', 24))
     130        from wllogic import show_addr
     131        network_addr = show_addr(network('172.18.5.10', 24))
    135132        self.failUnlessEqual(network_addr, '172.18.5.0')
    136133
    137134    def test_broadcast(self):
    138135        from wllogic import broadcast
    139         from wllogic import showaddr
     136        from wllogic import show_addr
    140137       
    141         broadcast_addr = showaddr(broadcast('172.16.5.232', 24))
     138        broadcast_addr = show_addr(broadcast('172.16.5.232', 24))
    142139        self.failUnlessEqual(broadcast_addr, '172.16.5.255')
    143140
     
    161158        self.failUnlessRaises(ValueError, getBroadcast, '172.17.2.0', 33)
    162159
    163     def test_freeMasterIP(self):
    164         from wllogic import freeMasterIP
     160    def test_free_masterip(self):
     161        from wllogic import free_masterip
    165162        from exodus.models import Node, Network
    166163
     
    168165                masterip = '172.16.0.1', name = 'testnode')
    169166        network = Network.objects.get(pk=1)
    170         ip = freeMasterIP(network)
     167        ip = free_masterip(network)
    171168        self.failIfEqual(ip, '172.16.0.0')
    172169        self.failUnlessEqual(ip, '172.16.1.0')
  • trunk/exodus/views.py

    r6359 r6365  
    1111
    1212from exodus.models import *
    13 from exodus.wllogic import freeMasterIP, newSSIDName, addInterlinkIP, \
     13from exodus.wllogic import free_masterip, newSSIDName, addInterlinkIP, \
    1414                freeInterlinkIP, freePublicAPIP
    1515
     
    245245                # input a valid master ip into new_data
    246246                _instance  = self.form.save(commit=False)
    247                 _instance.masterip = freeMasterIP(_instance.network)
     247                _instance.masterip = free_masterip(_instance.network)
    248248                _instance.save()
    249249                self.response = HttpResponseRedirect(reverse('exodus.views.viewNode', \
  • trunk/exodus/wllogic.py

    r6357 r6365  
    1515# Taken from lvoege@gmail.com's getrange.py
    1616#
    17 def parseaddr(s):
     17def parse_addr(s):
    1818        """Remember when using an address has a section which is higher than
    19         255, such as 172.16.0.256, the ip address from showaddr turns out as
     19        255, such as 172.16.0.256, the ip address from show_addr turns out as
    2020        172.16.1.0
    2121        """
     
    2626                long(f[3])
    2727
    28 def showaddr(a):
     28def show_addr(a):
    2929        return "%d.%d.%d.%d" % ((a >> 24) & 0xff, (a >> 16) & 0xff, (a >> 8) & 0xff, a & 0xff)
    3030
     
    3636
    3737def getSubnet(netmask):
    38         return(showaddr(netmask2subnet(netmask)))
     38        return(show_addr(netmask2subnet(netmask)))
    3939
    4040def network(address, netmask):
    4141        """IPv4 network address when address and netmask are given"""
    42         return(parseaddr(address) & netmask2subnet(netmask))
     42        return(parse_addr(address) & netmask2subnet(netmask))
    4343
    4444def broadcast(address, netmask):
     
    4646        if netmask > 32:
    4747                raise ValueError, 'netmask too large'
    48         return(parseaddr(address) | 0xffffffff >> netmask)
     48        return(parse_addr(address) | 0xffffffff >> netmask)
    4949
    5050def getNetwork(address, netmask):
    51         return(showaddr(network(address,netmask)))
     51        return(show_addr(network(address,netmask)))
    5252
    5353def getBroadcast(address, netmask):
    54         return(showaddr(broadcast(address,netmask)))
     54        return(show_addr(broadcast(address,netmask)))
    5555
    56 #XXX: freeMasterIP/addInterlinkIP should be more general by writing a function
     56#XXX: free_masterip/addInterlinkIP 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 freeMasterIP(city_network, netmask = None):
     60def free_masterip(city_network, netmask = None):
    6161        if netmask == None:
    6262                netmask = MASTERIP_NETMASK
     
    7474
    7575        #XXX: No out of bond checking done yet
    76         i = parseaddr(city_network.ipspacestart)
     76        i = parse_addr(city_network.ipspacestart)
    7777        while taken.has_key(i):
    7878                i = i + numaddrs
    7979   
    80         return showaddr(i)
     80        return show_addr(i)
    8181
    8282#
     
    109109                i = i + numaddrs
    110110       
    111         return showaddr(i)
     111        return show_addr(i)
    112112
    113113def freeInterlinkIP(masterLink):
     
    126126                i = i + numaddrs
    127127       
    128         return showaddr(i)
     128        return show_addr(i)
    129129
    130130def addInterlinkIP(masterLink):
     
    133133        for interface in Interface.objects.filter(link=masterLink):
    134134                #Grr, needs all interfaces which are master requires a bit of a hack
    135                 addr = parseaddr(interface.ip)
     135                addr = parse_addr(interface.ip)
    136136                taken[addr] = 1
    137137
     
    142142                i = i + 1
    143143       
    144         return showaddr(i)
     144        return show_addr(i)
Note: See TracChangeset for help on using the changeset viewer.