aboutsummaryrefslogtreecommitdiff
path: root/rumba/ssh_support.py
diff options
context:
space:
mode:
authorMarco Capitani <m.capitani@nextworks.it>2018-02-21 11:47:43 +0100
committerMarco Capitani <m.capitani@nextworks.it>2018-02-27 16:51:26 +0100
commite6af5e64b850be64d5e1d1012e890ca9571b0df0 (patch)
tree60ef94a76aea5bd4fec5843a573cc040aa2211d1 /rumba/ssh_support.py
parent0158b68b1736ca8a5fb68de5a56cae234030774c (diff)
downloadrumba-e6af5e64b850be64d5e1d1012e890ca9571b0df0.tar.gz
rumba-e6af5e64b850be64d5e1d1012e890ca9571b0df0.zip
utils & storyboard: add syslog retrieval functionality
Implements #39. Also updated examples.
Diffstat (limited to 'rumba/ssh_support.py')
-rw-r--r--rumba/ssh_support.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/rumba/ssh_support.py b/rumba/ssh_support.py
index 69c049c..98caca2 100644
--- a/rumba/ssh_support.py
+++ b/rumba/ssh_support.py
@@ -37,12 +37,14 @@ try:
except NameError:
pass
+
logger = log.get_logger(__name__)
class SSHException(Exception):
pass
+
def get_ssh_client():
ssh_client = paramiko.SSHClient()
ssh_client.load_system_host_keys()
@@ -64,6 +66,7 @@ def _print_stream(stream):
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)
retry = 0
@@ -97,7 +100,7 @@ def ssh_connect(hostname, port, username, password, time_out, proxy_server):
logger.error('If you are sure this is not a man in the ' +
'middle attack, edit that file to remove the ' +
'entry and then hit return to try again.')
- input()
+ input('Key mismatch detected. Press ENTER when ready.')
except (paramiko.ssh_exception.SSHException, EOFError):
retry += 1
logger.error('Failed to connect to host, retrying: ' +
@@ -105,6 +108,7 @@ def ssh_connect(hostname, port, username, password, time_out, proxy_server):
if retry == max_retries:
raise SSHException('Failed to connect to host')
+
def execute_proxy_commands(testbed, ssh_config, commands, time_out=3):
"""
Remote execution of a list of shell command on hostname, using the
@@ -202,6 +206,7 @@ def execute_commands(testbed, ssh_config, commands, time_out=3):
'\n\t'.join(list_print) + '\n')
return o
+
def execute_command(testbed, ssh_config, command, time_out=3):
"""
Remote execution of a list of shell command on hostname. By
@@ -256,6 +261,7 @@ def write_text_to_file(testbed, ssh_config, text, file_name):
except SSHException as e:
raise SSHException('Failed to write text to remote file')
+
def copy_files_to_testbed(testbed, ssh_config, paths, destination):
"""
Copies local files to a remote node.
@@ -292,6 +298,7 @@ def copy_files_to_testbed(testbed, ssh_config, paths, destination):
except Exception as e:
raise SSHException('Failed to copy files to testbed')
+
def copy_file_to_testbed(testbed, ssh_config, path, destination):
"""
Copies a local file to a remote node.
@@ -304,7 +311,8 @@ 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):
+def copy_files_from_testbed(testbed, ssh_config, paths,
+ destination, sudo=False):
"""
Copies local files to a remote node.
@@ -312,10 +320,15 @@ def copy_files_from_testbed(testbed, ssh_config, paths, destination):
@param ssh_config: ssh config of the node
@param paths: source paths (remote) as an iterable
@param destination: destination folder name (local)
+ @param sudo: if path to copy requires root access, should be set to true
"""
if destination is not '' and not destination.endswith('/'):
destination = destination + '/'
+ if sudo:
+ execute_command(testbed, ssh_config,
+ 'sudo chmod a+rw %s' % (" ".join(paths)))
+
if ssh_config.client is None:
client, proxy_client = ssh_connect(ssh_config.hostname, ssh_config.port,
testbed.username, testbed.password,
@@ -341,7 +354,8 @@ def copy_files_from_testbed(testbed, ssh_config, paths, destination):
raise SSHException('Failed to copy files from testbed', e)
-def copy_file_from_testbed(testbed, ssh_config, path, destination):
+def copy_file_from_testbed(testbed, ssh_config, path,
+ destination, sudo=False):
"""
Copies a local file to a remote node.
@@ -349,8 +363,9 @@ def copy_file_from_testbed(testbed, ssh_config, path, destination):
@param ssh_config: ssh config of the node
@param path: source path (remote)
@param destination: destination folder name (local)
+ @param sudo: if path to copy requires root access, should be set to true
"""
- copy_files_from_testbed(testbed, ssh_config, [path], destination)
+ copy_files_from_testbed(testbed, ssh_config, [path], destination, sudo)
def setup_vlans(testbed, node, vlans):