xlogin 0.8.15 → 0.8.18
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 +33 -6
- data/lib/xlogin/cli.rb +4 -4
- data/lib/xlogin/factory.rb +4 -30
- data/lib/xlogin/rake_task.rb +7 -2
- data/lib/xlogin/spec.rb +52 -0
- data/lib/xlogin/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ada4bef520cb3929924a9de570480b28af0c5ec0
|
4
|
+
data.tar.gz: fc80ebec45b43cf0a752376b5981fed03b5f7eff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f61d0bfb77b7bd07943ca1eae1356a66d924ffadd35b85314eaec46f6e0708656220925c9f7553eab1fd3ce0024838fba36a30385663a27ea31ae1bf36dba2c5
|
7
|
+
data.tar.gz: a8d19a98a7329aee5f8fb2704059e46b773fd456ef15bfd529b8695a6e2e5f65cb8b49abc0c057f54680a2f7d3209abfb2073a207db677a565200918ee62a146
|
data/lib/xlogin.rb
CHANGED
@@ -56,18 +56,45 @@ module Xlogin
|
|
56
56
|
@authorized = boolean == true || (block && block.call == true)
|
57
57
|
end
|
58
58
|
|
59
|
+
def register(**args)
|
60
|
+
factory.set_info(**args)
|
61
|
+
end
|
62
|
+
|
59
63
|
def source(*source_files)
|
60
|
-
|
64
|
+
source_files.compact.each do |file|
|
65
|
+
raise SessionError.new("Inventory file not found: #{file}") unless File.exist?(file)
|
66
|
+
instance_eval(IO.read(file), file) if File.exist?(file)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def template(name, *args, &block)
|
71
|
+
return template_dir(name, *args) unless block # for backward compatibility
|
72
|
+
|
73
|
+
raise ArgumentError.new('missing template name') unless name
|
74
|
+
factory.set_template(name, &block)
|
61
75
|
end
|
62
76
|
|
63
|
-
def
|
77
|
+
def template_dir(*template_dirs)
|
64
78
|
files = template_dirs.flat_map { |dir| Dir.glob(File.join(dir, '*.rb')) }
|
65
|
-
|
79
|
+
template_file(*files)
|
80
|
+
end
|
81
|
+
|
82
|
+
def template_file(*template_files)
|
83
|
+
template_files.compact.each do |file|
|
84
|
+
raise TemplateError.new("Template file not found: #{file}") unless File.exist?(file)
|
85
|
+
name = File.basename(file, '.rb').scan(/\w+/).join('_')
|
86
|
+
factory.set_template(name, IO.read(file)) if File.exist?(file)
|
87
|
+
end
|
66
88
|
end
|
67
|
-
alias_method :template_dir, :template
|
68
89
|
|
69
|
-
def
|
70
|
-
|
90
|
+
def method_missing(method_name, *args, &block)
|
91
|
+
type = method_name.to_s.downcase
|
92
|
+
name = args[0]
|
93
|
+
uri = args[1]
|
94
|
+
opts = args[2] || {}
|
95
|
+
|
96
|
+
super unless args.size == 2 || args.size == 3
|
97
|
+
register(type: type, name: name, uri: uri, **opts)
|
71
98
|
end
|
72
99
|
|
73
100
|
end
|
data/lib/xlogin/cli.rb
CHANGED
@@ -61,14 +61,14 @@ module Xlogin
|
|
61
61
|
|
62
62
|
authorize(config.authorize)
|
63
63
|
source(File.expand_path(config.inventory, ENV['PWD']))
|
64
|
-
|
64
|
+
template_file(*config.templates.map { |file| File.expand_path(file, ENV['PWD']) })
|
65
65
|
end
|
66
66
|
|
67
67
|
config.hostlist = Xlogin.list(*host.to_s.split(/\s+/))
|
68
68
|
raise "No host found: `#{host}`" if config.hostlist.empty?
|
69
|
-
rescue => e
|
70
|
-
|
71
|
-
|
69
|
+
#rescue => e
|
70
|
+
# $stderr.puts e, '', parser
|
71
|
+
# exit 1
|
72
72
|
end
|
73
73
|
|
74
74
|
config
|
data/lib/xlogin/factory.rb
CHANGED
@@ -11,13 +11,6 @@ module Xlogin
|
|
11
11
|
@templates = Hash.new
|
12
12
|
end
|
13
13
|
|
14
|
-
def source(*files)
|
15
|
-
files.compact.each do |file|
|
16
|
-
raise SessionError.new("Inventory file not found: #{file}") unless File.exist?(file)
|
17
|
-
instance_eval(IO.read(file), file) if File.exist?(file)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
14
|
def set_info(**opts)
|
22
15
|
name = opts[:name]
|
23
16
|
return unless name
|
@@ -39,17 +32,10 @@ module Xlogin
|
|
39
32
|
values.reduce(&:&).uniq
|
40
33
|
end
|
41
34
|
|
42
|
-
def
|
43
|
-
files.compact.each do |file|
|
44
|
-
raise TemplateError.new("Template file not found: #{file}") unless File.exist?(file)
|
45
|
-
name = File.basename(file, '.rb').scan(/\w+/).join('_')
|
46
|
-
set_template(name, IO.read(file)) if File.exist?(file)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def set_template(name, text)
|
35
|
+
def set_template(name, text = nil, &block)
|
51
36
|
template = get_template(name)
|
52
|
-
template.instance_eval(text)
|
37
|
+
template.instance_eval(text) if text
|
38
|
+
template.instance_eval(&block) if block
|
53
39
|
@templates[name.to_s.downcase] = template
|
54
40
|
end
|
55
41
|
|
@@ -68,22 +54,10 @@ module Xlogin
|
|
68
54
|
|
69
55
|
def build_from_hostname(hostname, **opts)
|
70
56
|
hostinfo = get_info(hostname)
|
71
|
-
raise
|
57
|
+
raise SessionError.new("Host not found: '#{hostname}'") unless hostinfo
|
72
58
|
|
73
59
|
build(hostinfo.merge(name: hostname, **opts))
|
74
60
|
end
|
75
61
|
|
76
|
-
def method_missing(method_name, *args, &block)
|
77
|
-
super unless caller_locations.first.label == 'block in source' and args.size >= 2
|
78
|
-
|
79
|
-
type = method_name.to_s.downcase
|
80
|
-
name = args.shift
|
81
|
-
uri = args.shift
|
82
|
-
opts = args.shift || {}
|
83
|
-
|
84
|
-
super if [type, name, uri].any? { |e| e.nil? }
|
85
|
-
set_info(type: type, name: name, uri: uri, **opts)
|
86
|
-
end
|
87
|
-
|
88
62
|
end
|
89
63
|
end
|
data/lib/xlogin/rake_task.rb
CHANGED
@@ -16,7 +16,7 @@ module Xlogin
|
|
16
16
|
description = Rake.application.last_description
|
17
17
|
task 'all' => hostnames unless opts[:bundle] == false
|
18
18
|
|
19
|
-
description = opts[:desc]
|
19
|
+
description = opts[:desc]
|
20
20
|
hostnames.each do |hostname|
|
21
21
|
desc description
|
22
22
|
RakeTask.new(hostname, &block)
|
@@ -32,6 +32,8 @@ module Xlogin
|
|
32
32
|
attr_accessor :silent
|
33
33
|
attr_accessor :fail_on_error
|
34
34
|
|
35
|
+
@@graceful_shutdown = false
|
36
|
+
|
35
37
|
def initialize(name)
|
36
38
|
@name = name
|
37
39
|
@taskname = [*Rake.application.current_scope.to_a.reverse, name].join(':')
|
@@ -65,12 +67,14 @@ module Xlogin
|
|
65
67
|
if lock
|
66
68
|
task(name => lock)
|
67
69
|
file(lock) do
|
70
|
+
next if @@graceful_shutdown
|
68
71
|
run_task
|
69
72
|
mkdir_p(File.dirname(lock), verbose: Rake.application.options.trace)
|
70
73
|
touch(lock, verbose: Rake.application.options.trace)
|
71
74
|
end
|
72
75
|
else
|
73
76
|
task(name) do
|
77
|
+
next if @@graceful_shutdown
|
74
78
|
run_task
|
75
79
|
end
|
76
80
|
end
|
@@ -92,7 +96,8 @@ module Xlogin
|
|
92
96
|
rescue => e
|
93
97
|
output($stderr, buffer.string) if !silent && Rake.application.options.always_multitask
|
94
98
|
output($stderr, "[ERROR] Xlogin - #{e}\n")
|
95
|
-
|
99
|
+
|
100
|
+
@@graceful_shutdown = true if fail_on_error
|
96
101
|
end
|
97
102
|
end
|
98
103
|
|
data/lib/xlogin/spec.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
module Xlogin
|
2
|
+
|
3
|
+
class ExpectationError < StandardError
|
4
|
+
|
5
|
+
def initialize(expect, actual)
|
6
|
+
super("Expected to match #{expect}")
|
7
|
+
@actual = actual
|
8
|
+
end
|
9
|
+
|
10
|
+
def full_message
|
11
|
+
"#{message},\nbut actually was:\n#{@actual}"
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
class Expectation
|
17
|
+
|
18
|
+
def initialize(session, *args)
|
19
|
+
@session = session
|
20
|
+
@args = args
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_match(regexp)
|
24
|
+
return if match(regexp)
|
25
|
+
raise ExpectationError.new(@expect, @actual)
|
26
|
+
end
|
27
|
+
|
28
|
+
def not_to_match(regexp)
|
29
|
+
return unless match(regexp)
|
30
|
+
raise ExpectationError.new(@expect, @actual)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
def match(regexp)
|
35
|
+
regexp = Regexp.new(regexp.to_s) unless regexp.kind_of?(Regexp)
|
36
|
+
@expect = regexp.inspect
|
37
|
+
|
38
|
+
@actual || = @session.cmd(*@args)
|
39
|
+
@actual =~ regexp
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
module SessionModule
|
45
|
+
|
46
|
+
def expect(*args)
|
47
|
+
Expectation.new(self, *args)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
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.8.
|
4
|
+
version: 0.8.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- haccht
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-telnet
|
@@ -148,6 +148,7 @@ files:
|
|
148
148
|
- lib/xlogin/rake_task.rb
|
149
149
|
- lib/xlogin/session.rb
|
150
150
|
- lib/xlogin/session_pool.rb
|
151
|
+
- lib/xlogin/spec.rb
|
151
152
|
- lib/xlogin/ssh.rb
|
152
153
|
- lib/xlogin/telnet.rb
|
153
154
|
- lib/xlogin/template.rb
|