Skip to content

Commit

Permalink
Exposed get_pty parameter (#147)
Browse files Browse the repository at this point in the history
For use with commands that require a pseudo-terminal to run without
exceptions (like certain windows powershell commands)
  • Loading branch information
obaireys authored Jan 3, 2022
1 parent 6d258ff commit b3a3f19
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions rrmngmnt/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ def _update_timeout_exception(self, ex, timeout=None):
def command(self, cmd):
return RemoteExecutor.Command(cmd, self)

def run_cmd(self, cmd, input_=None, timeout=None):
def run_cmd(self, cmd, input_=None, timeout=None, get_pty=False):
if self._executor.sudo:
cmd.insert(0, "sudo")

cmd = self.command(cmd)
return cmd.run(input_, timeout)
return cmd.run(input_, timeout, get_pty=get_pty)

@contextlib.contextmanager
def open_file(self, path, mode='r', bufsize=-1):
Expand Down Expand Up @@ -245,19 +245,28 @@ def session(self, timeout=None):
"""
return RemoteExecutor.Session(self, timeout)

def run_cmd(self, cmd, input_=None, tcp_timeout=None, io_timeout=None):
def run_cmd(
self,
cmd,
input_=None,
tcp_timeout=None,
io_timeout=None,
get_pty=False
):
"""
Args:
tcp_timeout (float): Tcp timeout
cmd (list): Command
input_ (str): Input data
io_timeout (float): Timeout for data operation (read/write)
get_pty (bool) : get pseudoterminal
(equivalent to passing -t arg to ssh)
Returns:
tuple (int, str, str): Rc, out, err
"""
with self.session(tcp_timeout) as session:
return session.run_cmd(cmd, input_, io_timeout)
return session.run_cmd(cmd, input_, io_timeout, get_pty=get_pty)

def is_connective(self, tcp_timeout=20.0):
"""
Expand Down

0 comments on commit b3a3f19

Please sign in to comment.