xlogin 0.14.5 → 0.15.0
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/xlogin.rb +1 -3
- data/lib/xlogin/factory.rb +23 -15
- data/lib/xlogin/session_pool.rb +14 -19
- data/lib/xlogin/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cda6f2be936220ffb49b9d586d0e8ebcd248194bb0d16b7bc595ab3209da42da
|
4
|
+
data.tar.gz: 484a16a9c5f1e3eaa9d65f85de52e634ffb29a6b4e66f5461385c1f29c115ae6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0562b0ad712a00b3b2dd8d36b43c3fc15f1435492f9c025e374c52a1a92495575667476dfe1e679a57a6f396b5eba0bad2341d56c0a36454e70ff7737c656ac8
|
7
|
+
data.tar.gz: 716231e8c898ebb0d10b85a58c422f9815361e9c4303c803f2ca40c80fd83e957cd135b3f2db920ec12468e04e42d25f3c5b0213120e149451a62535b218b71b
|
data/lib/xlogin.rb
CHANGED
@@ -40,15 +40,13 @@ module Xlogin
|
|
40
40
|
return session unless block
|
41
41
|
begin block.call(session) ensure session.close end
|
42
42
|
end
|
43
|
-
alias_method :create, :get
|
44
43
|
|
45
|
-
def
|
44
|
+
def pool(args, **opts, &block)
|
46
45
|
pool = factory.build_pool(args, **opts)
|
47
46
|
|
48
47
|
return pool unless block
|
49
48
|
begin block.call(pool) ensure pool.close end
|
50
49
|
end
|
51
|
-
alias_method :create_pool, :get_pool
|
52
50
|
|
53
51
|
def configure(&block)
|
54
52
|
instance_eval(&block)
|
data/lib/xlogin/factory.rb
CHANGED
@@ -13,7 +13,7 @@ module Xlogin
|
|
13
13
|
def initialize
|
14
14
|
@inventory = Hash.new
|
15
15
|
@templates = Hash.new
|
16
|
-
@
|
16
|
+
@tunnels = Hash.new
|
17
17
|
@mutex = Mutex.new
|
18
18
|
end
|
19
19
|
|
@@ -54,32 +54,40 @@ module Xlogin
|
|
54
54
|
@templates.keys
|
55
55
|
end
|
56
56
|
|
57
|
-
def open_tunnel(
|
57
|
+
def open_tunnel(name, host, port)
|
58
58
|
@mutex.synchronize do
|
59
|
-
unless @
|
60
|
-
|
61
|
-
case
|
59
|
+
unless @tunnels[name]
|
60
|
+
uri = Addressable::URI.parse(name)
|
61
|
+
case uri.scheme
|
62
62
|
when 'ssh'
|
63
|
-
username, password = *
|
64
|
-
|
65
|
-
|
63
|
+
username, password = *uri.userinfo.split(':')
|
64
|
+
gateway = Net::SSH::Gateway.new(
|
65
|
+
uri.host,
|
66
66
|
username,
|
67
67
|
password: password,
|
68
|
-
port:
|
68
|
+
port: uri.port || 22
|
69
69
|
)
|
70
|
+
|
71
|
+
@tunnels[name] = Struct.new('Tunnel', :gateway, :ports).new(gateway, [])
|
70
72
|
end
|
71
73
|
end
|
72
74
|
|
73
|
-
|
74
|
-
|
75
|
-
|
75
|
+
if tunnel = @tunnels[name]
|
76
|
+
port = tunnel.gateway.open(host, port)
|
77
|
+
host = '127.0.0.1'
|
78
|
+
tunnel.ports << port
|
79
|
+
end
|
80
|
+
return host, port
|
76
81
|
end
|
77
82
|
end
|
78
83
|
|
79
|
-
def close_tunnel(
|
84
|
+
def close_tunnel(name, port)
|
80
85
|
@mutex.synchronize do
|
81
|
-
|
82
|
-
|
86
|
+
if tunnel = @tunnels[name]
|
87
|
+
tunnel.ports.delete(port)
|
88
|
+
tunnel.gateway.close(port)
|
89
|
+
tunnel.gateway.shutdown! if tunnel.ports.empty?
|
90
|
+
end
|
83
91
|
end
|
84
92
|
end
|
85
93
|
|
data/lib/xlogin/session_pool.rb
CHANGED
@@ -13,20 +13,12 @@ module Xlogin
|
|
13
13
|
@args = args
|
14
14
|
@opts = opts
|
15
15
|
|
16
|
-
@size = DEFAULT_POOL_SIZE
|
17
|
-
@idle = DEFAULT_POOL_IDLE
|
16
|
+
@size = @opts.delete(:pool_size) || DEFAULT_POOL_SIZE
|
17
|
+
@idle = @opts.delete(:pool_idle) || DEFAULT_POOL_IDLE
|
18
18
|
|
19
19
|
@mutex = Mutex.new
|
20
20
|
@queue = Queue.new
|
21
|
-
@
|
22
|
-
end
|
23
|
-
|
24
|
-
def size=(val)
|
25
|
-
@mutex.synchronize{ @size = val }
|
26
|
-
end
|
27
|
-
|
28
|
-
def idle=(val)
|
29
|
-
@mutex.synchronize{ @idle = val }
|
21
|
+
@count = 0
|
30
22
|
end
|
31
23
|
|
32
24
|
def with
|
@@ -38,20 +30,22 @@ module Xlogin
|
|
38
30
|
|
39
31
|
def close
|
40
32
|
until @queue.empty?
|
41
|
-
session, _ = @queue.deq
|
33
|
+
session, _, _ = @queue.deq
|
42
34
|
destroy(session)
|
43
35
|
end
|
44
36
|
end
|
45
37
|
|
46
38
|
def deq
|
47
39
|
@mutex.synchronize do
|
48
|
-
if @queue.empty? && @
|
49
|
-
@
|
40
|
+
if @queue.empty? && @count < @size
|
41
|
+
@count += 1
|
50
42
|
return Xlogin.get(@args, **@opts)
|
51
43
|
end
|
52
44
|
end
|
53
45
|
|
54
|
-
session, last_used = @queue.deq
|
46
|
+
session, last_used, watch_dog = @queue.deq
|
47
|
+
|
48
|
+
watch_dog.kill
|
55
49
|
if Time.now - last_used > @idle
|
56
50
|
destroy(session)
|
57
51
|
return deq
|
@@ -59,23 +53,24 @@ module Xlogin
|
|
59
53
|
|
60
54
|
begin
|
61
55
|
raise IOError if session&.sock&.closed?
|
56
|
+
return session
|
62
57
|
rescue IOError, EOFError, Errno::ECONNABORTED, Errno::ECONNREFUSED, Errno::ECONNRESET
|
63
58
|
destroy(session)
|
64
59
|
return deq
|
65
60
|
end
|
66
|
-
|
67
|
-
session
|
68
61
|
end
|
69
62
|
|
70
63
|
def enq(session)
|
71
64
|
last_used = Time.now
|
72
|
-
@
|
65
|
+
watch_dog = Thread.new(session){ |s| sleep(@idle * 1.5) && s.close rescue nil }
|
66
|
+
@queue.enq [session, last_used, watch_dog]
|
73
67
|
end
|
74
68
|
|
69
|
+
private
|
75
70
|
def destroy(session)
|
76
71
|
@mutex.synchronize do
|
77
72
|
session.close rescue nil
|
78
|
-
@
|
73
|
+
@count -= 1
|
79
74
|
end
|
80
75
|
end
|
81
76
|
|
data/lib/xlogin/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xlogin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- haccht
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-telnet
|