diff options
Diffstat (limited to 'rumba/ssh_support.py')
-rw-r--r-- | rumba/ssh_support.py | 65 |
1 files changed, 19 insertions, 46 deletions
diff --git a/rumba/ssh_support.py b/rumba/ssh_support.py index cfe8c26..5d62b81 100644 --- a/rumba/ssh_support.py +++ b/rumba/ssh_support.py @@ -156,51 +156,6 @@ def ssh_sftp(ssh_config, testbed): chan.invoke_subsystem("sftp") return paramiko.sftp_client.SFTPClient(chan) -def execute_proxy_commands(testbed, ssh_config, commands, time_out=3): - """ - Remote execution of a list of shell command on hostname, using the - http and https proxy specified by the testbed. By - default this function will exit (timeout) after 3 seconds. - - @param testbed: testbed info - @param ssh_config: ssh config of the node - @param commands: *nix shell command - @param time_out: time_out value in seconds, error will be generated if - no result received in given number of seconds, the value None can - be used when no timeout is needed - """ - new_commands = [] - for command in commands: - proxy = testbed.http_proxy - if proxy is not None: - proxy_command = 'export http_proxy=' + proxy + '; ' \ - + 'export https_proxy=' + proxy + ';' - new_commands.append(proxy_command + ' ' + command) - else: - new_commands.append(command) - return execute_commands(testbed, ssh_config, new_commands, time_out) - - -def execute_proxy_command(testbed, ssh_config, command, time_out=3): - """ - Remote execution of a list of shell command on hostname, using - a proxy http and https. - By default this function will exit (timeout) after 3 seconds. - - @param testbed: testbed info - @param ssh_config: ssh config of the node - @param command: *nix shell command - @param time_out: time_out value in seconds, error will be generated if - no result received in given number of seconds, the value None can - be used when no timeout is needed - - @return: stdout resulting from the command - """ - o = execute_proxy_commands(testbed, ssh_config, [command], time_out) - if o is not None: - return o - - def execute_commands(testbed, ssh_config, commands, time_out=3): """ Remote execution of a list of shell command on hostname. By @@ -457,4 +412,22 @@ def aptitude_install(testbed, node, packages): "while ! " + sudo("apt-get update") + "; do sleep 1; done", "while ! " + sudo(package_install) + "; do sleep 1; done"] - execute_proxy_commands(testbed, node.ssh_config, cmds, time_out=None) + execute_commands(testbed, node.ssh_config, cmds, time_out=None) + +def set_http_proxy(testbed, node, proxy): + """ + Sets a system-wide HTTP proxy for a node. + + @param testbed: testbed info + @param node: the node + """ + + proxies = [] + proxies.append('export http_proxy="' + proxy + '"') + proxies.append('export https_proxy="' + proxy + '"') + + cmds = [] + for line in proxies: + cmds.append('echo \''+ line + '\' | sudo tee --append /etc/profile') + + execute_commands(testbed, node.ssh_config, cmds, time_out=None) |