Rfaulk has uploaded a new change for review. https://gerrit.wikimedia.org/r/83988
Change subject: add - ssh_command method. ...................................................................... add - ssh_command method. Change-Id: I6fb6a7464657afd00dd03eca364e12a9368df860 --- M sartoris/sartoris.py 1 file changed, 33 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/sartoris refs/changes/88/83988/1 diff --git a/sartoris/sartoris.py b/sartoris/sartoris.py index fb3db55..a3229a5 100755 --- a/sartoris/sartoris.py +++ b/sartoris/sartoris.py @@ -427,6 +427,39 @@ t.close() sock.close() + @staticmethod + def ssh_command(cmd, host, port, user, password, nbytes=1000): + + # Initialize connection + client = paramiko.Transport((host, port)) + client.connect(username=user, password=password) + + # Prepare stream lists, open session, exec command + stdout_data = [] + stderr_data = [] + session = client.open_channel(kind='session') + session.exec_command(cmd) + + # Read output + while True: + if session.recv_ready(): + stdout_data.append(session.recv(nbytes)) + if session.recv_stderr_ready(): + stderr_data.append(session.recv_stderr(nbytes)) + if session.exit_status_ready(): + break + + # Get exit status and close sessions + exit_status = session.recv_exit_status() + session.close() + client.close() + + return { + 'exit_status': exit_status, + 'stdout': ''.join(stdout_data), + 'stderr': ''.join(stderr_data), + } + def resync(self, args): """ * write a lock file -- To view, visit https://gerrit.wikimedia.org/r/83988 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6fb6a7464657afd00dd03eca364e12a9368df860 Gerrit-PatchSet: 1 Gerrit-Project: sartoris Gerrit-Branch: master Gerrit-Owner: Rfaulk <rfaulk...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits