diff options
Diffstat (limited to 'libs/connect/ssh.py')
-rwxr-xr-x | libs/connect/ssh.py | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/libs/connect/ssh.py b/libs/connect/ssh.py index a419c31..e4540d5 100755 --- a/libs/connect/ssh.py +++ b/libs/connect/ssh.py @@ -7,8 +7,8 @@ import time from atfglobals import GlobalObj class SshConnection(): - - def __init__(self): + + def __init__(self): self._connection = paramiko.SSHClient() def connect(self, host, user, password): @@ -17,14 +17,14 @@ class SshConnection(): SSH to Server "host" as User "user" Parameter: - host: Server IP Address + host: Server IP Address user: Login Username password: Login password Return: Success: 0 Failure: 1 - """ + """ logger = GlobalObj.getLoggerObj() self._connection.set_missing_host_key_policy(paramiko.AutoAddPolicy()) @@ -43,22 +43,22 @@ class SshConnection(): except paramiko.SSHException: logger.error("SSHException: Unknown server " + host) - return 1 + return 1 return 0 def close(self): """ Objective: - Close SSH Connections + Close SSH Connections """ self._connection.close() - return + return def executecommand(self, command, commandInput=None): """ Objective: - Execute Command "comamnd" + Execute Command "comamnd" Parameters: command: command to execute @@ -73,14 +73,23 @@ class SshConnection(): output["stdoutdata"] = None output["stderrdata"] = None exit_status_ready_flag = True - + try: transport = self._connection.get_transport() channel = transport.open_session() channel.exec_command(command) # Adding sleep to get the correct exit_status. - time.sleep(5) - exit_status_ready_flag = channel.exit_status_ready() + timeout = 60 + sleeptime = 5 + while timeout: + time.sleep(sleeptime) + exit_status_ready_flag = channel.exit_status_ready() + if not exit_status_ready_flag: + timeout -=1 + continue + else: + break + if not exit_status_ready_flag: stdin = channel.makefile("wb") @@ -91,7 +100,7 @@ class SshConnection(): after executing comamnd for command completion") stdin.write("\n") return output - + stdout = channel.makefile("rb") stderr = channel.makefile_stderr("rb") exit_status = channel.recv_exit_status() @@ -104,5 +113,3 @@ class SshConnection(): logger.error("Unable to Execute Command: " + command) return output - - |