diff options
author | Marco Capitani <m.capitani@nextworks.it> | 2017-11-16 16:59:04 +0100 |
---|---|---|
committer | Sander Vrijders <sander.vrijders@ugent.be> | 2017-11-17 15:17:31 +0000 |
commit | 38e25070ab5e5b74917797f9049dd226afeb9728 (patch) | |
tree | 219891c01f85a6c4c8da13c6f247e7230282bad7 /rumba/ssh_support.py | |
parent | 9d21bf51eb1765e0bdb15ef3d8b8700327bf2f66 (diff) | |
download | rumba-38e25070ab5e5b74917797f9049dd226afeb9728.tar.gz rumba-38e25070ab5e5b74917797f9049dd226afeb9728.zip |
storyboard: add logging and log retrieval
Diffstat (limited to 'rumba/ssh_support.py')
-rw-r--r-- | rumba/ssh_support.py | 57 |
1 files changed, 55 insertions, 2 deletions
diff --git a/rumba/ssh_support.py b/rumba/ssh_support.py index fbe68c8..1a065c6 100644 --- a/rumba/ssh_support.py +++ b/rumba/ssh_support.py @@ -26,6 +26,7 @@ import os import paramiko +import re import time import rumba.log as log @@ -53,12 +54,15 @@ def get_ssh_client(): def _print_stream(stream): o = str(stream.read()).strip('b') o = o.strip('\'\"') - o = o.replace('\\n', '') + o = o.rstrip() + o = re.sub(r'(\\n)*$', '', o) if o != "": o_array = o.split('\\n') for oi in o_array: logger.debug(oi) - return o.rstrip() + else: + o_array = [] + return '\n'.join(o_array) def ssh_connect(hostname, port, username, password, time_out, proxy_server): logger.debug('Trying to open a connection towards node %s.' % hostname) @@ -300,6 +304,55 @@ def copy_file_to_testbed(testbed, ssh_config, path, destination): copy_files_to_testbed(testbed, ssh_config, [path], destination) +def copy_files_from_testbed(testbed, ssh_config, paths, destination): + """ + Copies local files to a remote node. + + @param testbed: testbed info + @param ssh_config: ssh config of the node + @param paths: source paths (remote) as an iterable + @param destination: destination folder name (local) + """ + if destination is not '' and not destination.endswith('/'): + destination = destination + '/' + + if ssh_config.client is None: + client, proxy_client = ssh_connect(ssh_config.hostname, ssh_config.port, + testbed.username, testbed.password, + None, ssh_config.proxy_server) + ssh_config.client = client + ssh_config.proxy_client = proxy_client + + try: + sftp_client = ssh_config.client.open_sftp() + + for path in paths: + file_name = os.path.basename(path) + dest_file = destination + file_name + logger.debug("Copying %s to %s@%s:%s path %s" % ( + path, + testbed.username, + ssh_config.hostname, + ssh_config.port, + dest_file)) + sftp_client.get(path, dest_file) + + except Exception as e: + raise SSHException('Failed to copy files from testbed', e) + + +def copy_file_from_testbed(testbed, ssh_config, path, destination): + """ + Copies a local file to a remote node. + + @param testbed: testbed info + @param ssh_config: ssh config of the node + @param path: source path (remote) + @param destination: destination folder name (local) + """ + copy_files_from_testbed(testbed, ssh_config, [path], destination) + + def setup_vlans(testbed, node, vlans): """ Gets the interface (ethx) to link mapping |