xlogin 0.15.7 → 0.16.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/xlogin.rb +4 -4
- data/lib/xlogin/factory.rb +2 -2
- data/lib/xlogin/rake_task.rb +31 -24
- data/lib/xlogin/session.rb +5 -5
- data/lib/xlogin/telnet.rb +1 -1
- 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: 342f00cdb5f923c597cf7f40c1d4cf35c8cb7ecb596caa8457c05b09c9b7bd2d
|
4
|
+
data.tar.gz: 4a7f6f3041a53b942ea434a8417b6b150397fed622e1a2f7a3b7dc0148f87865
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bb500f47f1b95b5f29c3f10083df805a1dd09cb23ce3696719a8bcffe00812cd947b3001743085663e698628c1d7ed78aa1c2db9c77e434791ad2bf32f0acb9
|
7
|
+
data.tar.gz: abeccd10d1efca609233477172d1926bd3003f05ac4faec3d81b8750c096f7745f0c886fe3801143a52d09afabfcafecbd5c253480ec4c899e0b60bf1d5f7236
|
data/lib/xlogin.rb
CHANGED
@@ -21,14 +21,14 @@ module Xlogin
|
|
21
21
|
end
|
22
22
|
|
23
23
|
class << self
|
24
|
-
def list(*patterns)
|
25
|
-
factory.list_hostinfo(*patterns)
|
26
|
-
end
|
27
|
-
|
28
24
|
def find(*patterns)
|
29
25
|
list(*patterns).first
|
30
26
|
end
|
31
27
|
|
28
|
+
def list(*patterns)
|
29
|
+
factory.list_hostinfo(*patterns)
|
30
|
+
end
|
31
|
+
|
32
32
|
def get(args, **opts, &block)
|
33
33
|
session = case args
|
34
34
|
when Hash then factory.build(**args.merge(**opts))
|
data/lib/xlogin/factory.rb
CHANGED
@@ -26,14 +26,14 @@ module Xlogin
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def list_hostinfo(*patterns)
|
29
|
-
patterns = patterns.flat_map{ |e| e.split(/\s+/) }
|
29
|
+
patterns = patterns.compact.flat_map{ |e| e.split(/\s+/) }
|
30
30
|
return @inventory.values if patterns.empty?
|
31
31
|
|
32
32
|
values1 = patterns.map do |pattern|
|
33
33
|
values2 = pattern.split(',').map do |entry|
|
34
34
|
key, val = entry.to_s.split(':')
|
35
35
|
key, val = 'name', key if val.nil?
|
36
|
-
@inventory.values.select{ |e| File.fnmatch(val, e[key.to_sym]) }
|
36
|
+
@inventory.values.select{ |e| File.fnmatch(val, e[key.to_sym], File::FNM_EXTGLOB) }
|
37
37
|
end
|
38
38
|
values2.reduce(&:&) || []
|
39
39
|
end
|
data/lib/xlogin/rake_task.rb
CHANGED
@@ -10,13 +10,20 @@ module Xlogin
|
|
10
10
|
class << self
|
11
11
|
include Rake::DSL
|
12
12
|
|
13
|
-
def
|
13
|
+
def all(*patterns, &block)
|
14
14
|
description = Rake.application.last_description
|
15
|
-
|
15
|
+
task all: Xlogin.list(*patterns).map{ |e| e[:name] }
|
16
16
|
|
17
|
-
|
17
|
+
desc description
|
18
|
+
generate(*patterns, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
def generate(*patterns, &block)
|
22
|
+
description = Rake.application.last_description
|
23
|
+
|
24
|
+
hostnames = Xlogin.list(*patterns).map{ |e| e[:name] }
|
18
25
|
hostnames.each do |hostname|
|
19
|
-
desc "#{description}
|
26
|
+
desc "#{description} - #{hostname}" if description
|
20
27
|
RakeTask.new(hostname, &block)
|
21
28
|
end
|
22
29
|
end
|
@@ -78,41 +85,41 @@ module Xlogin
|
|
78
85
|
|
79
86
|
def run_task
|
80
87
|
buffer = StringIO.new
|
81
|
-
loggers = []
|
82
|
-
loggers << log
|
83
|
-
loggers <<
|
84
|
-
loggers << buffer
|
88
|
+
loggers = [buffer]
|
89
|
+
loggers << log if log
|
90
|
+
loggers << STDOUT if !silent && !Rake.application.options.always_multitask
|
85
91
|
|
86
92
|
session = Xlogin.get(name, log: loggers, timeout: timeout)
|
93
|
+
instance_exec(session, &@runner)
|
87
94
|
|
88
|
-
|
89
|
-
$stdout.print log_text(buffer.string) if !silent && Rake.application.options.always_multitask
|
90
|
-
|
95
|
+
print(buffer.string) if !silent && Rake.application.options.always_multitask
|
91
96
|
return true
|
92
97
|
rescue => e
|
93
98
|
RakeTask.shutdown! if fail_on_error
|
94
99
|
|
95
|
-
session.
|
96
|
-
if Rake.application.options.always_multitask
|
97
|
-
$stderr.print log_text(buffer.string + "\n").colorize(color: :red)
|
98
|
-
end
|
99
|
-
|
100
|
+
session.log_message(e.to_s.colorize(color: :red)) if session
|
101
|
+
print(buffer.string + "\n", color: :red) if Rake.application.options.always_multitask
|
100
102
|
return false
|
101
103
|
ensure
|
102
104
|
session.close rescue nil
|
103
105
|
end
|
104
106
|
|
105
|
-
def
|
106
|
-
text.
|
107
|
-
end
|
107
|
+
def puts(text, **opts)
|
108
|
+
return text.each { |e| puts(e, **opts) } if text.kind_of?(Array)
|
108
109
|
|
109
|
-
|
110
|
+
text = text.to_s
|
111
|
+
text = text + "\n" unless text[-1] == "\n"
|
112
|
+
print(text, **opts)
|
113
|
+
end
|
110
114
|
|
111
|
-
|
115
|
+
def print(text, **opts)
|
116
|
+
text = text.to_s
|
117
|
+
return if text.empty?
|
112
118
|
|
113
|
-
|
114
|
-
|
115
|
-
|
119
|
+
text = text.gsub("\r", '')
|
120
|
+
text = text.lines.map{ |text| "#{name}\t|#{text}" }.join if Rake.application.options.always_multitask
|
121
|
+
text = text.colorize(**opts)
|
122
|
+
$stdout.print(text)
|
116
123
|
end
|
117
124
|
|
118
125
|
end
|
data/lib/xlogin/session.rb
CHANGED
@@ -44,8 +44,8 @@ module Xlogin
|
|
44
44
|
super(args)
|
45
45
|
rescue => e
|
46
46
|
unless (num_try += 1) > (@config.retry || 0)
|
47
|
-
sleep
|
48
|
-
retry
|
47
|
+
sleep 2.0 ** (num_try)
|
48
|
+
retry
|
49
49
|
end
|
50
50
|
raise e
|
51
51
|
end
|
@@ -84,7 +84,7 @@ module Xlogin
|
|
84
84
|
return waitfor(prompt_pattern) if args.empty?
|
85
85
|
|
86
86
|
line = super(*args) do |recv|
|
87
|
-
|
87
|
+
log_message(recv)
|
88
88
|
block.call(recv) if block
|
89
89
|
end
|
90
90
|
|
@@ -123,11 +123,11 @@ module Xlogin
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
-
|
127
|
-
def write_log(text)
|
126
|
+
def log_message(text)
|
128
127
|
@loggers.each{ |_, logger| logger.syswrite(text) if logger }
|
129
128
|
end
|
130
129
|
|
130
|
+
private
|
131
131
|
def build_log(log)
|
132
132
|
case log
|
133
133
|
when String
|
data/lib/xlogin/telnet.rb
CHANGED
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.16.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- haccht
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-telnet
|