Exemplo n.º 1
0
    def __init__(self, host, user, password, port):
        #paramiko.util.log_to_file(Resources.getLogName())
        self.id = random.randint(1, 999)
        self.client = paramiko.SSHClient()
        self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        self.client.connect(hostname=host, username=user, password=password, port=port)
        Resources.logCommand('Set ' + self.server + ' connection', 'Connection id: ' + str(self.id))

        self.lastExecutionTime = datetime.datetime.now()
        self.connectionClosed  = False
        Timer(600.0, lambda: self.checkLastTimeExecution()).start()

        print('Set ' + self.server + ' connection', 'Connection id: ' + str(self.id))
Exemplo n.º 2
0
    def executeCommand(self, command):
        self.isExecuting = True
        self.lastExecutionTime = datetime.datetime.now()

        stdin, stdout, stderr = self.client.exec_command(command)
        response = stdout.read() + stderr.read()
        Resources.logCommand(command, response, 'Connection: ' + self.server + ', id: ' + str(self.id))

        #printMessage(response)
        #mila.printMessage(response)

        self.isExecuting = False
        return response
Exemplo n.º 3
0
 def __exit__(self, exc_type, exc_val, exc_tb):
     Resources.logCommand('Close ' + self.server + ' connection', 'Connection closed, id: ' + str(self.id))
     print('Exit ' + self.server + ' connection', 'Exit id: ' + str(self.id))
     self.client.close()