sshkit-custom-dsl 0.0.2 → 0.0.3
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/core_ext/sshkit.rb +1 -5
- data/lib/sshkit/custom/config/runner/abstract.rb +100 -0
- data/lib/sshkit/custom/config/runner/group.rb +31 -0
- data/lib/sshkit/custom/config/runner/parallel.rb +26 -0
- data/lib/sshkit/custom/config/runner/sequential.rb +18 -0
- data/lib/sshkit/custom/config/store.rb +2 -10
- data/lib/sshkit/custom/dsl/helper.rb +1 -1
- data/lib/sshkit/custom/dsl/version.rb +1 -1
- data/lib/sshkit/custom/dsl.rb +5 -0
- metadata +5 -5
- data/lib/core_ext/sshkit/runner/abstract.rb +0 -49
- data/lib/core_ext/sshkit/runner/group.rb +0 -20
- data/lib/core_ext/sshkit/runner/parallel.rb +0 -27
- data/lib/core_ext/sshkit/runner/sequential.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df9d3b3f6a8a1e8f438527d2fa787c935d0aec37
|
4
|
+
data.tar.gz: 7d674c1c4ddfd58e581d78397bbac4c1058593fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba0cdea9ea03e9050e98048fe550d61411267077cbec690d84489e672e6ca212bcd8eadf6403eae4e46c25963aa8b4c0361e708b76b3f252ce378cfbb0bc2aca
|
7
|
+
data.tar.gz: cc05b1582649595794fa865511779466fd0661ecb1bd264d0a853a430d212a0424cc54f4028048996ea7d5e5b6d94600cd2e842608542d12ae489b09cc685ded
|
data/lib/core_ext/sshkit.rb
CHANGED
@@ -1,6 +1,2 @@
|
|
1
1
|
require 'sshkit'
|
2
|
-
require 'core_ext/sshkit/backend/abstract'
|
3
|
-
require 'core_ext/sshkit/runner/abstract'
|
4
|
-
require 'core_ext/sshkit/runner/sequential'
|
5
|
-
require 'core_ext/sshkit/runner/parallel'
|
6
|
-
require 'core_ext/sshkit/runner/group'
|
2
|
+
require 'core_ext/sshkit/backend/abstract'
|
@@ -0,0 +1,100 @@
|
|
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}: #{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
|
@@ -0,0 +1,31 @@
|
|
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(nil, nil).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
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module SSHKit
|
2
|
+
module Custom
|
3
|
+
module Config
|
4
|
+
module Runner
|
5
|
+
|
6
|
+
class Parallel < Abstract
|
7
|
+
|
8
|
+
def apply_block_to_bcks(&block)
|
9
|
+
threads = []
|
10
|
+
|
11
|
+
backends.each do |next_backend|
|
12
|
+
|
13
|
+
threads << Thread.new(next_backend) do |backend|
|
14
|
+
apply_to_bck backend, &block
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
threads.map(&:join)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,18 @@
|
|
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
|
@@ -14,15 +14,7 @@ module SSHKit
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def create_runner(opts)
|
17
|
-
|
18
|
-
|
19
|
-
@runner ||= case opts_with_defaults[:in]
|
20
|
-
when :parallel then SSHKit::Runner::Parallel
|
21
|
-
when :sequence then SSHKit::Runner::Sequential
|
22
|
-
when :groups then SSHKit::Runner::Group
|
23
|
-
else
|
24
|
-
raise RuntimeError, "Don't know how to handle run style #{opts_with_defaults[:in].inspect}"
|
25
|
-
end.new(nil, opts_with_defaults)
|
17
|
+
@runner ||= Runner::Abstract.create_runner opts
|
26
18
|
end
|
27
19
|
|
28
20
|
def runner
|
@@ -78,7 +70,7 @@ module SSHKit
|
|
78
70
|
end
|
79
71
|
|
80
72
|
def active_backend
|
81
|
-
SSHKit::Runner::Abstract.active_backend
|
73
|
+
SSHKit::Custom::Config::Runner::Abstract.active_backend
|
82
74
|
end
|
83
75
|
end
|
84
76
|
end
|
data/lib/sshkit/custom/dsl.rb
CHANGED
@@ -3,6 +3,11 @@ require 'core_ext/sshkit'
|
|
3
3
|
require 'scoped_storage'
|
4
4
|
|
5
5
|
require 'sshkit/custom/config/store'
|
6
|
+
require 'sshkit/custom/config/runner/abstract'
|
7
|
+
require 'sshkit/custom/config/runner/sequential'
|
8
|
+
require 'sshkit/custom/config/runner/parallel'
|
9
|
+
require 'sshkit/custom/config/runner/group'
|
10
|
+
|
6
11
|
require 'sshkit/custom/dsl/config_statements'
|
7
12
|
require 'sshkit/custom/dsl/exec_statements'
|
8
13
|
require 'sshkit/custom/dsl/helper'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sshkit-custom-dsl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dieter Späth
|
@@ -157,10 +157,10 @@ files:
|
|
157
157
|
- Rakefile
|
158
158
|
- lib/core_ext/sshkit.rb
|
159
159
|
- lib/core_ext/sshkit/backend/abstract.rb
|
160
|
-
- lib/
|
161
|
-
- lib/
|
162
|
-
- lib/
|
163
|
-
- lib/
|
160
|
+
- lib/sshkit/custom/config/runner/abstract.rb
|
161
|
+
- lib/sshkit/custom/config/runner/group.rb
|
162
|
+
- lib/sshkit/custom/config/runner/parallel.rb
|
163
|
+
- lib/sshkit/custom/config/runner/sequential.rb
|
164
164
|
- lib/sshkit/custom/config/store.rb
|
165
165
|
- lib/sshkit/custom/dsl.rb
|
166
166
|
- lib/sshkit/custom/dsl/config_statements.rb
|
@@ -1,49 +0,0 @@
|
|
1
|
-
module SSHKit
|
2
|
-
module Runner
|
3
|
-
class Abstract
|
4
|
-
attr_accessor :backends
|
5
|
-
|
6
|
-
def active_backend
|
7
|
-
self.class.active_backend
|
8
|
-
end
|
9
|
-
|
10
|
-
def active_backend=(new_backend)
|
11
|
-
self.class.active_backend=new_backend
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.scope_storage
|
15
|
-
ScopedStorage::ThreadLocalStorage
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.scope
|
19
|
-
@scope ||= ScopedStorage::Scope.new('sshkit_runner', scope_storage)
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.active_backend
|
23
|
-
scope[:active_backend]
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.active_backend=(new_backend)
|
27
|
-
scope[:active_backend]=new_backend
|
28
|
-
end
|
29
|
-
|
30
|
-
def send_cmd(cmd, *args, &block)
|
31
|
-
|
32
|
-
begin
|
33
|
-
|
34
|
-
if block
|
35
|
-
args = Array(block.call(active_backend.host))
|
36
|
-
end
|
37
|
-
|
38
|
-
active_backend.send(cmd, *args)
|
39
|
-
|
40
|
-
rescue Exception => e
|
41
|
-
e2 = ExecuteError.new e
|
42
|
-
raise e2, "Exception while executing on host #{active_backend.host}: #{e.message}"
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module SSHKit
|
2
|
-
module Runner
|
3
|
-
|
4
|
-
class Group < Sequential
|
5
|
-
attr_writer :group_size
|
6
|
-
|
7
|
-
def apply_block_to_bcks( &block)
|
8
|
-
backends.each_slice(group_size).collect do |group_backends|
|
9
|
-
|
10
|
-
Parallel.new(nil, nil).tap do |runner|
|
11
|
-
runner.backends = group_backends
|
12
|
-
runner.apply_block_to_bcks(&block)
|
13
|
-
end
|
14
|
-
|
15
|
-
sleep wait_interval
|
16
|
-
end.flatten
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module SSHKit
|
2
|
-
module Runner
|
3
|
-
|
4
|
-
class Parallel < Abstract
|
5
|
-
|
6
|
-
def apply_block_to_bcks( &block)
|
7
|
-
threads = []
|
8
|
-
backends.each do |host|
|
9
|
-
threads << Thread.new(host) do |h|
|
10
|
-
begin
|
11
|
-
|
12
|
-
self.active_backend = h
|
13
|
-
block.call(h.host)
|
14
|
-
|
15
|
-
rescue Exception => e
|
16
|
-
e2 = ExecuteError.new e
|
17
|
-
raise e2, "Exception while executing on host #{h}: #{e.message}"
|
18
|
-
ensure
|
19
|
-
self.active_backend = nil
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
threads.map(&:join)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module SSHKit
|
2
|
-
module Runner
|
3
|
-
class Sequential < Abstract
|
4
|
-
def apply_block_to_bcks( &block)
|
5
|
-
backends.each do |backend|
|
6
|
-
begin
|
7
|
-
|
8
|
-
self.active_backend = backend
|
9
|
-
block.call(backend.host)
|
10
|
-
|
11
|
-
rescue Exception => e
|
12
|
-
e2 = ExecuteError.new e
|
13
|
-
raise e2, "Exception while executing on host #{backend}: #{e.message}"
|
14
|
-
ensure
|
15
|
-
self.active_backend = nil
|
16
|
-
end
|
17
|
-
sleep wait_interval
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|