From 99dcdf01ffcca6e35b9bae925384ceebd3a14bde Mon Sep 17 00:00:00 2001 From: Richard Bronkhorst Date: Fri, 4 May 2012 14:11:44 +0200 Subject: [PATCH 1/4] allow EM::Ssh::Shell.new to use :port, :verbose and :auth_methods options --- lib/em-ssh.rb | 12 ++++++++++-- lib/em-ssh/shell.rb | 5 ++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/em-ssh.rb b/lib/em-ssh.rb index 0ed838a..eff007f 100644 --- a/lib/em-ssh.rb +++ b/lib/em-ssh.rb @@ -49,8 +49,16 @@ def logger(level = Logger::WARN) # log.debug "**** channel: #{channel}" # channel.request_pty(options[:pty] || {}) do |pty,suc| def connect(host, user, opts = {}, &blk) - logger.debug("#{self}.connect(#{host}, #{user}, #{opts})") - options = { :host => host, :user => user, :port => DEFAULT_PORT }.merge(opts) + level = case opts[:verbose] + when :debug then Logger::DEBUG + when :info then Logger::INFO + when :warn then Logger::WARN + when :error then Logger::ERROR + when :fatal then Logger::FATAL + else Logger::WARN + end + logger(level).debug("#{self}.connect(#{host}, #{user}, #{opts})") + options = { :host => host, :user => user, :port => DEFAULT_PORT, :logger => logger}.merge(opts) EM.connect(options[:host], options[:port], Connection, options, &blk) end alias :start :connect diff --git a/lib/em-ssh/shell.rb b/lib/em-ssh/shell.rb index 0bc9cc1..11ebc7b 100644 --- a/lib/em-ssh/shell.rb +++ b/lib/em-ssh/shell.rb @@ -68,7 +68,10 @@ def initialize(address, user, pass, opts = {}, &blk) @user = user @pass = pass @options = opts - @connect_opts = {:password => pass, :port => 22, :auth_methods => ['publickey', 'password']}.merge(opts[:net_ssh] || {}) + @port = opts[:port] || 22 + @auth_methods = opts[:auth_methods] || ['publickey', 'password'] + @verbose = opts[:verbose] || :debug + @connect_opts = {:password => pass, :port => @port, :auth_methods => @auth_methods, :verbose => @verbose}.merge(opts[:net_ssh] || {}) @connection = opts[:connection] @parent = opts[:parent] @children = [] From 4afe386193d1e790899413a63d255410d0ffd5d6 Mon Sep 17 00:00:00 2001 From: Richard Bronkhorst Date: Fri, 4 May 2012 14:12:56 +0200 Subject: [PATCH 2/4] fix double resume issue on connection error in EM::Ssh::Shell --- lib/em-ssh/shell.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/em-ssh/shell.rb b/lib/em-ssh/shell.rb index 11ebc7b..e91ea5b 100644 --- a/lib/em-ssh/shell.rb +++ b/lib/em-ssh/shell.rb @@ -263,7 +263,6 @@ def connect connection.errback do |e| e.set_backtrace(trace + Array(e.backtrace)) fire(:error, e) - f.resume(e) end # err end return Fiber.yield From f077397e7ae4ed44d005b48b4781ed4622971527 Mon Sep 17 00:00:00 2001 From: Richard Bronkhorst Date: Fri, 4 May 2012 14:23:25 +0200 Subject: [PATCH 3/4] set default verbosity to warn --- lib/em-ssh/shell.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/em-ssh/shell.rb b/lib/em-ssh/shell.rb index e91ea5b..2a39700 100644 --- a/lib/em-ssh/shell.rb +++ b/lib/em-ssh/shell.rb @@ -70,7 +70,7 @@ def initialize(address, user, pass, opts = {}, &blk) @options = opts @port = opts[:port] || 22 @auth_methods = opts[:auth_methods] || ['publickey', 'password'] - @verbose = opts[:verbose] || :debug + @verbose = opts[:verbose] || :warn @connect_opts = {:password => pass, :port => @port, :auth_methods => @auth_methods, :verbose => @verbose}.merge(opts[:net_ssh] || {}) @connection = opts[:connection] @parent = opts[:parent] From 849c5ec8cbd3476473c83f07a4007125586ce87e Mon Sep 17 00:00:00 2001 From: Richard Bronkhorst Date: Mon, 7 May 2012 12:56:49 +0200 Subject: [PATCH 4/4] override standard logger --- lib/em-ssh.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/em-ssh.rb b/lib/em-ssh.rb index eff007f..7ede41d 100644 --- a/lib/em-ssh.rb +++ b/lib/em-ssh.rb @@ -57,6 +57,7 @@ def connect(host, user, opts = {}, &blk) when :fatal then Logger::FATAL else Logger::WARN end + @logger = ::Logger.new(STDERR).tap{ |l| l.level = level } logger(level).debug("#{self}.connect(#{host}, #{user}, #{opts})") options = { :host => host, :user => user, :port => DEFAULT_PORT, :logger => logger}.merge(opts) EM.connect(options[:host], options[:port], Connection, options, &blk)