xlogin 0.7.14 → 0.7.16

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: fdd4ee47fc2ae343363a8074944dbaf7d624c430
4
- data.tar.gz: d50197fa6e9fec8b0f79fb32f3f1ca00153a53a8
3
+ metadata.gz: c724426e5a7a390655bde1100323aa82b3e7189e
4
+ data.tar.gz: 2e1f06d01d84439fdbce0acd48487d1ffb6fec6d
5
5
  SHA512:
6
- metadata.gz: de383fcdbe2573f505563ac729579a954b83321cf7285693b6446df6a7b9d43d2f7d87d925fd01fa7158e4dfee8e9d58c248ed6b9f6a362512e0fd57111370ea
7
- data.tar.gz: 924e67dc76b0b414b2e402ec6890028e0d37e0b5a65f132b761bcc0761a9f9750490b3b8df4c54cbd8a916b019a399782d650feef2739ca7199b4468fd1c3195
6
+ metadata.gz: a878236af348f8b765472712079c09dc7847d6db5a0521c1913edd62fb4efd63cd24411386b320912c24ed504a56acf1b8a3267db8ba2c4ef2f63abf8869a234
7
+ data.tar.gz: 6d48c122220ce879f30933a866773b9d2bd0879059cca7ea0419f7cb9b6aef6a08d6680f0e5629f8a44689e1efd4c0e85d1e6199775379e340c44908f325e6b8
@@ -54,7 +54,13 @@ module Xlogin
54
54
  factory.source(source_file || DEFAULT_INVENTORY_FILE)
55
55
  end
56
56
 
57
- def template(*template_files)
57
+ def template(*template_dirs)
58
+ files = template_dirs.flat_map { |dir| Dir.glob(File.join(dir, '*.rb')) }
59
+ load_template(*files)
60
+ end
61
+ alias_method :template_dir, :template
62
+
63
+ def load_template(*template_files)
58
64
  return factory.source_template(*template_files) unless template_files.empty?
59
65
 
60
66
  unless Dir.exist?(DEFAULT_TEMPLATE_DIR)
@@ -64,11 +70,6 @@ module Xlogin
64
70
  template_dir(DEFAULT_TEMPLATE_DIR)
65
71
  end
66
72
 
67
- def template_dir(*template_dirs)
68
- files = template_dirs.flat_map { |dir| Dir.glob(File.join(dir, '*.rb')) }
69
- template(*files)
70
- end
71
-
72
73
  end
73
74
 
74
75
  end
@@ -10,7 +10,6 @@ module Xlogin
10
10
  def initialize
11
11
  @database = Hash.new
12
12
  @templates = Hash.new
13
- @mutex = Mutex.new
14
13
  @group = nil
15
14
  end
16
15
 
@@ -68,15 +67,11 @@ module Xlogin
68
67
  end
69
68
 
70
69
  def build(type:, uri:, **opts)
71
- @mutex.synchronize { Xlogin.configure { template_dir } if @templates.empty? }
72
-
73
70
  template = get_template(type)
74
71
  template.build(uri, **opts)
75
72
  end
76
73
 
77
74
  def build_from_hostname(hostname, **opts)
78
- @mutex.synchronize { Xlogin.configure { source } if @database.empty? }
79
-
80
75
  hostinfo = get(hostname)
81
76
  raise Xlogin::SessionError.new("Host not found: '#{hostname}'") unless hostinfo
82
77
 
@@ -20,7 +20,7 @@ module Xlogin
20
20
  when 'telnet' then 23
21
21
  end
22
22
 
23
- raise ArgumentError.new("Invalid URI - '#{uri}'") unless @host && @port
23
+ raise SessionError.new("Invalid URI - '#{uri}'") unless @host && @port
24
24
 
25
25
  @name = opts.delete(:name) || @host
26
26
  @config = OpenStruct.new(opts)
@@ -5,15 +5,17 @@ module Xlogin
5
5
  class SessionPool
6
6
 
7
7
  DEFAULT_SIZE = 1
8
- DEFAULT_IDLE = 10
8
+ DEFAULT_IDLE = false
9
9
 
10
10
  def initialize(args, **opts)
11
- @args = args
12
- @opts = opts
11
+ @args = args
12
+ @opts = opts
13
13
 
14
- @mutex = Mutex.new
15
- @queue = Queue.new
16
- @created = 0
14
+ @mutex = Mutex.new
15
+ @queue = Queue.new
16
+
17
+ @created = 0
18
+ @watchdog = Hash.new
17
19
  end
18
20
 
19
21
  def size
@@ -43,27 +45,36 @@ module Xlogin
43
45
  def deq
44
46
  session = try_create
45
47
  unless session
46
- session, expires = @queue.deq
47
- if expires < Time.now
48
- session.close
49
- session = session.duplicate
50
- end
48
+ session, updated = @queue.deq
49
+ session = session.duplicate if idle && updated + idle.to_f < Time.now
51
50
  end
52
51
 
53
52
  session
54
53
  end
55
54
 
56
55
  def enq(session)
57
- @queue.enq [session, Time.now + idle]
56
+ @mutex.synchronize { update_watchdog(session) }
57
+ @queue.enq [session, Time.now]
58
58
  end
59
59
 
60
60
  def try_create
61
61
  @mutex.synchronize do
62
62
  return unless @created < size
63
63
 
64
+ session = Xlogin.get(@args, **@opts)
65
+ update_watchdog(session)
66
+
64
67
  @created += 1
65
- Xlogin.get(@args, **@opts)
68
+ session
66
69
  end
67
70
  end
71
+
72
+ def update_watchdog(session)
73
+ return unless idle
74
+
75
+ @watchdog[session].tap { |th| th.kill if th }
76
+ @watchdog[session] = Thread.new(session) { |s| sleep(idle.to_f + 1) && s.close }
77
+ end
68
78
  end
79
+
69
80
  end
@@ -1,3 +1,3 @@
1
1
  module Xlogin
2
- VERSION = "0.7.14"
2
+ VERSION = "0.7.16"
3
3
  end
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.7.14
4
+ version: 0.7.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - haccht
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-14 00:00:00.000000000 Z
11
+ date: 2018-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-telnet