"""
from __future__ import absolute_import
import os
+import io
import select
import socket
import time
from yardstick.network_services.utils import provision_tool
+def convert_key_to_str(key):
+ if not isinstance(key, (paramiko.RSAKey, paramiko.DSSKey)):
+ return key
+ k = io.StringIO()
+ key.write_private_key(k)
+ return k.getvalue()
+
+
class SSHError(Exception):
pass
if mode is not None:
sftp.chmod(remotepath, mode)
+ def get_file_obj(self, remotepath, file_obj):
+ client = self._get_client()
+
+ with client.open_sftp() as sftp:
+ sftp.getfo(remotepath, file_obj)
+
class AutoConnectSSH(SSH):
+ # always wait or we will get OpenStack SSH errors
def __init__(self, user, host, port=None, pkey=None,
- key_filename=None, password=None, name=None, wait=False):
+ key_filename=None, password=None, name=None, wait=True):
super(AutoConnectSSH, self).__init__(user, host, port, pkey, key_filename, password, name)
self._wait = wait
self._connect()
return super(AutoConnectSSH, self).put_file_obj(file_obj, remote_path, mode)
+ def get_file_obj(self, remote_path, file_obj):
+ self._connect()
+ return super(AutoConnectSSH, self).get_file_obj(remote_path, file_obj)
+
def provision_tool(self, tool_path, tool_file=None):
self._connect()
return super(AutoConnectSSH, self).provision_tool(tool_path, tool_file)