xlogin 0.7.11 → 0.7.12

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: 16ee3834f35038d07a026c8a7a75cdd9c5b7e073
4
- data.tar.gz: cad0b549fc1ddc90867e2013c3257ad18fed5ec0
3
+ metadata.gz: db5dac91935e8ed2bf468c8628fe4dd817087042
4
+ data.tar.gz: 9cccb35b91f483fc5825bb9a197aa0c5c247e7e3
5
5
  SHA512:
6
- metadata.gz: 6adaa86538aaa1fd7c5fa59b951ec80221dd58b1348ac0b30e2a9c7ad58ab6d28ad48a00caf40e4310f0a32ba6cd3b67869c0041d0fc22997a3662de14142f51
7
- data.tar.gz: 2e39a4485161afdcdec728d35035473632220fd673abe15feace7def8411a65729a855f555fe44beabaded183df1c8f00e5a700f2f58e27cbd1974bc71188b6f
6
+ metadata.gz: 59a9746e814e56e2e4d4fea2d260b9e5ce5ff24ad560510993e4d7e7ccb4efd7e9ec2d467385693ede380897a17c662657e9383fe070763c370746196675841d
7
+ data.tar.gz: a880c5a4155e87855cf3f09c87f32af0f8871a6da8ea0cb2c9ca3e649196f5b5e5c2d0edd84616638bdd0c511cd9db38a1eb2c5cd820d74f60823e55bab8d103
data/lib/xlogin.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  $:.unshift File.dirname(__FILE__)
2
2
 
3
+ require 'thread'
3
4
  require 'xlogin/factory'
4
5
  require 'xlogin/version'
5
6
 
@@ -30,7 +31,7 @@ module Xlogin
30
31
  end
31
32
 
32
33
  def get_pool(args, **opts, &block)
33
- pool = SessionPool.new(args, **opts)
34
+ pool = factory.pool(args, **opts)
34
35
 
35
36
  return pool unless block
36
37
  block.call(pool)
data/lib/xlogin/cli.rb CHANGED
@@ -115,7 +115,7 @@ module Xlogin
115
115
  loggers << $stdout if config.parallels == 1
116
116
  loggers << File.join(config.logdir, "#{hostname}.log") if config.logdir
117
117
 
118
- session = Xlogin.factory.build(hostinfo.merge(log: loggers))
118
+ session = Xlogin.get(hostinfo.merge(log: loggers))
119
119
  session.enable if session.config.enable
120
120
 
121
121
  block.call(session)
@@ -65,20 +65,20 @@ module Xlogin
65
65
  @group = current_group
66
66
  end
67
67
 
68
- def build(type:, uri:, **opts)
69
- Xlogin.configure { template_dir } if @templates.empty?
68
+ def pool(args, **opts)
69
+ SessionPool.new(args, **opts)
70
+ end
70
71
 
72
+ def build(type:, uri:, **opts)
71
73
  template = get_template(type)
72
74
  template.build(uri, **opts)
73
75
  end
74
76
 
75
77
  def build_from_hostname(hostname, **opts)
76
- Xlogin.configure { source } if @database.empty?
77
-
78
78
  hostinfo = get(hostname)
79
79
  raise Xlogin::SessionError.new("Host not found: '#{hostname}'") unless hostinfo
80
80
 
81
- build(hostinfo.merge(**opts)).tap { |s| s.name = hostname }
81
+ build(hostinfo.merge(name: hostname, **opts))
82
82
  end
83
83
 
84
84
  def method_missing(method_name, *args, &block)
@@ -13,21 +13,21 @@ module Xlogin
13
13
  attr_accessor :config
14
14
 
15
15
  def initialize(template, uri, **opts)
16
- @template = template
17
- @config = OpenStruct.new(opts)
18
-
19
16
  @uri = uri
20
17
  @host = uri.host
21
- @name = uri.host
22
18
  @port = uri.port
23
19
  @port ||= case @uri.scheme
24
20
  when 'ssh' then 22
25
21
  when 'telnet' then 23
26
22
  end
27
23
 
28
- @username, @password = uri.userinfo.to_s.split(':')
29
24
  raise ArgumentError.new("Invalid URI - '#{uri}'") unless @host && @port
30
25
 
26
+ @name = opts.delete(:name) || @host
27
+ @config = OpenStruct.new(opts)
28
+ @template = template
29
+ @username, @password = uri.userinfo.to_s.split(':')
30
+
31
31
  ssh_tunnel(@config.via) if @config.via
32
32
  max_retry = @config.retry || 1
33
33
 
@@ -71,10 +71,11 @@ module Xlogin
71
71
  end
72
72
 
73
73
  def waitfor(*args, &block)
74
- line = ''
75
- return waitfor(Regexp.union(*@template.prompt.map(&:first)), &block) if args.empty?
76
-
77
- line = super(*args, &block)
74
+ args << Regexp.union(*@template.prompt.map(&:first)) if args.empty?
75
+ line = super(*args) do |recv|
76
+ block.call(recv) if block
77
+ output_log(recv)
78
+ end
78
79
 
79
80
  _, process = @template.prompt.find { |r, p| r =~ line && p }
80
81
  if process
@@ -94,6 +95,7 @@ module Xlogin
94
95
  logger.close if output_log.kind_of?(String)
95
96
  end
96
97
  @gateway.shutdown! if @gateway
98
+
97
99
  super
98
100
  @closed = true
99
101
  end
@@ -153,11 +155,10 @@ module Xlogin
153
155
  case output_log
154
156
  when String
155
157
  FileUtils.mkdir_p(File.dirname(output_log))
156
- logger = File.open(output_log, 'a+')
157
- logger.binmode
158
- logger.sync = true
159
-
160
- loggers[output_log] = logger
158
+ loggers[output_log] = File.open(output_log, 'a+').tap do |logger|
159
+ logger.binmode
160
+ logger.sync = true
161
+ end
161
162
  when IO, StringIO
162
163
  loggers[output_log] = output_log
163
164
  end
@@ -168,12 +169,12 @@ module Xlogin
168
169
  class SessionPool
169
170
 
170
171
  def initialize(args, **opts)
171
- temp = case args
172
- when String then opts.select { |k, v| %i(size timeout).member?(k) && !v.nil? }
173
- when Hash then args.select { |k, v| %i(size timeout).member?(k) && !v.nil? }
174
- end
172
+ pool_opts = case args
173
+ when String then opts.select { |k, v| %i(size timeout).member?(k) && !v.nil? }
174
+ when Hash then args.select { |k, v| %i(size timeout).member?(k) && !v.nil? }
175
+ end
175
176
 
176
- @pool = ConnectionPool.new(**temp) { Wrapper.new(args, **opts) }
177
+ @pool = ConnectionPool.new(**pool_opts) { Wrapper.new(args, **opts) }
177
178
  end
178
179
 
179
180
  def with(**opts)
data/lib/xlogin/telnet.rb CHANGED
@@ -7,18 +7,12 @@ module Xlogin
7
7
 
8
8
  prepend SessionModule
9
9
 
10
- alias_method :telnet_login, :login
11
- undef_method :login
12
-
13
10
  def initialize(args)
14
11
  username = args.delete('Username')
15
12
  password = args.delete('Password')
16
- super(args)
17
13
 
18
- if username || password
19
- return login(*[username, password].compact) if respond_to?(:login)
20
- telnet_login(*[username, password].compact)
21
- end
14
+ super(args)
15
+ login(*[username, password].compact) if username || password
22
16
  end
23
17
 
24
18
  def interact!
@@ -47,7 +47,7 @@ module Xlogin
47
47
  methods.each do |name, block|
48
48
  case name
49
49
  when :enable
50
- define_method(name) { |password = opts[:enable]| instance_exec(password, &block) }
50
+ define_method(name) { |args = opts[:enable]| instance_exec(args, &block) }
51
51
  else
52
52
  define_method(name, &block)
53
53
  end
@@ -1,3 +1,3 @@
1
1
  module Xlogin
2
- VERSION = "0.7.11"
2
+ VERSION = "0.7.12"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xlogin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.11
4
+ version: 0.7.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - haccht