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 ExecTask(object): """ A remote task tracked by the manager """ def __init__(self, task_id, hostname, command, user=None): self.task_id = task_id self.hostname = hostname self.command = command self.status = "PROTO" if user: self.user = user else: self.user = os.getenv('USER') self.ssh = None def __repr__(self): return "(%i) on %s: %s" % \ (self.task_id,self.hostname,self.command) def run(self): self.ssh = NeXPyroSSH(self.user, self.hostname, command=self.command) def terminate(self): self.ssh.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()
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 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
# hostname = "130.202.115.40" 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)
def run(self): self.ssh = NeXPyroSSH(self.user, self.hostname, command=self.command)