blower 2.1.3 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40847731e80163a484abde1221b6262ae1dda13a
4
- data.tar.gz: 3de0f99403ec2cba21482643e0972810e77252c0
3
+ metadata.gz: 9cfbaaa18cbeed95710091e851f7869055d0adb3
4
+ data.tar.gz: 5dba28a766c20b2c622a814687fe6defdc825982
5
5
  SHA512:
6
- metadata.gz: 850978d570b60a14a329f8e574377d72b4d6b76b6418e4657ec90118d64c00cca4dd71af8dad17077e3d37b919d9b5620f4461eb9ca578e38a3ff5cf343cc9e9
7
- data.tar.gz: 8c97ad6a254327b696061f16f9457e9a540465e20dd13b1b1bc9d9910cfd99908877283d2bb67e47be4b9fd78da626691ff7b60e8e96b48bf9c66c128df88217
6
+ metadata.gz: 720985c8137a5283d7b9909c767b39342d06b87ed8d83866f595ac44f18ccd86b6ce7286aca31bc4a54ba3246f148d5ddf63fc43b6351510d3d5100df84aa668
7
+ data.tar.gz: f6b2a4d82dc3ffc7ff803a082a8f1374e52b20f7f95c843aa8265197613f63dbec6d89d20962354da9441535bf5cd5458acab48d68408bbd5646fc426f621bec
@@ -28,30 +28,30 @@ module Blower
28
28
  def add_host (spec)
29
29
  host = Host.new(*spec) unless spec.is_a?(Host)
30
30
  @hosts << host
31
+ host
31
32
  end
32
33
 
33
- # Execute the block on one host.
34
- # @param host Host to use. If nil, a random host is picked.
35
- def one_host (host = nil, &block)
36
- map [host || target.hosts.sample], &block
37
- end
38
-
39
- # Execute the block once for each host.
40
- # Each block executes in a copy of the context.
34
+ # Execute the block once for each host and return nil.
41
35
  def each (hosts = @hosts, &block)
42
- map(hosts, &block)
43
- nil
36
+ Kernel.fail "No hosts left" if hosts.empty?
37
+ Enumerator.new do |y|
38
+ hosts.each do |host|
39
+ y << host
40
+ end
41
+ end.each(&block)
44
42
  end
45
43
 
46
- # Execute the block once for each host.
47
- # Each block executes in a copy of the context.
48
- def map (hosts = @hosts, &block)
49
- Kernel.fail "No hosts left" if hosts.empty?
50
- hosts.map do |host|
51
- Thread.new do
52
- block.(host)
44
+ # Execute the block once for each host and return a hash of the results.
45
+ def hashmap (hosts = @hosts, &block)
46
+ result = {}
47
+ threads = []
48
+ each hosts do |host|
49
+ threads << Thread.new do
50
+ result[host] = block.(host)
53
51
  end
54
- end.map(&:join)
52
+ end
53
+ threads.each(&:join)
54
+ result
55
55
  end
56
56
 
57
57
  # Reboot each host and waits for them to come back up.
@@ -64,6 +64,8 @@ module Blower
64
64
  end
65
65
  log.debug "Waiting for server to go away..."
66
66
  sleep 0.1 while ping(true)
67
+ end
68
+ each do
67
69
  log.debug "Waiting for server to come back..."
68
70
  sleep 1.0 until ping(true)
69
71
  end
@@ -72,9 +74,16 @@ module Blower
72
74
  # Execute a shell command on each host.
73
75
  def sh (command, quiet = false)
74
76
  log.info "sh: #{command}" unless quiet
75
- map do |host|
76
- status = host.sh(command)
77
- fail host, "#{command}: exit status #{status}" if status != 0
77
+ win = true
78
+ hashmap do |host|
79
+ out = ""
80
+ status = host.sh(command, out)
81
+ if status != 0
82
+ fail host, "#{command}: exit status #{status}"
83
+ nil
84
+ else
85
+ out
86
+ end
78
87
  end
