Exemplo n.º 1
0
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()
Exemplo n.º 2
0
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()
Exemplo n.º 3
0
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()
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
 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
Exemplo n.º 6
0
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()
Exemplo n.º 7
0
# 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)
Exemplo n.º 8
0
 def run(self):
     self.ssh = NeXPyroSSH(self.user, self.hostname, command=self.command)
Exemplo n.º 9
0
 def run(self):
     self.ssh = NeXPyroSSH(self.user, self.hostname, command=self.command)