rye 0.9.5 → 0.9.6
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.
- data/CHANGES.txt +4 -0
- data/lib/rye.rb +1 -1
- data/lib/rye/set.rb +58 -51
- data/rye.gemspec +1 -1
- metadata +93 -66
data/CHANGES.txt
CHANGED
data/lib/rye.rb
CHANGED
data/lib/rye/set.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# vim: set sw=2 ts=2 :
|
2
2
|
|
3
3
|
module Rye
|
4
|
-
|
4
|
+
|
5
5
|
# = Rye::Set
|
6
6
|
#
|
7
7
|
#
|
@@ -9,15 +9,15 @@ module Rye
|
|
9
9
|
attr_reader :name
|
10
10
|
attr_reader :boxes
|
11
11
|
attr_reader :opts
|
12
|
-
|
12
|
+
|
13
13
|
# Run commands in parallel? A Boolean value. Default: false.
|
14
14
|
attr_accessor :parallel
|
15
|
-
|
16
|
-
|
15
|
+
|
16
|
+
|
17
17
|
# * +name+ The name of the set of machines
|
18
|
-
# * +opts+ a hash of optional arguments
|
18
|
+
# * +opts+ a hash of optional arguments
|
19
19
|
#
|
20
|
-
# The +opts+ hash is used as defaults for all for all Rye::Box objects.
|
20
|
+
# The +opts+ hash is used as defaults for all for all Rye::Box objects.
|
21
21
|
# All args supported by Rye::Box are available here with the addition of:
|
22
22
|
#
|
23
23
|
# * :parallel => run the commands in parallel? true or false (default).
|
@@ -25,11 +25,11 @@ module Rye
|
|
25
25
|
def initialize(name='default', opts={})
|
26
26
|
@name = name
|
27
27
|
@boxes = []
|
28
|
-
|
28
|
+
|
29
29
|
# These opts are use by Rye::Box and also passed to Net::SSH
|
30
30
|
@opts = {
|
31
31
|
:parallel => false,
|
32
|
-
:user => Rye.sysinfo.user,
|
32
|
+
:user => Rye.sysinfo.user,
|
33
33
|
:safe => true,
|
34
34
|
:port => 22,
|
35
35
|
:keys => [],
|
@@ -38,36 +38,36 @@ module Rye
|
|
38
38
|
:debug => nil,
|
39
39
|
:error => STDERR,
|
40
40
|
}.merge(opts)
|
41
|
-
|
41
|
+
|
42
42
|
@parallel = @opts.delete(:parallel) # Rye::Box doesn't have :parallel
|
43
|
-
|
43
|
+
|
44
44
|
@safe = @opts.delete(:safe)
|
45
45
|
@debug = @opts.delete(:debug)
|
46
46
|
@error = @opts.delete(:error)
|
47
|
-
|
47
|
+
|
48
48
|
@opts[:keys] = [@opts[:keys]].flatten.compact
|
49
|
-
|
49
|
+
|
50
50
|
add_keys(@opts[:keys])
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
def opts; @opts; end
|
54
54
|
def user; (@opts || {})[:user]; end
|
55
55
|
def root?; user.to_s == "root" end
|
56
|
-
|
57
|
-
# * +boxes+ one or more boxes. Rye::Box objects will be added directly
|
58
|
-
# to the set. Hostnames will be used to create new instances of Rye::Box
|
59
|
-
# and those will be added to the list.
|
56
|
+
|
57
|
+
# * +boxes+ one or more boxes. Rye::Box objects will be added directly
|
58
|
+
# to the set. Hostnames will be used to create new instances of Rye::Box
|
59
|
+
# and those will be added to the list.
|
60
60
|
def add_box(*boxes)
|
61
|
-
boxes = boxes.flatten.compact
|
61
|
+
boxes = boxes.flatten.compact
|
62
62
|
@boxes += boxes.collect do |box|
|
63
|
-
box = Rye::Box.new(box, @opts) if box.is_a?(String)
|
63
|
+
box = Rye::Box.new(box, @opts) if box.is_a?(String)
|
64
64
|
box.add_keys(@keys)
|
65
65
|
box
|
66
66
|
end
|
67
67
|
self
|
68
68
|
end
|
69
69
|
alias :add_boxes :add_box
|
70
|
-
|
70
|
+
|
71
71
|
# Add one or more private keys to each box. Also stores key paths
|
72
72
|
# in the set so when new boxes are added they will get the same keys,
|
73
73
|
# * +additional_keys+ is a list of file paths to private keys
|
@@ -83,7 +83,7 @@ module Rye
|
|
83
83
|
self
|
84
84
|
end
|
85
85
|
alias :add_key :add_keys
|
86
|
-
|
86
|
+
|
87
87
|
def remove_keys(*keys)
|
88
88
|
@opts[:keys] ||= []
|
89
89
|
@opts[:keys] -= keys.flatten.compact
|
@@ -93,7 +93,7 @@ module Rye
|
|
93
93
|
self
|
94
94
|
end
|
95
95
|
alias :remove_key :remove_keys
|
96
|
-
|
96
|
+
|
97
97
|
# Add an environment variable. +n+ and +v+ are the name and value.
|
98
98
|
# Returns the instance of Rye::Set
|
99
99
|
def setenv(n, v)
|
@@ -101,21 +101,21 @@ module Rye
|
|
101
101
|
self
|
102
102
|
end
|
103
103
|
alias :setenvironment_variable :setenv
|
104
|
-
|
104
|
+
|
105
105
|
# See Rye.keys
|
106
106
|
def keys
|
107
107
|
Rye.keys
|
108
108
|
end
|
109
|
-
|
109
|
+
|
110
110
|
def to_s
|
111
111
|
"%s:%s" % [self.class.to_s, @name]
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
def inspect
|
115
115
|
a = [self.class.to_s, @name, @parallel, @opts.inspect, @boxes.inspect]
|
116
116
|
%q{#<%s:%s parallel=%s opts=%s boxes=%s>} % a
|
117
117
|
end
|
118
|
-
|
118
|
+
|
119
119
|
# See Rye::Box.[]
|
120
120
|
def [](key=nil)
|
121
121
|
run_command(:cd, key)
|
@@ -126,20 +126,20 @@ module Rye
|
|
126
126
|
run_command(:cd, key)
|
127
127
|
self
|
128
128
|
end
|
129
|
-
|
129
|
+
|
130
130
|
# Are there any boxes in this set?
|
131
131
|
def empty?
|
132
132
|
@boxes.nil? || @boxes.empty?
|
133
133
|
end
|
134
|
-
|
135
|
-
# Catches calls to Rye::Box commands. If +meth+ is the name of an
|
136
|
-
# instance method defined in Rye::Cmd then we call it against all
|
134
|
+
|
135
|
+
# Catches calls to Rye::Box commands. If +meth+ is the name of an
|
136
|
+
# instance method defined in Rye::Cmd then we call it against all
|
137
137
|
# the boxes in +@boxes+. Otherwise this method raises a
|
138
138
|
# Rye::CommandNotFound exception. It will also raise a Rye::NoBoxes
|
139
|
-
# exception if this set has no boxes defined.
|
139
|
+
# exception if this set has no boxes defined.
|
140
140
|
#
|
141
|
-
# Returns a Rye::Rap object containing the responses from each Rye::Box.
|
142
|
-
def method_missing(meth, *args, &block)
|
141
|
+
# Returns a Rye::Rap object containing the responses from each Rye::Box.
|
142
|
+
def method_missing(meth, *args, &block)
|
143
143
|
# Ruby 1.8 populates Module.instance_methods with Strings. 1.9 uses Symbols.
|
144
144
|
meth = (Rye.sysinfo.ruby[1] == 8) ? meth.to_s : meth.to_sym
|
145
145
|
raise Rye::NoBoxes if @boxes.empty?
|
@@ -148,39 +148,46 @@ module Rye
|
|
148
148
|
end
|
149
149
|
run_command(meth, *args, &block)
|
150
150
|
end
|
151
|
-
|
151
|
+
|
152
152
|
private
|
153
|
-
|
154
|
-
# Determines whether to call the serial or parallel method, then calls it.
|
153
|
+
|
154
|
+
# Determines whether to call the serial or parallel method, then calls it.
|
155
155
|
def run_command(meth, *args, &block)
|
156
156
|
runner = @parallel ? :run_command_parallel : :run_command_serial
|
157
157
|
self.send(runner, meth, *args, &block)
|
158
158
|
end
|
159
|
-
|
160
|
-
|
159
|
+
|
160
|
+
|
161
161
|
# Run the command on all boxes in parallel
|
162
162
|
def run_command_parallel(meth, *args, &block)
|
163
163
|
debug "P: #{meth} on #{@boxes.size} boxes (#{@boxes.collect {|b| b.host }.join(', ')})"
|
164
164
|
threads = []
|
165
|
-
|
165
|
+
|
166
166
|
raps = Rye::Rap.new(self)
|
167
167
|
(@boxes || []).each do |box|
|
168
168
|
threads << Thread.new do
|
169
169
|
Thread.current[:rap] = box.send(meth, *args, &block) # Store the result in the thread
|
170
170
|
end
|
171
171
|
end
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
172
|
+
|
173
|
+
threads.each do |t|
|
174
|
+
Kernel.sleep 0.03 # Give the thread some breathing room
|
175
|
+
|
176
|
+
begin
|
177
|
+
t.join # Wait for the thread to finish
|
178
|
+
rescue Exception => ex
|
179
|
+
# Store the exception in the result
|
180
|
+
raps << Rap.new(self, [ex])
|
181
|
+
next
|
182
|
+
end
|
183
|
+
|
184
|
+
raps << t[:rap] # Grab the result
|
178
185
|
end
|
179
|
-
|
186
|
+
|
180
187
|
raps
|
181
188
|
end
|
182
|
-
|
183
|
-
|
189
|
+
|
190
|
+
|
184
191
|
# Run the command on all boxes in serial
|
185
192
|
def run_command_serial(meth, *args, &block)
|
186
193
|
debug "S: #{meth} on #{@boxes.size} boxes (#{@boxes.collect {|b| b.host }.join(', ')})"
|
@@ -190,10 +197,10 @@ module Rye
|
|
190
197
|
end
|
191
198
|
raps
|
192
199
|
end
|
193
|
-
|
200
|
+
|
194
201
|
def debug(msg); @debug.puts msg if @debug; end
|
195
202
|
def error(msg); @error.puts msg if @error; end
|
196
|
-
|
203
|
+
|
197
204
|
end
|
198
|
-
|
205
|
+
|
199
206
|
end
|
data/rye.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
@spec = Gem::Specification.new do |s|
|
2
2
|
s.name = "rye"
|
3
3
|
s.rubyforge_project = "rye"
|
4
|
-
s.version = "0.9.
|
4
|
+
s.version = "0.9.6"
|
5
5
|
s.summary = "Rye: Safely run SSH commands on a bunch of machines at the same time (from Ruby)."
|
6
6
|
s.description = s.summary
|
7
7
|
s.author = "Delano Mandelbaum"
|
metadata
CHANGED
@@ -1,82 +1,105 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rye
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.6
|
4
5
|
prerelease:
|
5
|
-
version: 0.9.5
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Delano Mandelbaum
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-05-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: annoy
|
17
|
-
|
18
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
19
17
|
none: false
|
20
|
-
requirements:
|
21
|
-
- -
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
24
22
|
type: :runtime
|
25
|
-
version_requirements: *id001
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: sysinfo
|
28
23
|
prerelease: false
|
29
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
25
|
none: false
|
31
|
-
requirements:
|
32
|
-
- -
|
33
|
-
- !ruby/object:Gem::Version
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: sysinfo
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
34
37
|
version: 0.7.3
|
35
38
|
type: :runtime
|
36
|
-
version_requirements: *id002
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: highline
|
39
39
|
prerelease: false
|
40
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.7.3
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: highline
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
45
53
|
version: 1.5.1
|
46
54
|
type: :runtime
|
47
|
-
version_requirements: *id003
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: net-ssh
|
50
55
|
prerelease: false
|
51
|
-
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
57
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.5.1
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: net-ssh
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
56
69
|
version: 2.0.13
|
57
70
|
type: :runtime
|
58
|
-
version_requirements: *id004
|
59
|
-
- !ruby/object:Gem::Dependency
|
60
|
-
name: net-scp
|
61
71
|
prerelease: false
|
62
|
-
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
73
|
none: false
|
64
|
-
requirements:
|
65
|
-
- -
|
66
|
-
- !ruby/object:Gem::Version
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 2.0.13
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: net-scp
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
67
85
|
version: 1.0.2
|
68
86
|
type: :runtime
|
69
|
-
|
70
|
-
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.0.2
|
94
|
+
description: ! 'Rye: Safely run SSH commands on a bunch of machines at the same time
|
95
|
+
(from Ruby).'
|
71
96
|
email: delano@solutious.com
|
72
97
|
executables: []
|
73
|
-
|
74
98
|
extensions: []
|
75
|
-
|
76
|
-
extra_rdoc_files:
|
99
|
+
extra_rdoc_files:
|
77
100
|
- README.rdoc
|
78
101
|
- LICENSE.txt
|
79
|
-
files:
|
102
|
+
files:
|
80
103
|
- CHANGES.txt
|
81
104
|
- LICENSE.txt
|
82
105
|
- README.rdoc
|
@@ -94,34 +117,38 @@ files:
|
|
94
117
|
- rye.gemspec
|
95
118
|
homepage: http://github.com/delano/rye/
|
96
119
|
licenses: []
|
97
|
-
|
98
120
|
post_install_message:
|
99
|
-
rdoc_options:
|
121
|
+
rdoc_options:
|
100
122
|
- --line-numbers
|
101
123
|
- --title
|
102
|
-
-
|
124
|
+
- ! 'Rye: Safely run SSH commands on a bunch of machines at the same time (from Ruby).'
|
103
125
|
- --main
|
104
126
|
- README.rdoc
|
105
|
-
require_paths:
|
127
|
+
require_paths:
|
106
128
|
- lib
|
107
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
130
|
none: false
|
109
|
-
requirements:
|
110
|
-
- -
|
111
|
-
- !ruby/object:Gem::Version
|
112
|
-
version:
|
113
|
-
|
131
|
+
requirements:
|
132
|
+
- - ! '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
hash: 614630044624283309
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
139
|
none: false
|
115
|
-
requirements:
|
116
|
-
- -
|
117
|
-
- !ruby/object:Gem::Version
|
118
|
-
version:
|
140
|
+
requirements:
|
141
|
+
- - ! '>='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
segments:
|
145
|
+
- 0
|
146
|
+
hash: 614630044624283309
|
119
147
|
requirements: []
|
120
|
-
|
121
148
|
rubyforge_project: rye
|
122
|
-
rubygems_version: 1.8.
|
149
|
+
rubygems_version: 1.8.22
|
123
150
|
signing_key:
|
124
151
|
specification_version: 2
|
125
|
-
summary:
|
152
|
+
summary: ! 'Rye: Safely run SSH commands on a bunch of machines at the same time (from
|
153
|
+
Ruby).'
|
126
154
|
test_files: []
|
127
|
-
|