woolen_common 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9bfcc3f0af04c4a4230d16193e1d818c0c41413e
4
- data.tar.gz: aa47e53628f6b73da3d28c891b3a7c0b63684cac
3
+ metadata.gz: 4aeb6013d053af960f118edcd50414ed21b10ea1
4
+ data.tar.gz: fbf8e57654e519f7602adc9bd6b5b136b2cf2d6b
5
5
  SHA512:
6
- metadata.gz: e1bf4e00f194ec67ec1e437c6ab401fa3178a95c6e90d4b78cc5283e294ca65a320d03947aab0aba0041d85c87b48bd09072a466cafd926f756c9a8b6f984483
7
- data.tar.gz: 52fef77f9c5c1ac560c0fb93efc7646edd77435248d2cd0fd7563d682e1eda7af82f96655d90109b4a129aaa5a59487d32c581083e3b49b0828710af9d14c61d
6
+ metadata.gz: c55cea41a15a9d15948873ae0628c581d8b55a3d1bfdf187afe19862ccbcaba30483c57ad6b80b624422bffafb70903fdf9cfbc274abb84d30646a657b74e642
7
+ data.tar.gz: 561ea2799300a3b7bb891b3e86391683e7b8d153cd3659f5d39e1bfb2b4f88a625891b3ffe1f24c6d3dcf1afc8671aaf9b8e7041bf514d86bb75b726e43c9711
@@ -2,11 +2,60 @@
2
2
  begin
3
3
  require 'net/ssh' rescue nil
4
4
  require 'net/sftp' rescue nil
5
+ require 'connection_pool'
5
6
  require "#{File.join(File.dirname(__FILE__), 'logger')}"
6
7
  module WoolenCommon
8
+ class SshProxyPool
9
+ include WoolenCommon::ToolLogger
10
+
11
+ class << self
12
+ attr_accessor :the_ssh_instances
13
+ def get_ssh_proxy(ip, user, password, port=22, max_ssh=10, time_out=10)
14
+ @the_ssh_instances ||= {}
15
+ @the_ssh_instances[ip] ||= {}
16
+ @the_ssh_instances[ip][port] ||= {}
17
+ @the_ssh_instances[ip][port][user] ||= {}
18
+ @the_ssh_instances[ip][port][user][password] ||= self.new(ip, user, password, port=22, max_ssh=10, time_out=10)
19
+ @the_ssh_instances[ip][port][user][password]
20
+ end
21
+ end
22
+
23
+ def initialize(ip, user, password, port=22, max_ssh=10, time_out=10)
24
+ debug "ssh setup : [ user::#{user},password::#{password},port:#{port} ]"
25
+ @ip = ip
26
+ @user = user
27
+ @password = password
28
+ @port = port
29
+ @max_ssh = max_ssh
30
+ @time_out = time_out
31
+ get_pool
32
+ end
33
+
34
+ def get_pool
35
+ @ssh_connection_pool ||= ::ConnectionPool.new({:size => @max_ssh, :timeout => @time_out}) do
36
+ debug "ip:#{@ip},@password:#{@password},@port:#{@port}"
37
+ ::WoolenCommon::SshProxy.new(@ip, @user, :password => @password, :port => @port)
38
+ end
39
+ end
40
+
41
+ def method_missing(method, *args, &block)
42
+ debug "need to invoke ssh method ::#{method} #{args}"
43
+ self.instance_eval <<-THE_END
44
+ def #{method}(*args,&block)
45
+ trace "need to invoke ssh method ::#{method} \#{args}"
46
+ get_pool.with do |ssh_conn|
47
+ return ssh_conn.send :#{method}, *args, &block
48
+ end
49
+ end
50
+ THE_END
51
+ self.send method, *args, &block
52
+ end
53
+ end
54
+
7
55
  class SshProxy
8
- include ToolLogger
56
+ include WoolenCommon::ToolLogger
9
57
  class << self
58
+
10
59
  attr_accessor :the_ssh_instances
11
60
  def get_ssh_proxy(ip,port,user,passwd)
12
61
  options = {:port => port,:password => passwd}
@@ -1,3 +1,3 @@
1
1
  module WoolenCommon
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: woolen_common
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - just_woolen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-24 00:00:00.000000000 Z
11
+ date: 2017-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: connection_pool
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: The common helper for dev in ruby
70
84
  email:
71
85
  - just_woolen@qq.com