sshkit 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,11 @@
3
3
  This file is written in reverse chronological order, newer releases will
4
4
  appear at the top.
5
5
 
6
+ ## 0.0.4
7
+
8
+ * Rename the ConnectionManager class to Coordinator, connections are handled
9
+ in the backend, if it needs to create some connections.
10
+
6
11
  ## 0.0.3
7
12
 
8
13
  * Refactor the runner classes into an abstract heirarchy.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sshkit (0.0.2)
4
+ sshkit (0.0.3)
5
5
  net-ssh
6
6
  term-ansicolor
7
7
 
@@ -6,13 +6,18 @@ require_relative 'host'
6
6
 
7
7
  require_relative 'command'
8
8
  require_relative 'configuration'
9
- require_relative 'connection_manager'
9
+ require_relative 'coordinator'
10
10
 
11
11
  require_relative 'formatters/abstract'
12
12
  require_relative 'formatters/black_hole'
13
13
  require_relative 'formatters/pretty'
14
14
  require_relative 'formatters/dot'
15
15
 
16
+ require_relative 'runners/abstract'
17
+ require_relative 'runners/sequential'
18
+ require_relative 'runners/parallel'
19
+ require_relative 'runners/group'
20
+
16
21
  require_relative 'backends/abstract'
17
22
  require_relative 'backends/printer'
18
23
  require_relative 'backends/netssh'
@@ -0,0 +1,38 @@
1
+ module SSHKit
2
+
3
+ class Coordinator
4
+
5
+ attr_accessor :hosts
6
+
7
+ def initialize(raw_hosts)
8
+ @raw_hosts = Array(raw_hosts)
9
+ raise NoValidHosts unless Array(raw_hosts).any?
10
+ resolve_hosts!
11
+ end
12
+
13
+ def each(options={}, &block)
14
+ options = default_options.merge(options)
15
+ case options[:in]
16
+ when :parallel then Runner::Parallel
17
+ when :sequence then Runner::Sequential
18
+ when :groups then Runner::Group
19
+ else
20
+ raise RuntimeError, "Don't know how to handle run style #{options[:in].inspect}"
21
+ end.new(hosts, &block).execute
22
+ end
23
+
24
+ private
25
+
26
+ attr_accessor :cooldown
27
+
28
+ def default_options
29
+ { in: :parallel }
30
+ end
31
+
32
+ def resolve_hosts!
33
+ @hosts = @raw_hosts.collect { |rh| rh.is_a?(Host) ? rh : Host.new(rh) }.uniq
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -5,7 +5,7 @@ module SSHKit
5
5
  module DSL
6
6
 
7
7
  def on(hosts, options={}, &block)
8
- ConnectionManager.new(hosts).each(options, &block)
8
+ Coordinator.new(hosts).each(options, &block)
9
9
  end
10
10
 
11
11
  end
@@ -0,0 +1,24 @@
1
+ module SSHKit
2
+
3
+ module Runner
4
+
5
+ class Abstract
6
+
7
+ attr_reader :hosts, :block
8
+
9
+ def initialize(hosts, &block)
10
+ @hosts = Array(hosts)
11
+ @block = block
12
+ end
13
+
14
+ private
15
+
16
+ def backend(host, &block)
17
+ SSHKit.config.backend.new(host, &block)
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,21 @@
1
+ module SSHKit
2
+
3
+ module Runner
4
+
5
+ class Group < Sequential
6
+ attr_writer :group_size
7
+ def execute
8
+ hosts.each_slice(group_size).collect do |group_hosts|
9
+ Parallel.new(group_hosts, &block).execute
10
+ sleep wait_interval
11
+ end.flatten
12
+ end
13
+ private
14
+ def group_size
15
+ @group_size ||= 2
16
+ end
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -1,5 +1,3 @@
1
- require 'timeout'
2
-
3
1
  module SSHKit
4
2
 
5
3
  module Runner
@@ -64,44 +62,3 @@ module SSHKit
64
62
  end
