Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Minor cleanup

  • Loading branch information...
commit 47df82bfce465c4576cf4e4b7fa204e69f5d30ae 1 parent e81c6c4
@m-o-e m-o-e authored
Showing with 18 additions and 11 deletions.
  1. +1 −0  .gitignore
  2. +15 −9 lib/net/ssh/simple/core.rb
  3. +2 −2 net-ssh-simple.gemspec
View
1  .gitignore
@@ -5,3 +5,4 @@ pkg/*
.yardoc
coverage.data
coverage
+sync
View
24 lib/net/ssh/simple/core.rb
@@ -1,3 +1,4 @@
+require 'timeout'
module Net
module SSH
# Net::SSH::Simple is a simple wrapper around Net::SSH and Net::SCP.
@@ -229,9 +230,9 @@ class Simple
# @param (see Net::SSH::Simple#ssh)
# @raise [Net::SSH::Simple::Error]
# @return [Net::SSH::Simple::Result] Result
- def self.ssh(*args)
+ def self.ssh(*args, &block)
s = self.new
- r = s.ssh(*args)
+ r = s.ssh(*args, &block)
s.close
r
end
@@ -500,9 +501,9 @@ def self.async(&block)
# @return [Net::SSH::Simple::Result] Result
#
def self.sync(&block)
- b = self.new
- r = Blockenspiel.invoke(block, b)
- b.close
+ s = self.new
+ r = Blockenspiel.invoke(block, s)
+ s.close
r
end
@@ -519,15 +520,20 @@ def close
end
private
- def with_session(host, opts, &block)
+ def with_session(host, opts={:timeout => 60}, &block)
begin
- session = @sessions[host.hash] = @sessions[host.hash] ||\
- Net::SSH.start(*[host, opts[:user], opts])
- block.call(session)
+ Timeout.timeout(opts[:timeout]) do
+ session = @sessions[host.hash] = @sessions[host.hash] ||\
+ Net::SSH.start(*[host, opts[:user], opts])
+ block.call(session)
+ end
rescue => e
opts[:password].gsub!(/./,'*') if opts.include? :password
@result[:exception] = e
@result[:context] = [host,opts]
+ @result[:success] = false
+ @result[:timed_out] = true
+ @result[:finish_at] = Time.new
raise Net::SSH::Simple::Error, [e, [host,opts]]
end
end
View
4 net-ssh-simple.gemspec
@@ -11,14 +11,14 @@ Gem::Specification.new do |s|
s.description = %q{Net::SSH::Simple is a simple wrapper around Net::SSH and Net::SCP.}
s.summary = %q{SSH without the headache}
- s.rubyforge_project = "net-ssh-simple"
+ s.required_ruby_version = '>= 1.9.2'
s.add_dependency "net-ssh", "~> 2.1.4"
s.add_dependency "net-scp", "~> 1.0.4"
s.add_dependency "blockenspiel", "~> 0.4.3"
s.add_dependency "hashie", "~> 1.1.0"
- s.add_development_dependency "rake"
+ s.add_development_dependency "rake", "~> 0.9.2.2"
s.add_development_dependency "rspec"
s.add_development_dependency "cover_me"
Please sign in to comment.
Something went wrong with that request. Please try again.