- Timestamp:
- Nov 5, 2008, 11:32:49 AM (16 years ago)
- Location:
- trunk/exodus
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/exodus/tests.py
r6359 r6365 34 34 from exodus.models import Location 35 35 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') 40 37 self.failUnless(str(l.longitude), '34.55') 41 38 self.failUnless(str(l.latitude), '44.55') … … 99 96 def test_parse_show_addr(self): 100 97 ip = '172.16.2.0' 101 from exodus.wllogic import parse addr102 parsed = parse addr(ip)98 from exodus.wllogic import parse_addr 99 parsed = parse_addr(ip) 103 100 self.failUnlessEqual(str(parsed), '2886730240') 104 101 105 from exodus.wllogic import show addr106 o_ip = show addr(parsed)102 from exodus.wllogic import show_addr 103 o_ip = show_addr(parsed) 107 104 self.failUnlessEqual(o_ip, ip) 108 105 109 106 # when using an address larger then 256, move 1 address up. 110 107 ip = '172.16.2.256' 111 o_ip = show addr(parseaddr(ip))108 o_ip = show_addr(parse_addr(ip)) 112 109 self.failUnlessEqual(o_ip, '172.16.3.0') 113 110 … … 131 128 def test_network(self): 132 129 from wllogic import network 133 from wllogic import show addr134 network_addr = show addr(network('172.18.5.10', 24))130 from wllogic import show_addr 131 network_addr = show_addr(network('172.18.5.10', 24)) 135 132 self.failUnlessEqual(network_addr, '172.18.5.0') 136 133 137 134 def test_broadcast(self): 138 135 from wllogic import broadcast 139 from wllogic import show addr136 from wllogic import show_addr 140 137 141 broadcast_addr = show addr(broadcast('172.16.5.232', 24))138 broadcast_addr = show_addr(broadcast('172.16.5.232', 24)) 142 139 self.failUnlessEqual(broadcast_addr, '172.16.5.255') 143 140 … … 161 158 self.failUnlessRaises(ValueError, getBroadcast, '172.17.2.0', 33) 162 159 163 def test_free MasterIP(self):164 from wllogic import free MasterIP160 def test_free_masterip(self): 161 from wllogic import free_masterip 165 162 from exodus.models import Node, Network 166 163 … … 168 165 masterip = '172.16.0.1', name = 'testnode') 169 166 network = Network.objects.get(pk=1) 170 ip = free MasterIP(network)167 ip = free_masterip(network) 171 168 self.failIfEqual(ip, '172.16.0.0') 172 169 self.failUnlessEqual(ip, '172.16.1.0') -
trunk/exodus/views.py
r6359 r6365 11 11 12 12 from exodus.models import * 13 from exodus.wllogic import free MasterIP, newSSIDName, addInterlinkIP, \13 from exodus.wllogic import free_masterip, newSSIDName, addInterlinkIP, \ 14 14 freeInterlinkIP, freePublicAPIP 15 15 … … 245 245 # input a valid master ip into new_data 246 246 _instance = self.form.save(commit=False) 247 _instance.masterip = free MasterIP(_instance.network)247 _instance.masterip = free_masterip(_instance.network) 248 248 _instance.save() 249 249 self.response = HttpResponseRedirect(reverse('exodus.views.viewNode', \ -
trunk/exodus/wllogic.py
r6357 r6365 15 15 # Taken from lvoege@gmail.com's getrange.py 16 16 # 17 def parse addr(s):17 def parse_addr(s): 18 18 """Remember when using an address has a section which is higher than 19 255, such as 172.16.0.256, the ip address from show addr turns out as19 255, such as 172.16.0.256, the ip address from show_addr turns out as 20 20 172.16.1.0 21 21 """ … … 26 26 long(f[3]) 27 27 28 def show addr(a):28 def show_addr(a): 29 29 return "%d.%d.%d.%d" % ((a >> 24) & 0xff, (a >> 16) & 0xff, (a >> 8) & 0xff, a & 0xff) 30 30 … … 36 36 37 37 def getSubnet(netmask): 38 return(show addr(netmask2subnet(netmask)))38 return(show_addr(netmask2subnet(netmask))) 39 39 40 40 def network(address, netmask): 41 41 """IPv4 network address when address and netmask are given""" 42 return(parse addr(address) & netmask2subnet(netmask))42 return(parse_addr(address) & netmask2subnet(netmask)) 43 43 44 44 def broadcast(address, netmask): … … 46 46 if netmask > 32: 47 47 raise ValueError, 'netmask too large' 48 return(parse addr(address) | 0xffffffff >> netmask)48 return(parse_addr(address) | 0xffffffff >> netmask) 49 49 50 50 def getNetwork(address, netmask): 51 return(show addr(network(address,netmask)))51 return(show_addr(network(address,netmask))) 52 52 53 53 def getBroadcast(address, netmask): 54 return(show addr(broadcast(address,netmask)))54 return(show_addr(broadcast(address,netmask))) 55 55 56 #XXX: free MasterIP/addInterlinkIP should be more general by writing a function56 #XXX: free_masterip/addInterlinkIP should be more general by writing a function 57 57 # which finds a range based on a given range, taken ip/netmask and 58 58 # requested subnet 59 59 60 def free MasterIP(city_network, netmask = None):60 def free_masterip(city_network, netmask = None): 61 61 if netmask == None: 62 62 netmask = MASTERIP_NETMASK … … 74 74 75 75 #XXX: No out of bond checking done yet 76 i = parse addr(city_network.ipspacestart)76 i = parse_addr(city_network.ipspacestart) 77 77 while taken.has_key(i): 78 78 i = i + numaddrs 79 79 80 return show addr(i)80 return show_addr(i) 81 81 82 82 # … … 109 109 i = i + numaddrs 110 110 111 return show addr(i)111 return show_addr(i) 112 112 113 113 def freeInterlinkIP(masterLink): … … 126 126 i = i + numaddrs 127 127 128 return show addr(i)128 return show_addr(i) 129 129 130 130 def addInterlinkIP(masterLink): … … 133 133 for interface in Interface.objects.filter(link=masterLink): 134 134 #Grr, needs all interfaces which are master requires a bit of a hack 135 addr = parse addr(interface.ip)135 addr = parse_addr(interface.ip) 136 136 taken[addr] = 1 137 137 … … 142 142 i = i + 1 143 143 144 return show addr(i)144 return show_addr(i)
Note:
See TracChangeset
for help on using the changeset viewer.