79
88
  end
80
89
 
@@ -83,7 +92,7 @@ module Blower
83
92
  def sh? (command, quiet = false)
84
93
  log.info "sh?: #{command}" unless quiet
85
94
  win = true
86
- map do |host|
95
+ each do |host|
87
96
  status = host.sh(command)
88
97
  win = false if status != 0
89
98
  end
@@ -95,7 +104,7 @@ module Blower
95
104
  def ping (quiet = false)
96
105
  log.info "ping" unless quiet
97
106
  win = true
98
- map do |host|
107
+ each do |host|
99
108
  win &&= host.ping
100
109
  end
101
110
  win
@@ -110,7 +119,7 @@ module Blower
110
119
  # @param to A string.
111
120
  def cp (from, to)
112
121
  log.info "cp: #{from} -> #{to}"
113
- map do |host|
122
+ each do |host|
114
123
  host.cp(from, to)
115
124
  end
116
125
  end
@@ -123,14 +132,6 @@ module Blower
123
132
  target.cp(StringIO.new(string), to)
124
133
  end
125
134
 
126
- # Capture the output a command on the remote host.
127
- # @return (String) The combined stdout and stderr of the command.
128
- def capture (command)
129
- stdout = ""
130
- target.sh(command, stdout)
131
- stdout
132
- end
133
-
134
135
  # Run a task.
135
136
  # @param task (String) The name of the task
136
137
  def run (task, optional: false)
data/lib/blower/host.rb CHANGED
@@ -102,7 +102,7 @@ module Blower
102
102
  end
103
103
 
104
104
  # Execute the block with self as a parameter.
105
- # Exists to confirm with the HostGroup interface.
105
+ # Exists to conform with the HostGroup interface.
106
106
  def each (&block)
107
107
  block.(self)
108
108
  end
@@ -1,3 +1,3 @@
1
1
  module Blower
2
- VERSION = "2.1.3"
2
+ VERSION = "2.2.0"
3
3
  end
data/lib/blower.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'blower/logger'
2
2
  require 'blower/context'
3
3
  require 'blower/host'
4
- require 'blower/mock_host'
5
4
  require 'blower/version'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blower
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Baum
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-19 00:00:00.000000000 Z
11
+ date: 2016-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh
@@ -78,7 +78,6 @@ files:
78
78
  - lib/blower/context.rb
79
79
  - lib/blower/host.rb
80
80
  - lib/blower/logger.rb
81
- - lib/blower/mock_host.rb
82
81
  - lib/blower/version.rb
83
82
  homepage: http://www.github.org/nbaum/blower
84
83
  licenses:
@@ -1,42 +0,0 @@
1
- module Blower
2
-
3
- class MockHost
4
- extend Forwardable
5
-
6
- attr_accessor :log
7
- attr_accessor :data
8
-
9
- def_delegators :data, :[], :[]=
10
-
11
- def initialize (name)
12
- @log = Logger.new("mock #{name.ljust(15)} | ")
13
- @data = {}
14
- end
15
-
16
- def sh (command, stdout: nil, stdin: nil)
17
- log.info command
18
- sleep rand * 0.1
19
- end
20
-
21
- def cp (from, to, quiet: false)
22
- if from.is_a?(String)
23
- to += File.basename(from) if to[-1] == "/"
24
- log.info "#{from} -> #{to}" unless quiet
25
- elsif from.is_a?(Array)
26
- to += "/" unless to[-1] == "/"
27
- log.info "#{from.join(", ")} -> #{to}" unless quiet
28
- elsif from.is_a?(StringIO) or from.is_a?(IO)
29
- log.info "string -> #{to}" unless quiet
30
- else
31
- fail "Don't know how to copy a #{from.class}: #{from}"
32
- end
33
- sleep rand * 0.1
34
- end
35
-
36
- def each (&block)
37
- block.(self)
38
- end
39
-
40
- end
41
-
42
- end