xlogin 0.15.8 → 0.16.3
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 +35 -26
- data/lib/xlogin/session.rb +4 -4
- 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: 275b3d2ef47b42378243799768a5654d993a3a3f1d3c64b893367c41ea714598
|
4
|
+
data.tar.gz: a4deb367df7c2c42e7330d53f4b2abfe7266d96a59dd3b4e8de0160cbe8125c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45bfb93bf676763536cb996f1f775035c14e6561888245d5d3a34eda6769da01270facb941f4c84c9a167c72cfa1440ade59c6d2bd4485d2acfeec06a138c57c
|
7
|
+
data.tar.gz: 351d88211a993c21930f2e30f6435c245ee920190ba6705664cc953c79ef0640bca465b466fc10344d1e3003257adaca58001d47ec03d9bf5e3d19e5f8bfb98b
|
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
|
@@ -59,8 +66,10 @@ module Xlogin
|
|
59
66
|
|
60
67
|
private
|
61
68
|
def define
|
62
|
-
|
63
|
-
|
69
|
+
self.log = File.join(Dir.pwd, 'log', name + '.log') if self.log == true
|
70
|
+
self.lock = File.join(Dir.pwd, 'lock', name_with_scope) if self.lock == true
|
71
|
+
mkdir_p(File.dirname(self.log), verbose: Rake.application.options.trace) if self.log
|
72
|
+
mkdir_p(File.dirname(self.lock), verbose: Rake.application.options.trace) if self.lock
|
64
73
|
|
65
74
|
if lock
|
66
75
|
task(name => lock)
|
@@ -78,41 +87,41 @@ module Xlogin
|
|
78
87
|
|
79
88
|
def run_task
|
80
89
|
buffer = StringIO.new
|
81
|
-
loggers = []
|
82
|
-
loggers << log
|
83
|
-
loggers <<
|
84
|
-
loggers << buffer
|
90
|
+
loggers = [buffer]
|
91
|
+
loggers << log if log
|
92
|
+
loggers << STDOUT if !silent && !Rake.application.options.always_multitask
|
85
93
|
|
86
94
|
session = Xlogin.get(name, log: loggers, timeout: timeout)
|
95
|
+
instance_exec(session, &@runner)
|
87
96
|
|
88
|
-
|
89
|
-
$stdout.print log_text(buffer.string) if !silent && Rake.application.options.always_multitask
|
90
|
-
|
97
|
+
print(buffer.string) if !silent && Rake.application.options.always_multitask
|
91
98
|
return true
|
92
99
|
rescue => e
|
93
100
|
RakeTask.shutdown! if fail_on_error
|
94
101
|
|
95
|
-
session.
|
96
|
-
if Rake.application.options.always_multitask
|
97
|
-
$stderr.print log_text(buffer.string + "\n").colorize(color: :red)
|
98
|
-
end
|
99
|
-
|
102
|
+
session.log_message(e.to_s.colorize(color: :red)) if session
|
103
|
+
print(buffer.string + "\n", color: :red) if Rake.application.options.always_multitask
|
100
104
|
return false
|
101
105
|
ensure
|
102
106
|
session.close rescue nil
|
103
107
|
end
|
104
108
|
|
105
|
-
def
|
106
|
-
text.
|
107
|
-
end
|
109
|
+
def puts(text, **opts)
|
110
|
+
return text.each { |e| puts(e, **opts) } if text.kind_of?(Array)
|
108
111
|
|
109
|
-
|
112
|
+
text = text.to_s
|
113
|
+
text = text + "\n" unless text[-1] == "\n"
|
114
|
+
print(text, **opts)
|
115
|
+
end
|
110
116
|
|
111
|
-
|
117
|
+
def print(text, **opts)
|
118
|
+
text = text.to_s
|
119
|
+
return if text.empty?
|
112
120
|
|
113
|
-
|
114
|
-
|
115
|
-
|
121
|
+
text = text.gsub("\r", '')
|
122
|
+
text = text.lines.map{ |text| "#{name}\t|#{text}" }.join if Rake.application.options.always_multitask
|
123
|
+
text = text.colorize(**opts)
|
124
|
+
$stdout.print(text)
|
116
125
|
end
|
117
126
|
|
118
127
|
end
|
data/lib/xlogin/session.rb
CHANGED
@@ -45,7 +45,7 @@ module Xlogin
|
|
45
45
|
rescue => e
|
46
46
|
unless (num_try += 1) > (@config.retry || 0)
|
47
47
|
sleep 2.0 ** (num_try)
|
48
|
-
retry
|
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.3
|
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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-telnet
|