class WoolenCommon::SshProxyPool

Attributes

the_ssh_instances[RW]

Public Class Methods

get_ssh_proxy(ip, user, password, port=22, max_ssh=10, time_out=10) click to toggle source
# File lib/woolen_common/ssh_proxy.rb, line 13
def get_ssh_proxy(ip, user, password, port=22, max_ssh=10, time_out=10)
  @the_ssh_instances ||= {}
  @the_ssh_instances[ip] ||= {}
  @the_ssh_instances[ip][port] ||= {}
  @the_ssh_instances[ip][port][user] ||= {}
  @the_ssh_instances[ip][port][user][password] ||= self.new(ip, user, password, port, max_ssh, time_out)
  @the_ssh_instances[ip][port][user][password]
end
new(ip, user, password, port=22, max_ssh=10, time_out=10) click to toggle source
# File lib/woolen_common/ssh_proxy.rb, line 23
def initialize(ip, user, password, port=22, max_ssh=10, time_out=10)
  debug "ssh setup : [ user::#{user},password::#{password},port:#{port}, time_out #{time_out} ]"
  @ip = ip
  @user = user
  @password = password
  @port = port
  @max_ssh = max_ssh
  @time_out = time_out
  get_pool
end

Public Instance Methods

get_pool() click to toggle source
# File lib/woolen_common/ssh_proxy.rb, line 34
def get_pool
  @ssh_connection_pool ||= ::WoolenCommon::ConnectionPool.new({ :size => @max_ssh, :timeout => @time_out }) do
    debug "ip:#{@ip},@password:#{@password},@port:#{@port}"
    ::WoolenCommon::SshProxy.new(@ip, @user, :password => @password, :port => @port, :proxy_conn_timeout => @time_out)
  end
end
method_missing(method, *args, &block) click to toggle source
# File lib/woolen_common/ssh_proxy.rb, line 41
      def method_missing(method, *args, &block)
        debug "need to invoke ssh method ::#{method} #{args}"
        self.instance_eval <<-THE_END
                    def #{method}(*args,&block)
                        trace "need to invoke ssh method ::#{method} \#{args}"
                        get_pool.with do |ssh_conn|
                            return ssh_conn.send :#{method}, *args, &block
                        end
                    end
        THE_END
        self.send method, *args, &block
      end