Repository: libcloud Updated Branches: refs/heads/trunk 7845e08a9 -> 368ed715b
Move CHUNK_SIZE and add SLEEP_DELAY variable to the ParamikoSSHClient class. Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/368ed715 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/368ed715 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/368ed715 Branch: refs/heads/trunk Commit: 368ed715b0cf7f031aa2418e2cbf9a041a39c967 Parents: 7845e08 Author: Tomaz Muraus <[email protected]> Authored: Fri Mar 27 23:37:05 2015 +0100 Committer: Tomaz Muraus <[email protected]> Committed: Fri Mar 27 23:37:05 2015 +0100 ---------------------------------------------------------------------- libcloud/compute/ssh.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/368ed715/libcloud/compute/ssh.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/ssh.py b/libcloud/compute/ssh.py index 7f4719c..427e133 100644 --- a/libcloud/compute/ssh.py +++ b/libcloud/compute/ssh.py @@ -51,10 +51,6 @@ __all__ = [ ] -# Maximum number of bytes to read at once from a socket -CHUNK_SIZE = 1024 - - class SSHCommandTimeoutError(Exception): """ Exception which is raised when an SSH command times out. @@ -199,10 +195,15 @@ class BaseSSHClient(object): class ParamikoSSHClient(BaseSSHClient): - """ A SSH Client powered by Paramiko. """ + + # Maximum number of bytes to read at once from a socket + CHUNK_SIZE = 1024 + # How long to sleep while waiting for command to finish + SLEEP_DELAY = 1.5 + def __init__(self, hostname, port=22, username='root', password=None, key=None, key_files=None, key_material=None, timeout=None): """ @@ -362,7 +363,7 @@ class ParamikoSSHClient(BaseSSHClient): raise SSHCommandTimeoutError(cmd=cmd, timeout=timeout) if chan.recv_ready(): - data = chan.recv(CHUNK_SIZE) + data = chan.recv(self.CHUNK_SIZE) while data: stdout.write(b(data).decode('utf-8')) @@ -371,10 +372,10 @@ class ParamikoSSHClient(BaseSSHClient): if not ready: break - data = chan.recv(CHUNK_SIZE) + data = chan.recv(self.CHUNK_SIZE) if chan.recv_stderr_ready(): - data = chan.recv_stderr(CHUNK_SIZE) + data = chan.recv_stderr(self.CHUNK_SIZE) while data: stderr.write(b(data).decode('utf-8')) @@ -383,7 +384,7 @@ class ParamikoSSHClient(BaseSSHClient): if not ready: break - data = chan.recv_stderr(CHUNK_SIZE) + data = chan.recv_stderr(self.CHUNK_SIZE) # We need to check the exist status here, because the command could # print some output and exit during this sleep bellow. @@ -393,7 +394,7 @@ class ParamikoSSHClient(BaseSSHClient): break # Short sleep to prevent busy waiting - time.sleep(1.5) + time.sleep(self.SLEEP_DELAY) # Receive the exit status code of the command we ran. status = chan.recv_exit_status()