65
63
 
66
64
  end
67
-
68
- module SSHKit
69
-
70
- NoValidHosts = Class.new(StandardError)
71
-
72
- class ConnectionManager
73
-
74
- attr_accessor :hosts
75
-
76
- def initialize(raw_hosts)
77
- @raw_hosts = Array(raw_hosts)
78
- raise NoValidHosts unless Array(raw_hosts).any?
79
- resolve_hosts!
80
- end
81
-
82
- def each(options={}, &block)
83
- options = default_options.merge(options)
84
- case options[:in]
85
- when :parallel then Runner::Parallel
86
- when :sequence then Runner::Sequential
87
- when :groups then Runner::Group
88
- else
89
- raise RuntimeError, "Don't know how to handle run style #{options[:in].inspect}"
90
- end.new(hosts, &block).execute
91
- end
92
-
93
- private
94
-
95
- attr_accessor :cooldown
96
-
97
- def default_options
98
- { in: :parallel }
99
- end
100
-
101
- def resolve_hosts!
102
- @hosts = @raw_hosts.collect { |rh| rh.is_a?(Host) ? rh : Host.new(rh) }.uniq
103
- end
104
-
105
- end
106
-
107
- end
@@ -0,0 +1,21 @@
1
+ module SSHKit
2
+
3
+ module Runner
4
+
5
+ class Sequential < Abstract
6
+ attr_writer :wait_interval
7
+ def execute
8
+ hosts.each do |host|
9
+ backend(host, &block).run
10
+ sleep wait_interval
11
+ end
12
+ end
13
+ private
14
+ def wait_interval
15
+ @wait_interval ||= 2
16
+ end
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -1,3 +1,3 @@
1
1
  module SSHKit
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -2,7 +2,7 @@ require 'helper'
2
2
 
3
3
  module SSHKit
4
4
 
5
- class TestConnectionManager < FunctionalTest
5
+ class TestCoordinator < FunctionalTest
6
6
 
7
7
  def setup
8
8
 
@@ -3,7 +3,7 @@ require 'helper'
3
3
 
4
4
  module SSHKit
5
5
 
6
- class TestConnectionManager < UnitTest
6
+ class TestCoordinator < UnitTest
7
7
 
8
8
  def setup
9
9
  @s = String.new
@@ -23,17 +23,17 @@ module SSHKit
23
23
  def test_connection_manager_handles_a_single_argument
24
24
  h = Host.new('1.example.com')
25
25
  Host.expects(:new).with('1.example.com').once().returns(h)
26
- ConnectionManager.new '1.example.com'
26
+ Coordinator.new '1.example.com'
27
27
  end
28
28
 
29
29
  def test_connection_manager_resolves_hosts
30
30
  h = Host.new('n.example.com')
31
31
  Host.expects(:new).times(3).returns(h)
32
- ConnectionManager.new %w{1.example.com 2.example.com 3.example.com}
32
+ Coordinator.new %w{1.example.com 2.example.com 3.example.com}
33
33
  end
34
34
 
35
35
  def test_connection_manager_removes_duplicates_after_resolving_hosts
36
- cm = ConnectionManager.new %w{user@1.example.com:22 user@1.example.com}
36
+ cm = Coordinator.new %w{user@1.example.com:22 user@1.example.com}
37
37
  assert_equal ['user@1.example.com:22'], cm.hosts.map(&:to_s)
38
38
  end
39
39
 
@@ -43,7 +43,7 @@ module SSHKit
43
43
  end
44
44
  String.new.tap do |str|
45
45
  SSHKit.capture_output str do
46
- ConnectionManager.new(%w{1.example.com}).each &spy
46
+ Coordinator.new(%w{1.example.com}).each &spy
47
47
  end
48
48
  assert_equal "echo 1.example.com", str.strip
49
49
  end
@@ -51,7 +51,7 @@ module SSHKit
51
51
 
52
52
  def test_the_connection_manaager_runs_things_in_parallel_by_default
