daemon: Use a set to store the broker node map.
This commit is contained in:
parent
6494605298
commit
8479ccd2c5
2 changed files with 37 additions and 43 deletions
|
@ -399,28 +399,25 @@ class CoreBroker(ConfigurableManager):
|
|||
def addnodemap(self, server, nodenum):
|
||||
''' Record a node number to emulation server mapping.
|
||||
'''
|
||||
self.nodemap_lock.acquire()
|
||||
with self.nodemap_lock:
|
||||
if nodenum in self.nodemap:
|
||||
if server in self.nodemap[nodenum]:
|
||||
self.nodemap_lock.release()
|
||||
return
|
||||
self.nodemap[nodenum].append(server)
|
||||
self.nodemap[nodenum].add(server)
|
||||
else:
|
||||
self.nodemap[nodenum] = [server,]
|
||||
self.nodemap[nodenum] = {server}
|
||||
if server in self.nodecounts:
|
||||
self.nodecounts[server] += 1
|
||||
else:
|
||||
self.nodecounts[server] = 1
|
||||
self.nodemap_lock.release()
|
||||
|
||||
def delnodemap(self, sock, nodenum):
|
||||
''' Remove a node number to emulation server mapping.
|
||||
Return the number of nodes left on this server.
|
||||
'''
|
||||
self.nodemap_lock.acquire()
|
||||
count = None
|
||||
with self.nodemap_lock:
|
||||
if nodenum not in self.nodemap:
|
||||
self.nodemap_lock.release()
|
||||
return count
|
||||
found = False
|
||||
for server in self.nodemap[nodenum]:
|
||||
|
@ -435,7 +432,6 @@ class CoreBroker(ConfigurableManager):
|
|||
if server in self.nodecounts:
|
||||
count -= 1
|
||||
self.nodecounts[server] = count
|
||||
self.nodemap_lock.release()
|
||||
return count
|
||||
|
||||
def incrbootcount(self):
|
||||
|
@ -450,15 +446,12 @@ class CoreBroker(ConfigurableManager):
|
|||
return self.bootcount
|
||||
|
||||
def getserversbynode(self, nodenum):
|
||||
''' Retrieve a list of emulation servers given a node number.
|
||||
''' Retrieve a set of emulation servers given a node number.
|
||||
'''
|
||||
self.nodemap_lock.acquire()
|
||||
with self.nodemap_lock:
|
||||
if nodenum not in self.nodemap:
|
||||
self.nodemap_lock.release()
|
||||
return []
|
||||
r = self.nodemap[nodenum]
|
||||
self.nodemap_lock.release()
|
||||
return r
|
||||
return set()
|
||||
return self.nodemap[nodenum]
|
||||
|
||||
def addnet(self, nodenum):
|
||||
''' Add a node number to the list of link-layer nodes.
|
||||
|
|
|
@ -237,8 +237,9 @@ class MobilityManager(ConfigurableManager):
|
|||
return
|
||||
for nodenum in nodenums:
|
||||
node = self.phys[nodenum]
|
||||
servers = self.session.broker.getserversbynode(nodenum)
|
||||
(host, port, sock) = self.session.broker.getserver(servers[0])
|
||||
for server in self.session.broker.getserversbynode(nodenum):
|
||||
break
|
||||
(host, port, sock) = self.session.broker.getserver(server)
|
||||
netif = self.session.broker.gettunnel(net.objid, IPAddr.toint(host))
|
||||
node.addnetif(netif, 0)
|
||||
netif.node = node
|
||||
|
|
Loading…
Reference in a new issue