Skip to content

Commit 24aea02

Browse files
authored
feat: add pty support to execute() (canonical#438)
By default, paramiko doesn't allocate a pty, but sometimes interactive ssh emulation is required. Plumb keyward arguments which allow get_pty to be passed as a kwarg to execute().
1 parent 113e5a0 commit 24aea02

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1!10.0.2
1+
1!10.0.3

pycloudlib/instance.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ def clean(self):
228228
self.execute("sudo echo 'uninitialized' > /etc/machine-id")
229229
self.execute("sudo rm -rf /var/log/syslog")
230230

231-
def _run_command(self, command, stdin):
231+
def _run_command(self, command, stdin, get_pty=False):
232232
"""Run command in the instance."""
233-
return self._ssh(list(command), stdin=stdin)
233+
return self._ssh(list(command), stdin=stdin, get_pty=get_pty)
234234

235235
def execute(
236236
self,
@@ -376,12 +376,13 @@ def update(self):
376376
]
377377
)
378378

379-
def _ssh(self, command, stdin=None):
379+
def _ssh(self, command, stdin=None, get_pty=False):
380380
"""Run a command via SSH.
381381
382382
Args:
383383
command: string or list of the command to run
384384
stdin: optional, values to be passed in
385+
get_pty: optional, allocates a pty
385386
386387
Returns:
387388
tuple of stdout, stderr and the return code
@@ -390,7 +391,7 @@ def _ssh(self, command, stdin=None):
390391
cmd = shell_pack(command)
391392
client = self._ssh_connect()
392393
try:
393-
fp_in, fp_out, fp_err = client.exec_command(cmd)
394+
fp_in, fp_out, fp_err = client.exec_command(cmd, get_pty=get_pty)
394395
except (ConnectionResetError, NoValidConnectionsError, EOFError) as e:
395396
raise SSHException from e
396397
channel = fp_in.channel

pycloudlib/lxd/instance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ def __repr__(self):
5959
"""Create string representation for class."""
6060
return "LXDInstance(name={})".format(self.name)
6161

62-
def _run_command(self, command, stdin):
62+
def _run_command(self, command, stdin, get_pty=False):
6363
"""Run command in the instance."""
6464
if self.execute_via_ssh:
65-
return super()._run_command(command, stdin)
65+
return super()._run_command(command, stdin, get_pty=get_pty)
6666

6767
base_cmd = [
6868
"lxc",

0 commit comments

Comments
 (0)