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

ssh/run optionally takes a block

and yields [STDOUT, STDERR]

Useful if you need real-timeish output
This commit is contained in:
Edward Muller 2012-05-23 15:28:02 -07:00
parent 3e24a47710
commit eb1763d61e
2 changed files with 6 additions and 4 deletions

View file

@ -24,12 +24,12 @@ module Fog
Fog::SCP.new(public_ip_address, username, scp_options).download(remote_path, local_path, download_options)
end
def ssh(commands, options={})
def ssh(commands, options={}, &blk)
require 'net/ssh'
requires :public_ip_address, :username
options[:key_data] = [private_key] if private_key
Fog::SSH.new(public_ip_address, username, options).run(commands)
Fog::SSH.new(public_ip_address, username, options).run(commands, &blk)
end
end

View file

@ -29,7 +29,7 @@ module Fog
@options = options
end
def run(commands)
def run(commands, &blk)
self.class.data[@address] << {:commands => commands, :username => @username, :options => @options}
end
@ -52,7 +52,7 @@ module Fog
@options = { :paranoid => false }.merge(options)
end
def run(commands)
def run(commands, &blk)
commands = [*commands]
results = []
begin
@ -68,11 +68,13 @@ module Fog
channel.on_data do |ch, data|
result.stdout << data
yield [data, nil] if blk
end
channel.on_extended_data do |ch, type, data|
next unless type == 1
result.stderr << data
yield [nil, data] if blk
end
channel.on_request('exit-status') do |ch, data|