def getSpanningTree(nodes, root = None, maxbranching = 2, hostgetter = operator.attrgetter('hostname')): if not root: # Pick root (deterministically) root = min(nodes, key=hostgetter) # Obtain all IPs in numeric format # (which means faster distance computations) for node in nodes: node._ip = server.gethostbyname(hostgetter(node)) node._ip_n = struct.unpack('!L', socket.inet_aton(node._ip))[0] # Compute plan # NOTE: the plan is an iterator plan = mst.mst( nodes, lambda a,b : ipaddr2.ipdistn(a._ip_n, b._ip_n), root = root, maxbranching = maxbranching) return plan
def getSpanningTree(nodes, root=None, maxbranching=2, hostgetter=operator.attrgetter('hostname')): if not root: # Pick root (deterministically) root = min(nodes, key=hostgetter) # Obtain all IPs in numeric format # (which means faster distance computations) for node in nodes: node._ip = server.gethostbyname(hostgetter(node)) node._ip_n = struct.unpack('!L', socket.inet_aton(node._ip))[0] # Compute plan # NOTE: the plan is an iterator plan = mst.mst(nodes, lambda a, b: ipaddr2.ipdistn(a._ip_n, b._ip_n), root=root, maxbranching=maxbranching) return plan
def do_spanning_deployment_plan(self): # Create application groups by collecting all applications # based on their hash - the hash should contain everything that # defines them and the platform they're built def dephash(app): return ( frozenset((app.depends or "").split(' ')), frozenset((app.sources or "").split(' ')), app.build, app.install, app.node.architecture, app.node.operatingSystem, app.node.pl_distro, app.__class__, ) depgroups = collections.defaultdict(list) for element in self._elements.itervalues(): if isinstance(element, self._app.Dependency): depgroups[dephash(element)].append(element) elif isinstance(element, self._node.Node): deps = element._yum_dependencies if deps: depgroups[dephash(deps)].append(deps) # Set up spanning deployment for those applications that # have been deployed in several nodes. for dh, group in depgroups.iteritems(): if len(group) > 1: # Pick root (deterministically) root = min(group, key=lambda app:app.node.hostname) # Obtain all IPs in numeric format # (which means faster distance computations) for dep in group: dep._ip = server.gethostbyname(dep.node.hostname) dep._ip_n = struct.unpack('!L', socket.inet_aton(dep._ip))[0] # Compute plan # NOTE: the plan is an iterator plan = mst.mst( group, lambda a,b : ipaddr2.ipdistn(a._ip_n, b._ip_n), root = root, maxbranching = 2) # Re-sign private key try: tempprk, temppuk, tmppass = self._make_temp_private_key() except TempKeyError: continue # Set up slaves plan = list(plan) for slave, master in plan: slave.set_master(master) slave.install_keys(tempprk, temppuk, tmppass) # We don't need the user's passphrase anymore self.sliceSSHKeyPass = None