Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions connection/ssh_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,26 @@ def disconnect(self):
except Exception:
raise Exception(f"An exception occurred while trying to disconnect from {self.host}")

def _exec_command(self, command, timeout):
channel = self.ssh.get_transport().open_session(timeout=timeout)
channel.settimeout(timeout)
channel.exec_command(command)
return channel

def _execute(self, command, timeout):
try:
(stdin, stdout, stderr) = self.ssh.exec_command(
command, timeout=timeout.total_seconds()
)
channel = self._exec_command(command, timeout.total_seconds())
except paramiko.SSHException as e:
raise ConnectionError(
f"An exception occurred while executing command '{command}' on" f" {self.host}\n{e}"
)

return Output(stdout.read(), stderr.read(), stdout.channel.recv_exit_status())
try:
stdout = channel.makefile("r").read()
stderr = channel.makefile_stderr("r").read()
return Output(stdout, stderr, channel.recv_exit_status())
finally:
channel.close()

def _rsync(
self,
Expand Down Expand Up @@ -200,7 +209,7 @@ def reboot(self):

def is_active(self):
try:
self.ssh.exec_command("", timeout=5)
self._exec_command("", timeout=5).close()
return True
except Exception:
return False
Expand Down
Loading