Module: Toss::Ssh::InstanceMethods
- Defined in:
- lib/toss/ssh.rb
Instance Method Summary collapse
- #close_sessions ⇒ Object
- #open_sessions ⇒ Object
- #ssh_exec!(ssh, command) ⇒ Object
- #start_session(server) ⇒ Object
Instance Method Details
#close_sessions ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/toss/ssh.rb', line 20 def close_sessions open_sessions.each.each do |target_host,session| puts "Closing ssh session for #{target_host}" session.close open_sessions.delete(target_host) end end |
#open_sessions ⇒ Object
10 11 12 |
# File 'lib/toss/ssh.rb', line 10 def open_sessions @open_sessions ||= {} end |
#ssh_exec!(ssh, command) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/toss/ssh.rb', line 28 def ssh_exec!(ssh, command) stdout_data = "" stderr_data = "" exit_code = nil exit_signal = nil ssh.open_channel do |channel| channel.exec(command) do |ch, success| unless success abort "FAILED: couldn't execute command (ssh.channel.exec)" end channel.on_data do |ch,data| stdout_data+=data end channel.on_extended_data do |ch,type,data| stderr_data+=data end channel.on_request("exit-status") do |ch,data| exit_code = data.read_long end channel.on_request("exit-signal") do |ch, data| exit_signal = data.read_long end end end ssh.loop [stdout_data, stderr_data, exit_code, exit_signal] end |
#start_session(server) ⇒ Object
14 15 16 17 18 |
# File 'lib/toss/ssh.rb', line 14 def start_session(server) puts "Starting ssh session to #{server.host}" open_sessions[server.host] = Net::SSH.start(server.host, server.user, :password => server.password) open_sessions[server.host] end |