1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Add debug option to Fog::Compute::Server#ssh

keeps display logic in Fog::SSH::Result
This commit is contained in:
Gabriel Horner 2012-04-20 10:41:50 -04:00
parent 7ec382cf36
commit 1cf33ccc7a

View file

@ -42,6 +42,7 @@ module Fog
@address = address @address = address
@username = username @username = username
@debug = options.delete :debug
@options = { :paranoid => false }.merge(options) @options = { :paranoid => false }.merge(options)
end end
@ -51,7 +52,7 @@ module Fog
begin begin
Net::SSH.start(@address, @username, @options) do |ssh| Net::SSH.start(@address, @username, @options) do |ssh|
commands.each do |command| commands.each do |command|
result = Result.new(command) result = Result.new(command, @debug)
ssh.open_channel do |ssh_channel| ssh.open_channel do |ssh_channel|
ssh_channel.request_pty ssh_channel.request_pty
ssh_channel.exec(command) do |channel, success| ssh_channel.exec(command) do |channel, success|
@ -91,6 +92,15 @@ module Fog
end end
require 'delegate'
class DebugString < SimpleDelegator
def <<(add_me)
puts add_me
super
end
end
class Result class Result
attr_accessor :command, :stderr, :stdout, :status attr_accessor :command, :stderr, :stdout, :status
@ -108,10 +118,10 @@ module Fog
Formatador.display_line(stderr.split("\r\n")) Formatador.display_line(stderr.split("\r\n"))
end end
def initialize(command) def initialize(command, debug=false)
@command = command @command = command
@stderr = '' @stderr = debug ? DebugString.new('') : ''
@stdout = '' @stdout = debug ? DebugString.new('') : ''
end end
end end