@@ -202,30 +202,46 @@ def _connect(self, client, host, port, sock=None, retries=1):
202202
203203 def exec_command (self , command , sudo = False , user = None ,
204204 shell = None ,
205- use_shell = True , ** kwargs ):
205+ use_shell = True , use_pty = True ,
206+ ** kwargs ):
206207 """Wrapper to :mod:`paramiko.SSHClient.exec_command`
207208
208209 Opens a new SSH session with a new pty and runs command before yielding
209210 the main gevent loop to allow other greenlets to execute.
210211
211- :param command: Shell command to execute
212+ :param command: Cxommand to execute
212213 :type command: str
213214 :param sudo: (Optional) Run with sudo. Defaults to False
214215 :type sudo: bool
216+ :param user: (Optional) User to switch to via sudo to run command as. \
217+ Defaults to user running the python process
218+ :type user: str
219+ :param shell: (Optional) Shell override to use instead of user login \
220+ configured shell. For example ``shell='bash -c'``
221+ :param use_shell: (Optional) Force use of shell on/off. \
222+ Defaults to `True` for on
223+ :type use_shell: bool
224+ :param use_pty: (Optional) Enable/Disable use of pseudo terminal \
225+ emulation. This is required in vast majority of cases, exception \
226+ being where a shell is not used and stdout/stderr/stdin buffers \
227+ are not required. Defaults to ``True``
228+ :type use_pty: bool
215229 :param kwargs: (Optional) Keyword arguments to be passed to remote \
216230 command
217231 :type kwargs: dict
218- :rtype: Tuple of `(channel, hostname, stdout, stderr)`. \
232+ :rtype: Tuple of `(channel, hostname, stdout, stderr, stdin )`. \
219233 Channel is the remote SSH channel, needed to ensure all of stdout has \
220234 been got, hostname is remote hostname the copy is to, stdout and \
221235 stderr are buffers containing command output.
222236 """
223237 channel = self .client .get_transport ().open_session ()
224238 if self .forward_ssh_agent :
225239 agent_handler = paramiko .agent .AgentRequestHandler (channel )
226- channel .get_pty ()
240+ if use_pty :
241+ channel .get_pty ()
227242 if self .channel_timeout :
228243 channel .settimeout (self .channel_timeout )
244+ stdin = channel .makefile ('wb' )
229245 _stdout , _stderr = channel .makefile ('rb' ), \
230246 channel .makefile_stderr ('rb' )
231247 stdout , stderr = self ._read_output_buffer (_stdout ,), \
@@ -247,7 +263,7 @@ def exec_command(self, command, sudo=False, user=None,
247263 channel .exec_command (_command , ** kwargs )
248264 logger .debug ("Command started" )
249265 sleep (0 )
250- return channel , self .host , stdout , stderr
266+ return channel , self .host , stdout , stderr , stdin
251267
252268 def _read_output_buffer (self , output_buffer , prefix = '' ):
253269 """Read from output buffers and log to host_logger"""
0 commit comments