53
53
  SSHKit.capture_output @s do
54
- ConnectionManager.new(%w{1.example.com 2.example.com}).each &block_to_run
54
+ Coordinator.new(%w{1.example.com 2.example.com}).each &block_to_run
55
55
  end
56
56
  assert_equal 2, results.length
57
57
  assert_equal *results.map(&:to_i)
@@ -59,7 +59,7 @@ module SSHKit
59
59
 
60
60
  def test_the_connection_manager_can_run_things_in_sequence
61
61
  SSHKit.capture_output @s do
62
- ConnectionManager.new(%w{1.example.com 2.example.com}).each in: :sequence, &block_to_run
62
+ Coordinator.new(%w{1.example.com 2.example.com}).each in: :sequence, &block_to_run
63
63
  end
64
64
  assert_equal 2, results.length
65
65
  assert_operator results.first.to_i, :<, results.last.to_i
@@ -67,7 +67,7 @@ module SSHKit
67
67
 
68
68
  def test_the_connection_manager_can_run_things_in_groups
69
69
  SSHKit.capture_output @s do
70
- ConnectionManager.new(%w{1.example.com 2.example.com 3.example.com
70
+ Coordinator.new(%w{1.example.com 2.example.com 3.example.com
71
71
  4.example.com 5.example.com 6.example.com}).each in: :groups, &block_to_run
72
72
  end
73
73
  assert_equal 6, results.length
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sshkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -245,16 +245,20 @@ files:
245
245
  - lib/sshkit/backends/printer.rb
246
246
  - lib/sshkit/command.rb
247
247
  - lib/sshkit/configuration.rb
248
- - lib/sshkit/connection_manager.rb
248
+ - lib/sshkit/coordinator.rb
249
249
  - lib/sshkit/dsl.rb
250
250
  - lib/sshkit/formatters/abstract.rb
251
251
  - lib/sshkit/formatters/black_hole.rb
252
252
  - lib/sshkit/formatters/dot.rb
253
253
  - lib/sshkit/formatters/pretty.rb
254
254
  - lib/sshkit/host.rb
255
+ - lib/sshkit/runners/abstract.rb
256
+ - lib/sshkit/runners/group.rb
257
+ - lib/sshkit/runners/parallel.rb
258
+ - lib/sshkit/runners/sequential.rb
255
259
  - lib/sshkit/version.rb
256
260
  - sshkit.gemspec
257
- - test/functional/test_connection_manager.rb
261
+ - test/functional/test_coordinator.rb
258
262
  - test/functional/test_ssh_server_comes_up_for_functional_tests.rb
259
263
  - test/helper.rb
260
264
  - test/integration/backends/test_netssh.rb
@@ -263,7 +267,7 @@ files:
263
267
  - test/unit/core_ext/test_string.rb
264
268
  - test/unit/test_command.rb
265
269
  - test/unit/test_configuration.rb
266
- - test/unit/test_connection_manager.rb
270
+ - test/unit/test_coordinator.rb
267
271
  - test/unit/test_host.rb
268
272
  homepage: http://wacku.github.com/sshkit
269
273
  licenses: []
@@ -290,7 +294,7 @@ signing_key:
290
294
  specification_version: 3
291
295
  summary: SSHKit makes it easy to write structured, testable SSH commands in Ruby
292
296
  test_files:
293
- - test/functional/test_connection_manager.rb
297
+ - test/functional/test_coordinator.rb
294
298
  - test/functional/test_ssh_server_comes_up_for_functional_tests.rb
295
299
  - test/helper.rb
296
300
  - test/integration/backends/test_netssh.rb
@@ -299,6 +303,6 @@ test_files:
299
303
  - test/unit/core_ext/test_string.rb
300
304
  - test/unit/test_command.rb
301
305
  - test/unit/test_configuration.rb
302
- - test/unit/test_connection_manager.rb
306
+ - test/unit/test_coordinator.rb
303
307
  - test/unit/test_host.rb
304
308
  has_rdoc: