weave 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +0 -16
- data/lib/weave.rb +14 -5
- data/lib/weave/version.rb +1 -1
- data/test/integrations/sanity_test.rb +19 -9
- data/weave.gemspec +0 -1
- metadata +40 -38
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a59144545dbba7f902dae6c32554a3f2743861e1
|
4
|
+
data.tar.gz: 495f658b7d46a8dd442e299f1b2e6b5f18974238
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ca9f0be174aa7bae005d03c9937944539e1826c680dda6cf6c8fdc5fcf3d36abefb4649ee3344d65d6b5a585f093fee8dee017c3112a3f704d4e87e9feb7db6e
|
7
|
+
data.tar.gz: 226c169a961c1cb2f40238c10be1ce68ce881d3bc1d67e447e9c32785b3f46317e0721d34dfc33bd17e0871904defee92fb1c170bb2a8bfb56151a377fbae4c6
|
data/README.md
CHANGED
@@ -22,19 +22,3 @@ examples (in `examples/`) to get started.
|
|
22
22
|
* Commands:
|
23
23
|
|
24
24
|
- `run`
|
25
|
-
|
26
|
-
## Other ideas
|
27
|
-
|
28
|
-
* Commands:
|
29
|
-
|
30
|
-
- `sudo`
|
31
|
-
- `rsync`
|
32
|
-
- `put`?
|
33
|
-
- `get`?
|
34
|
-
|
35
|
-
* Handle password prompts (maybe just sudo prompt)
|
36
|
-
* Handle ctrl-c correctly?
|
37
|
-
|
38
|
-
## To do:
|
39
|
-
|
40
|
-
* Full readme with detailed usage
|
data/lib/weave.rb
CHANGED
@@ -58,8 +58,10 @@ module Weave
|
|
58
58
|
|
59
59
|
# A pool of SSH connections. Operations over the pool may be performed in serial or in parallel.
|
60
60
|
class ConnectionPool
|
61
|
-
# @param [Array] host_list the array of hosts, of the form user@host
|
62
|
-
|
61
|
+
# @param [Array] host_list the array of hosts, of the form user@host. You may leave off this argument, and
|
62
|
+
# use #execute_with (instead of #execute) to specify the whole list of hosts each time.
|
63
|
+
def initialize(host_list = [])
|
64
|
+
@hosts = host_list
|
63
65
|
@connections = host_list.reduce({}) { |pool, host| pool.merge(host => LazyConnection.new(host)) }
|
64
66
|
end
|
65
67
|
|
@@ -73,18 +75,25 @@ module Weave
|
|
73
75
|
# @option options [Fixnum] :batch_by if set, group the connections into batches of no more than this value
|
74
76
|
# and fully process each batch before starting the next one.
|
75
77
|
def execute(options = {}, &block)
|
78
|
+
execute_with(@hosts, options, &block)
|
79
|
+
end
|
80
|
+
|
81
|
+
# This is the same as #execute, except that host_list overrides the list of connections with which this
|
82
|
+
# ConnectionPool was initialized. Any hosts in here that weren't already in the pool will be added.
|
83
|
+
def execute_with(host_list, options = {}, &block)
|
84
|
+
host_list.each { |host| @connections[host] ||= LazyConnection.new(host) }
|
76
85
|
args = options[:args] || []
|
77
86
|
options[:num_threads] ||= DEFAULT_THREAD_POOL_SIZE
|
78
87
|
if options[:serial]
|
79
|
-
|
88
|
+
host_list.each { |host| @connections[host].self_eval args, &block }
|
80
89
|
elsif options[:batch_by]
|
81
|
-
|
90
|
+
host_list.each_slice(options[:batch_by]) do |batch|
|
82
91
|
Weave.with_thread_pool(batch, options[:num_threads]) do |host, mutex|
|
83
92
|
@connections[host].self_eval args, mutex, &block
|
84
93
|
end
|
85
94
|
end
|
86
95
|
else
|
87
|
-
Weave.with_thread_pool(
|
96
|
+
Weave.with_thread_pool(host_list, options[:num_threads]) do |host, mutex|
|
88
97
|
@connections[host].self_eval args, mutex, &block
|
89
98
|
end
|
90
99
|
end
|
data/lib/weave/version.rb
CHANGED
@@ -10,17 +10,17 @@ class SanityTest < Scope::TestCase
|
|
10
10
|
|
11
11
|
setup_once do
|
12
12
|
# Make sure the machines are up.
|
13
|
-
vagrant_status =
|
13
|
+
vagrant_status = `/usr/bin/vagrant status`
|
14
14
|
unless $?.to_i.zero? && TEST_HOSTS.each { |host| vagrant_status =~ /#{host}\w+running/ }
|
15
15
|
abort "You need to set up the test vagrant virtual machines to run the sanity test." \
|
16
|
-
"Run '
|
16
|
+
"Run 'vagrant up'."
|
17
17
|
end
|
18
18
|
# Make sure the user's ssh config has weave entries.
|
19
19
|
TEST_HOSTS.each do |host|
|
20
20
|
config = Net::SSH::Config.load("~/.ssh/config", host)
|
21
21
|
unless config["hostname"] == "127.0.0.1"
|
22
22
|
abort "You need to add weave{1,2} to your ~/.ssh/config." \
|
23
|
-
"You can use the output of '
|
23
|
+
"You can use the output of 'vagrant ssh-config weave1'"
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -33,7 +33,7 @@ class SanityTest < Scope::TestCase
|
|
33
33
|
end
|
34
34
|
TEST_HOSTS.each do |host|
|
35
35
|
assert_empty output[host][:stderr]
|
36
|
-
assert_equal
|
36
|
+
assert_equal "hello\n", output[host][:stdout]
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -51,24 +51,24 @@ class SanityTest < Scope::TestCase
|
|
51
51
|
|
52
52
|
context "in serial" do
|
53
53
|
should "run some commands in the expected order" do
|
54
|
-
output =
|
54
|
+
output = ""
|
55
55
|
Weave.connect(ROOT_AT_TEST_HOSTS, :serial => true) do
|
56
56
|
command = (host == "weave1") ? "sleep 0.2; echo 'delayed'" : "echo 'on time'"
|
57
57
|
output += run(command, :output => :capture)[:stdout]
|
58
58
|
end
|
59
|
-
assert_equal
|
59
|
+
assert_equal "delayed\non time\n", output
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
63
|
context "in parallel" do
|
64
64
|
should "run some commands in the expected order" do
|
65
|
-
output =
|
65
|
+
output = ""
|
66
66
|
Weave.connect(ROOT_AT_TEST_HOSTS) do
|
67
67
|
command = (host == "weave1") ? "sleep 0.2; echo 'delayed'" : "echo 'on time'"
|
68
68
|
result = run(command, :output => :capture)
|
69
69
|
output += result[:stdout]
|
70
70
|
end
|
71
|
-
assert_equal
|
71
|
+
assert_equal "on time\ndelayed\n", output
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -80,9 +80,19 @@ class SanityTest < Scope::TestCase
|
|
80
80
|
end
|
81
81
|
TEST_HOSTS.each do |host|
|
82
82
|
assert_empty output[host][:stderr]
|
83
|
-
assert_equal
|
83
|
+
assert_equal "hello\n", output[host][:stdout]
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
87
|
+
|
88
|
+
context "with a different host list" do
|
89
|
+
should "run only on the listed hosts" do
|
90
|
+
output = ""
|
91
|
+
Weave::ConnectionPool.new.execute_with(SINGLE_TEST_HOST) do
|
92
|
+
output += run("echo 'hello'", :output => :capture)[:stdout]
|
93
|
+
end
|
94
|
+
assert_equal "hello\n", output
|
95
|
+
end
|
96
|
+
end
|
87
97
|
end
|
88
98
|
end
|
data/weave.gemspec
CHANGED
@@ -18,7 +18,6 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.add_dependency "net-ssh", ">= 2.2.0"
|
19
19
|
|
20
20
|
# For running integration tests.
|
21
|
-
gem.add_development_dependency "vagrant", "~> 1.0.5"
|
22
21
|
gem.add_development_dependency "scope"
|
23
22
|
gem.add_development_dependency "rake"
|
24
23
|
# For generating the docs
|
metadata
CHANGED
@@ -1,82 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weave
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Caleb Spare
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-05-31 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: net-ssh
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 2.2.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: vagrant
|
27
|
-
requirement: &70237392576560 !ruby/object:Gem::Requirement
|
28
|
-
none: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
29
23
|
requirements:
|
30
|
-
- -
|
24
|
+
- - '>='
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
33
|
-
type: :development
|
34
|
-
prerelease: false
|
35
|
-
version_requirements: *70237392576560
|
26
|
+
version: 2.2.0
|
36
27
|
- !ruby/object:Gem::Dependency
|
37
28
|
name: scope
|
38
|
-
requirement:
|
39
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
40
30
|
requirements:
|
41
|
-
- -
|
31
|
+
- - '>='
|
42
32
|
- !ruby/object:Gem::Version
|
43
33
|
version: '0'
|
44
34
|
type: :development
|
45
35
|
prerelease: false
|
46
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: rake
|
49
|
-
requirement:
|
50
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
51
44
|
requirements:
|
52
|
-
- -
|
45
|
+
- - '>='
|
53
46
|
- !ruby/object:Gem::Version
|
54
47
|
version: '0'
|
55
48
|
type: :development
|
56
49
|
prerelease: false
|
57
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
58
55
|
- !ruby/object:Gem::Dependency
|
59
56
|
name: yard
|
60
|
-
requirement:
|
61
|
-
none: false
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
62
58
|
requirements:
|
63
|
-
- -
|
59
|
+
- - '>='
|
64
60
|
- !ruby/object:Gem::Version
|
65
61
|
version: '0'
|
66
62
|
type: :development
|
67
63
|
prerelease: false
|
68
|
-
version_requirements:
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: redcarpet
|
71
|
-
requirement:
|
72
|
-
none: false
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
73
72
|
requirements:
|
74
|
-
- -
|
73
|
+
- - '>='
|
75
74
|
- !ruby/object:Gem::Version
|
76
75
|
version: '0'
|
77
76
|
type: :development
|
78
77
|
prerelease: false
|
79
|
-
version_requirements:
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
80
83
|
description: Simple parallel ssh.
|
81
84
|
email:
|
82
85
|
- cespare@gmail.com
|
@@ -100,27 +103,26 @@ files:
|
|
100
103
|
- weave.gemspec
|
101
104
|
homepage: https://github.com/cespare/weave
|
102
105
|
licenses: []
|
106
|
+
metadata: {}
|
103
107
|
post_install_message:
|
104
108
|
rdoc_options: []
|
105
109
|
require_paths:
|
106
110
|
- lib
|
107
111
|
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
-
none: false
|
109
112
|
requirements:
|
110
|
-
- -
|
113
|
+
- - '>='
|
111
114
|
- !ruby/object:Gem::Version
|
112
115
|
version: '0'
|
113
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
-
none: false
|
115
117
|
requirements:
|
116
|
-
- -
|
118
|
+
- - '>='
|
117
119
|
- !ruby/object:Gem::Version
|
118
120
|
version: '0'
|
119
121
|
requirements: []
|
120
122
|
rubyforge_project:
|
121
|
-
rubygems_version:
|
123
|
+
rubygems_version: 2.0.0
|
122
124
|
signing_key:
|
123
|
-
specification_version:
|
125
|
+
specification_version: 4
|
124
126
|
summary: Simple parallel ssh.
|
125
127
|
test_files:
|
126
128
|
- test/integrations/sanity_test.rb
|