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 +4 -4
- data/lib/blower/context.rb +33 -32
- data/lib/blower/host.rb +1 -1
- data/lib/blower/version.rb +1 -1
- data/lib/blower.rb +0 -1
- metadata +2 -3
- data/lib/blower/mock_host.rb +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9cfbaaa18cbeed95710091e851f7869055d0adb3
|
4
|
+
data.tar.gz: 5dba28a766c20b2c622a814687fe6defdc825982
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 720985c8137a5283d7b9909c767b39342d06b87ed8d83866f595ac44f18ccd86b6ce7286aca31bc4a54ba3246f148d5ddf63fc43b6351510d3d5100df84aa668
|
7
|
+
data.tar.gz: f6b2a4d82dc3ffc7ff803a082a8f1374e52b20f7f95c843aa8265197613f63dbec6d89d20962354da9441535bf5cd5458acab48d68408bbd5646fc426f621bec
|
data/lib/blower/context.rb
CHANGED
@@ -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
|
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
|
-
|
43
|
-
|
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
|
-
|
48
|
-
|
49
|
-
|
50
|
-
hosts
|
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
|
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
|
-
|
76
|
-
|
77
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
data/lib/blower/version.rb
CHANGED
data/lib/blower.rb
CHANGED
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.
|
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-
|
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:
|
data/lib/blower/mock_host.rb
DELETED
@@ -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
|