class NeXPyroSession(object): ''' Sets up a NeXPyro session on given host ''' def __init__(self, user, hostname, localPort): self.user = user self.hostname = hostname self.localPort = localPort self.sshService = None self.sshTunnel = None def run(self): command = "nxstartserver" self.sshService = NeXPyroSSH(self.user, self.hostname, command=command, getURI=True) uri = self.sshService.getURIfromQueue() if (uri == "UNSET"): print("SSH could not start NeXpyro service!") return False tokens = uri.split(":") port = int(tokens[2]) self.sshTunnel = NeXPyroSSH(self.user, self.hostname, localPort=self.localPort, remotePort=port) return True def terminate(self): print("session terminating ssh connections...") if self.sshTunnel != None: self.sshTunnel.terminate() if self.sshService != None: self.sshService.terminate()
class NeXPyroSession(object): """ Sets up a NeXPyro session on given host """ def __init__(self, user, hostname, localPort): self.user = user self.hostname = hostname self.localPort = localPort self.sshService = None self.sshTunnel = None def run(self): command = "nxstartserver" self.sshService = NeXPyroSSH(self.user, self.hostname, command=command, getURI=True) uri = self.sshService.getURIfromQueue() if uri == "UNSET": print("SSH could not start NeXpyro service!") return False tokens = uri.split(":") port = int(tokens[2]) self.sshTunnel = NeXPyroSSH(self.user, self.hostname, localPort=self.localPort, remotePort=port) return True def terminate(self): print("session terminating ssh connections...") if self.sshTunnel != None: self.sshTunnel.terminate() if self.sshService != None: self.sshService.terminate()
user = "******" # sshService = NeXpyroSSH("wozniak", hostname) # sshService = NeXpyroSSH("wozniak", hostname, command="echo hi") def sleep_safe(seconds): try: time.sleep(seconds) except KeyboardInterrupt: print(" Interrupted!") sys.exit(1) command = "python /home/wozniak/proj/nexusformat/src/nexusformat/pyro/start_server.py" sshService = NeXPyroSSH(user, hostname, command=command, getURI=True) try: uri = sshService.getURIfromQueue() except NeXPyroError as e: print e sshService.terminate() sleep_safe(2) sys.exit(1) if (uri == None or uri == "UNSET"): print("SSH could not start NeXpyro service!") sys.exit(1) print("uri: " + uri) tokens = uri.split(":") port = int(tokens[2]) print("remote port: ", port) sshTunnel = NeXPyroSSH("wozniak", hostname, localPort=9090, remotePort=port)