Changeset 6480
- Timestamp:
- Dec 23, 2008, 12:40:53 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/exodus/wllogic.py ¶
r6477 r6480 1 1 # (c) Roland van Laar 2 2 3 from exodus.models import Node, Interface,WIFI_MODE_CHOICES3 from exodus.models import Node, WIFI_MODE_CHOICES 4 4 from exodus.settings import MASTERIP_NETMASK, WIRELESS, COMPAT 5 5 from math import ceil, log … … 10 10 11 11 def new_ssid(nic): 12 """Generates a new ssid name for a new wifi NIC""" 12 """Generates a new ssid name for a new wifi NIC. 13 14 Don't use this for an accesspoint because it will generate a new 15 ssid. 16 """ 13 17 14 # nic is used instead of nic.iface, because string nic is passed on,15 # instead of object nic. 18 node = nic.node.name 19 network = nic.node.network.name 16 20 17 return "%s.%s.%s" % (nic.iface, nic.node.name, nic.node.network.name) 21 if nic.accesspoint: 22 ssid_list = set([i.ssid for i in \ 23 nic.node.interface_set.filter(accesspoint=True)]) 24 ssid = "ap%%d.%s.%s" % ( node, network) 25 free_list = ( ssid % (i) for i in range(len(ssid_list)+1) if not 26 (ssid %(i) in ssid_list)) 27 return free_list.next() 28 29 else: 30 return "il-%s.%s.%s.%s" % (nic.direction, nic.iface, node, network) 18 31 19 32 # … … 59 72 return(show_addr(broadcast(address,netmask))) 60 73 61 #XXX: free_master_ip/add_interlink_ip should be more general by writing a function62 # which finds a range based on a given range, taken ip/netmask and63 # requested subnet64 65 74 def free_master_ip(city_network, netmask = MASTERIP_NETMASK): 66 75 """Calculates the next free masterip.""" … … 83 92 # go from network address to a valid ip. 84 93 return show_addr(i+1) 85 86 #87 # XXX: Needs merging with free_interlink_ip as interface could have both AP,88 # interlink defined on one link89 #def free_publicap_ip(masterLink, netmask):90 # taken = {}91 #92 # for interface in Interface.objects.filter(link=masterLink):93 # #Grr, needs all interfaces which are master requires a bit of a hack94 # addr = network(interface.ip, interface.netmask)95 # addrMax = broadcast(interface.ip, interface.netmask)96 # while addr < addrMax:97 # taken[addr] = 198 # addr = addr + 199 #100 # for accessPoint in PublicAP.objects.filter(iface=masterLink):101 # #Grr, needs all interfaces which are master requires a bit of a hack102 # addr = network(accessPoint.ip, accessPoint.netmask)103 # addrMax = broadcast(accessPoint.ip, accessPoint.netmask)104 # while addr < addrMax:105 # taken[addr] = 1106 # addr = addr + 1107 #108 # #Should be dynamic based on the number of hosts in here109 # size = netmask110 # numaddrs = 1 << (32 - size)111 # i = network(masterLink.ip,masterLink.netmask)112 # while taken.has_key(i):113 # i = i + numaddrs114 #115 # return show_addr(i)116 #117 def free_interlink_ip(masterLink):118 taken = {}119 120 for interface in Interface.objects.filter(node=masterLink.node):121 #Grr, needs all interfaces which are master requires a bit of a hack122 addr = network(interface.ip, interface.netmask)123 taken[addr] = 1124 125 #Should be dynamic based on the number of hosts in here126 size = masterLink.netmask127 numaddrs = 1 << (32 - size)128 i = network(masterLink.node.masterip,24) + 4129 while taken.has_key(i):130 i = i + numaddrs131 132 return show_addr(i)133 134 def add_interlink_ip(master_link):135 taken = {}136 137 for interface in Interface.objects.filter(link=master_link):138 #Grr, needs all interfaces which are master requires a bit of a hack139 addr = parse_addr(interface.ip)140 taken[addr] = 1141 142 size = 32143 numaddrs = 1 << (32 - size)144 i = network(master_link.ip, master_link.netmask) + 1145 while taken.has_key(i):146 i = i + 1147 148 return show_addr(i)149 94 150 95 def link_is_wireless(iface):
Note:
See TracChangeset
for help on using the changeset viewer.