diff options
author | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2017-04-12 14:45:42 +0000 |
---|---|---|
committer | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2017-04-12 14:45:42 +0000 |
commit | 970263d8c3b11703d8bcf9017295c0238f9e581b (patch) | |
tree | 348b4325e55b98a4a97f81bbfdf183135a8e27db | |
parent | 6d8d0d30d75b318650034470b376a57a37b57944 (diff) | |
parent | 0c23d2434138a203c48c239b36e3f5fe45276672 (diff) | |
download | rumba-970263d8c3b11703d8bcf9017295c0238f9e581b.tar.gz rumba-970263d8c3b11703d8bcf9017295c0238f9e581b.zip |
Merge branch 'vincenzo' into 'master'
Verbose SSH command output
See merge request !27
-rw-r--r-- | rumba/ssh_support.py | 39 |
1 files changed, 12 insertions, 27 deletions
diff --git a/rumba/ssh_support.py b/rumba/ssh_support.py index ad32d13..1faa34e 100644 --- a/rumba/ssh_support.py +++ b/rumba/ssh_support.py @@ -27,6 +27,13 @@ def get_ssh_client(): return ssh_client +def _print_stream(stream): + o = str(stream.read()).strip('b\'\"\\n') + if o != "": + o_array = o.split('\\n') + for oi in o_array: + print(oi) + def execute_commands(testbed, ssh_config, commands, time_out=3): ''' Remote execution of a list of shell command on hostname. By @@ -42,19 +49,15 @@ def execute_commands(testbed, ssh_config, commands, time_out=3): ssh_client = get_ssh_client() try: - #print("Connecting to %s@%s:%s (pwd=%s)" % (testbed.username, - # ssh_config.hostname, ssh_config.port, testbed.password)) ssh_client.connect(ssh_config.hostname, ssh_config.port, testbed.username, testbed.password, look_for_keys=True, timeout=time_out) for command in commands: + print("%s@%s:%s >> %s" % (testbed.username, + ssh_config.hostname, ssh_config.port, command)) stdin, stdout, stderr = ssh_client.exec_command(command) - del stdin, stdout - err = str(stderr.read()).strip('b\'\"\\n') - if err != "": - err_array = err.split('\\n') - for erra in err_array: - print(erra) + _print_stream(stdout) + _print_stream(stderr) ssh_client.close() except Exception as e: @@ -75,25 +78,7 @@ def execute_command(testbed, ssh_config, command, time_out=3): @return: stdout resulting from the command ''' - ssh_client = get_ssh_client() - - try: - ssh_client.connect(ssh_config.hostname, ssh_config.port, - testbed.username, testbed.password, - look_for_keys=True, timeout=time_out) - stdin, stdout, stderr = ssh_client.exec_command(command) - del stdin - err = str(stderr.read()).strip('b\'\"\\n') - if err != "": - print(err) - output = str(stdout.read()).strip('b\'\"\\n') - ssh_client.close() - - return output - - except Exception as e: - print(str(e)) - return + return execute_commands(testbed, ssh_config, [command], time_out) def copy_file_to_testbed(testbed, ssh_config, text, file_name): ''' |