sshkit-custom-dsl 0.0.6 → 0.0.7
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/.gitignore +1 -0
- data/.rubocop_todo.yml +11 -0
- data/README.md +33 -4
- data/Rakefile +3 -4
- data/lib/core_ext/sshkit/backend/abstract.rb +4 -11
- data/lib/core_ext/sshkit.rb +1 -1
- data/lib/sshkit/custom/config/store.rb +11 -10
- data/lib/sshkit/custom/dsl/config_statements.rb +14 -9
- data/lib/sshkit/custom/dsl/exec_statements.rb +2 -3
- data/lib/sshkit/custom/dsl/helper.rb +3 -3
- data/lib/sshkit/custom/dsl/version.rb +1 -1
- data/lib/sshkit/custom/dsl.rb +4 -4
- data/lib/sshkit/custom/runner/abstract.rb +88 -0
- data/lib/sshkit/custom/runner/group.rb +34 -0
- data/lib/sshkit/custom/runner/parallel.rb +30 -0
- data/lib/sshkit/custom/runner/sequential.rb +14 -0
- data/spec/spec_helper.rb +0 -2
- data/spec/unit/sshkit/custom/config/store_spec.rb +116 -0
- data/spec/unit/sshkit/custom/dsl/config_statements_spec.rb +147 -0
- data/spec/unit/sshkit/custom/dsl/exec_statements_spec.rb +74 -0
- data/spec/unit/sshkit/custom/dsl/helper_spec.rb +57 -0
- data/spec/unit/sshkit/custom/runner/abstract_spec.rb +123 -0
- data/spec/unit/sshkit/custom/runner/group_spec.rb +48 -0
- data/spec/unit/sshkit/custom/runner/parallel_spec.rb +55 -0
- data/spec/unit/sshkit/custom/runner/sequential_spec.rb +27 -0
- data/sshkit-custom-dsl.gemspec +10 -10
- metadata +22 -6
- data/lib/sshkit/custom/config/runner/abstract.rb +0 -100
- data/lib/sshkit/custom/config/runner/group.rb +0 -31
- data/lib/sshkit/custom/config/runner/parallel.rb +0 -35
- data/lib/sshkit/custom/config/runner/sequential.rb +0 -18
@@ -1,100 +0,0 @@
|
|
1
|
-
module SSHKit
|
2
|
-
module Custom
|
3
|
-
module Config
|
4
|
-
module Runner
|
5
|
-
|
6
|
-
ExecuteError = SSHKit::Runner::ExecuteError
|
7
|
-
|
8
|
-
class Abstract
|
9
|
-
attr_accessor :backends
|
10
|
-
attr_reader :options
|
11
|
-
attr_writer :wait_interval
|
12
|
-
|
13
|
-
def self.create_runner(opts)
|
14
|
-
opts_with_defaults = { in: :parallel }.merge(opts)
|
15
|
-
|
16
|
-
case opts_with_defaults[:in]
|
17
|
-
when :parallel then Parallel
|
18
|
-
when :sequence then Sequential
|
19
|
-
when :groups then Group
|
20
|
-
else
|
21
|
-
raise RuntimeError, "Don't know how to handle run style #{opts_with_defaults[:in].inspect}"
|
22
|
-
end.new(opts_with_defaults)
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.scope_storage
|
27
|
-
ScopedStorage::ThreadLocalStorage
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.scope
|
31
|
-
@scope ||= ScopedStorage::Scope.new('sshkit_runner', scope_storage)
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.active_backend
|
35
|
-
scope[:active_backend]
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.active_backend=(new_backend)
|
39
|
-
scope[:active_backend]=new_backend
|
40
|
-
end
|
41
|
-
|
42
|
-
def initialize(options = nil)
|
43
|
-
@options = options || {}
|
44
|
-
end
|
45
|
-
|
46
|
-
def active_backend
|
47
|
-
self.class.active_backend
|
48
|
-
end
|
49
|
-
|
50
|
-
def active_backend=(new_backend)
|
51
|
-
self.class.active_backend=new_backend
|
52
|
-
end
|
53
|
-
|
54
|
-
def send_cmd(cmd, *args, &block)
|
55
|
-
|
56
|
-
begin
|
57
|
-
|
58
|
-
if block
|
59
|
-
args = Array(block.call(active_backend.host))
|
60
|
-
end
|
61
|
-
|
62
|
-
active_backend.send(cmd, *args)
|
63
|
-
|
64
|
-
rescue Exception => e
|
65
|
-
e2 = ExecuteError.new e
|
66
|
-
raise e2, "Exception while executing on host #{active_backend.host}: #{e.message}"
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
|
72
|
-
def apply_to_bck(backend, &block)
|
73
|
-
begin
|
74
|
-
|
75
|
-
self.active_backend = backend
|
76
|
-
block.call(backend.host)
|
77
|
-
|
78
|
-
rescue Exception => e
|
79
|
-
e2 = ExecuteError.new e
|
80
|
-
raise e2, "Exception while executing on host #{backend.host}: #{e.message}"
|
81
|
-
ensure
|
82
|
-
self.active_backend = nil
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
protected
|
87
|
-
|
88
|
-
def do_wait
|
89
|
-
sleep wait_interval
|
90
|
-
end
|
91
|
-
|
92
|
-
def wait_interval
|
93
|
-
@wait_interval || options[:wait] || 2
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module SSHKit
|
2
|
-
module Custom
|
3
|
-
module Config
|
4
|
-
module Runner
|
5
|
-
|
6
|
-
class Group < Abstract
|
7
|
-
attr_writer :group_size
|
8
|
-
|
9
|
-
def apply_block_to_bcks(&block)
|
10
|
-
backends.each_slice(group_size).collect do |group_backends|
|
11
|
-
|
12
|
-
Parallel.new(options).tap do |runner|
|
13
|
-
runner.backends = group_backends
|
14
|
-
runner.apply_block_to_bcks(&block)
|
15
|
-
end
|
16
|
-
|
17
|
-
do_wait
|
18
|
-
|
19
|
-
end.flatten
|
20
|
-
end
|
21
|
-
|
22
|
-
|
23
|
-
def group_size
|
24
|
-
@group_size ||= options[:limit] || 2
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module SSHKit
|
2
|
-
module Custom
|
3
|
-
module Config
|
4
|
-
module Runner
|
5
|
-
|
6
|
-
require 'rake'
|
7
|
-
|
8
|
-
class Parallel < Abstract
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
def thread_pool
|
13
|
-
@thread_pool ||= Rake::ThreadPool.new(thread_count)
|
14
|
-
end
|
15
|
-
|
16
|
-
def apply_block_to_bcks(&block)
|
17
|
-
|
18
|
-
futures = backends.map do |b|
|
19
|
-
thread_pool.future(b) do |fb|
|
20
|
-
apply_to_bck fb, &block
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
futures.each { |f| f.value }
|
25
|
-
end
|
26
|
-
|
27
|
-
def thread_count
|
28
|
-
@thread_count ||= options[:thread_count] || Rake.suggested_thread_count-1
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module SSHKit
|
2
|
-
module Custom
|
3
|
-
module Config
|
4
|
-
module Runner
|
5
|
-
class Sequential < Abstract
|
6
|
-
|
7
|
-
def apply_block_to_bcks(&block)
|
8
|
-
backends.each do |backend|
|
9
|
-
apply_to_bck backend, &block
|
10
|
-
do_wait
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|