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

Merge pull request #926 from freeformz/ssh_block

ssh/run optionally takes a block
This commit is contained in:
Dan Peterson 2012-05-23 15:55:46 -07:00
commit 851e838d46
2 changed files with 6 additions and 4 deletions

View file

@ -28,12 +28,12 @@ module Fog
Fog::SCP.new(public_ip_address, username, scp_options).download(remote_path, local_path, download_options) Fog::SCP.new(public_ip_address, username, scp_options).download(remote_path, local_path, download_options)
end end
def ssh(commands, options={}) def ssh(commands, options={}, &blk)
require 'net/ssh' require 'net/ssh'
requires :public_ip_address, :username requires :public_ip_address, :username
options[:key_data] = [private_key] if private_key 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
def sshable? def sshable?

View file

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