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.
@@ -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