Don't close paramiko SFTP multiple times in the same runner pass. Noticeable performance increase.

pull/1648/head
Michael DeHaan 12 years ago
parent 8b50ad7e85
commit 4c83c274e0

@ -135,29 +135,29 @@ class Connection(object):
if not os.path.exists(in_path): if not os.path.exists(in_path):
raise errors.AnsibleFileNotFound("file or module does not exist: %s" % in_path) raise errors.AnsibleFileNotFound("file or module does not exist: %s" % in_path)
try: try:
sftp = self.ssh.open_sftp() self.sftp = self.ssh.open_sftp()
except: except:
raise errors.AnsibleError("failed to open a SFTP connection") raise errors.AnsibleError("failed to open a SFTP connection")
try: try:
sftp.put(in_path, out_path) self.sftp.put(in_path, out_path)
except IOError: except IOError:
raise errors.AnsibleError("failed to transfer file to %s" % out_path) raise errors.AnsibleError("failed to transfer file to %s" % out_path)
sftp.close()
def fetch_file(self, in_path, out_path): def fetch_file(self, in_path, out_path):
''' save a remote file to the specified path ''' ''' save a remote file to the specified path '''
vvv("FETCH %s TO %s" % (in_path, out_path), host=self.host) vvv("FETCH %s TO %s" % (in_path, out_path), host=self.host)
try: try:
sftp = self.ssh.open_sftp() self.sftp = self.ssh.open_sftp()
except: except:
raise errors.AnsibleError("failed to open a SFTP connection") raise errors.AnsibleError("failed to open a SFTP connection")
try: try:
sftp.get(in_path, out_path) self.sftp.get(in_path, out_path)
except IOError: except IOError:
raise errors.AnsibleError("failed to transfer file from %s" % in_path) raise errors.AnsibleError("failed to transfer file from %s" % in_path)
sftp.close()
def close(self): def close(self):
''' terminate the connection ''' ''' terminate the connection '''
if self.sftp is not None:
self.sftp.close()
self.ssh.close() self.ssh.close()

Loading…
Cancel
Save