def findGatewayConnection(self): from baboossh.path import Path from baboossh.connection import Connection if not Path.hasDirectPath(self): paths = Path.getPath(None, self) if paths is None: return None else: prevHop = paths[-1].getSrc().getClosestEndpoint() return Connection.findWorkingByEndpoint(prevHop) return None
def getClosestEndpoint(self): from baboossh.path import Path endpoints = self.getEndpoints() shortestLen = None shortest = None for endpoint in endpoints: if Path.hasDirectPath(endpoint): return endpoint chain = Path.getPath(None, endpoint) if shortestLen is None or len(chain) < shortestLen: shortest = endpoint shortestLen = len(chain) return shortest
def getPathToDst(self,dst): if dst in self.getHostsNames(): hosts = Host.findByName(dst) if len(hosts) > 1: print("Several hosts corresponding. Please target endpoint.") return False dst = str(hosts[0].getClosestEndpoint()) try: dst = Endpoint.findByIpPort(dst) except: print("Please specify a valid endpoint in the IP:PORT form") return if dst is None: print("The endpoint provided doesn't exist in this workspace") return if Path.hasDirectPath(dst): print("The destination should be reachable from the host") return chain = Path.getPath(None,dst) if chain is None: print("No path could be found to the destination") return for path in chain: print(path)