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 +4 -4
- data/lib/woolen_common/ssh_proxy.rb +50 -1
- data/lib/woolen_common/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4aeb6013d053af960f118edcd50414ed21b10ea1
|
4
|
+
data.tar.gz: fbf8e57654e519f7602adc9bd6b5b136b2cf2d6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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}
|
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.
|
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:
|
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
|