cast-ssh 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZTFmOWY4NGFhZjQ2MjFlYWVlMGFiOTUxN2YzMDJiMTViNzVjNjRlMQ==
5
+ data.tar.gz: !binary |-
6
+ OTg2OWNhZjI5ZjVhMTEzODFhYjAwY2QxNDNkZGUzYzhiY2EzYmIyNw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MDZiZTg1YzU2ZjcwYWRjM2E1MjhjYzg4MWEwZGNiNTljNjAxOGI0OTExNTI2
10
+ MGEzN2ZlMjZjZTBkOTIzNTI1YjA1NGU1M2RhZTY4MWJhOTljZjY3Yzg2YTlk
11
+ YTBkMzg4Zjg3MjMxYTE1ZDdjNTM0N2NiOTJmZTYzYWFlY2Q2OTQ=
12
+ data.tar.gz: !binary |-
13
+ YTk3Mzg2ZDMzMWIyYjNkYmVjNzQ2MmU5OTIxNjhlNzRhYThlMjAzNzgwNmFj
14
+ YTAzMjZmZDBjZjFjOTgzY2M1YjU0MjQ3YmU4Yzc3ZmYwNzUzMjJjMjE2ZDE4
15
+ YmUxNDBhYTZmNWQ3YjhmNmY1ZDMyMWYzMzJhMGU4OTlmNWVmOWQ=
data/README.md CHANGED
@@ -7,25 +7,25 @@ This is a Ruby gem that executes remote commands via ssh on groups of servers de
7
7
  Grab the gem:
8
8
 
9
9
  gem install cast-ssh
10
-
10
+
11
11
  Create your group file at ~/.cast.yml, like this:
12
12
 
13
13
  group1:
14
14
  - host1
15
15
  - host2
16
16
  - host3
17
-
17
+
18
18
  group2:
19
19
  - host1
20
20
  - host4
21
21
  - host5
22
-
22
+
23
23
  Run commands in your shell:
24
24
 
25
25
  cast group1 echo test
26
26
  cast group1,group2 sudo whoami
27
27
  cast -s group1,host4 df -h
28
-
28
+
29
29
  The output from the second command will look something like this:
30
30
 
31
31
  [cast] loading groups from ~/.cast.yml
@@ -44,14 +44,15 @@ Note that the commands are run in parallel, so the output may be out of order.
44
44
 
45
45
  ### Options
46
46
 
47
- --serial, -s: Execute commands serially, rather than in parallel over the group
47
+ --serial, -s: Execute commands serially, rather than in parallel over the group
48
48
  --delay, -d <f>: Delay in seconds between execution of serial commands (switches to serial mode if defined)
49
- --groupfile, -g <s>: YAML file of server groups (default: ~/.cast.yml)
50
- --list, -l: Print out contents of groupfile without executing command
51
- --clusters, -c: Print out only groupnames without executing command
52
- --version, -v: Print version and exit
53
- --help, -h: Show this message
54
-
49
+ --groupfile, -g <s>: YAML file of server groups (default: ~/.cast.yml)
50
+ --list, -l: Print out contents of groupfile without executing command
51
+ --clusters, -c: Print out only groupnames without executing command
52
+ --ssh, -h <s>: SSH command to run (default: ssh)
53
+ --version, -v: Print version and exit
54
+ --help, -e: Show this message
55
+
55
56
  ### API
56
57
 
57
58
  You can also access the same functionality from within Ruby. The following methods are available:
@@ -64,6 +65,10 @@ You can also access the same functionality from within Ruby. The following metho
64
65
 
65
66
  Run a command locally, printing stdout and stderr from the command. Returns the process' return value.
66
67
 
68
+ * __Cast::_ensure_local__ cmd, prefix = nil -> int
69
+
70
+ Run a command locally but raise an exception if it fails.
71
+
67
72
  * __Cast::log__ msg, source = 'cast', stream = $stdout
68
73
 
69
74
  Log a message through the Cast mutex using the given prefix and stream. Output will look like "[prefix] msg". The prefix box will be left out if the argument is nil.
@@ -75,4 +80,4 @@ You can also access the same functionality from within Ruby. The following metho
75
80
  * __Cast::expand_groups__ cmdgroups, groups = @@groups -> Array
76
81
 
77
82
  Takes an array of groups and hosts, and expands the groups into their constituents given the input group hash. If no hash is given, use the value loaded most recently in load_groups. Returns an array of hostnames.
78
-
83
+
data/bin/cast CHANGED
@@ -33,6 +33,7 @@ EOS
33
33
  opt :groupfile, 'YAML file of server groups', :default => Cast::DEFAULTGROUPS, :short => 'g'
34
34
  opt :list, 'Print out contents of groupfile without executing command', :short => 'l'
35
35
  opt :clusters, 'Print out only groupnames without executing command', :short => 'c'
36
+ opt :ssh, 'SSH command to run', :default => 'ssh'
36
37
  end
37
38
 
38
39
  opt = Trollop::with_standard_exception_handling p do
data/lib/cast.rb CHANGED
@@ -7,7 +7,7 @@ STDOUT.sync = true
7
7
  STDERR.sync = true
8
8
 
9
9
  module Cast
10
- VERSION = '0.1.2'
10
+ VERSION = '0.1.3'
11
11
  DEFAULTGROUPS = '~/.cast.yml'
12
12
 
13
13
  @@mux = Mutex.new
@@ -64,21 +64,26 @@ module Cast
64
64
  end
65
65
  end
66
66
 
67
- def self.remote host, cmd
68
- fullcmd = "ssh #{host} '#{cmd}'"
67
+ def self.remote host, cmd, ssh = 'ssh'
68
+ fullcmd = "#{ssh} #{host} '#{cmd}'"
69
69
  log "running #{fullcmd}"
70
70
  local fullcmd, host
71
71
  end
72
72
 
73
+ def self.ensure_local cmd, prefix = nil
74
+ r = local cmd, prefix
75
+ raise "command failed: #{cmd}" unless r == 0
76
+ return r
77
+ end
78
+
73
79
  def self.local cmd, prefix = nil
74
80
  r = nil
75
81
 
76
82
  Open3.popen3 cmd do |stdin, stdout, stderr, wait_thr|
77
- @@pids << wait_thr[:pid]
78
-
83
+ @@pids << wait_thr.pid
79
84
  stdin.close
80
85
 
81
- while true
86
+ while wait_thr.status
82
87
  streams = []
83
88
  streams << stdout if stdout
84
89
  streams << stderr if stderr
@@ -90,6 +95,7 @@ module Cast
90
95
  if stream == stdout
91
96
  line = stream.gets
92
97
  if line == nil
98
+ stdout.close
93
99
  stdout = nil
94
100
  next
95
101
  end
@@ -98,6 +104,7 @@ module Cast
98
104
  elsif stream == stderr
99
105
  line = stream.gets
100
106
  if line == nil
107
+ stderr.close
101
108
  stderr = nil
102
109
  next
103
110
  end
@@ -105,14 +112,13 @@ module Cast
105
112
 
106
113
  else raise "unrecognized stream #{stream}"
107
114
  end
108
-
109
115
  end
110
116
  end
111
117
 
112
118
  r = wait_thr.value
113
119
  end
114
120
 
115
- return r
121
+ return r.exitstatus
116
122
  end
117
123
 
118
124
  end
@@ -1,6 +1,21 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Cast do
4
+ it 'should return the command output' do
5
+ r = Cast::local 'true'
6
+ r.should == 0
7
+
8
+ r = Cast::local 'false'
9
+ r.should == 1
10
+ end
11
+
12
+ it 'should ensure local commands finish' do
13
+ r = Cast::ensure_local 'true'
14
+ r.should == 0
15
+
16
+ expect { Cast::ensure_local 'false'}.to raise_error
17
+ end
18
+
4
19
  it 'should load groups' do
5
20
  groups = Cast::load_groups 'spec/test.yml'
6
21
  groups.size.should == 2
metadata CHANGED
@@ -1,93 +1,95 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: cast-ssh
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 2
9
- version: 0.1.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
10
5
  platform: ruby
11
- authors:
6
+ authors:
12
7
  - Peter Bakkum
13
8
  autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
-
17
- date: 2013-03-24 00:00:00 -07:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
11
+ date: 2013-03-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
21
14
  name: mocha
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- version: "0"
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
30
20
  type: :development
31
- version_requirements: *id001
32
- - !ruby/object:Gem::Dependency
33
- name: rspec
34
21
  prerelease: false
35
- requirement: &id002 !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- segments:
40
- - 0
41
- version: "0"
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
42
34
  type: :development
43
- version_requirements: *id002
44
- - !ruby/object:Gem::Dependency
45
- name: autotest-standalone
46
35
  prerelease: false
47
- requirement: &id003 !ruby/object:Gem::Requirement
48
- requirements:
49
- - - ">="
50
- - !ruby/object:Gem::Version
51
- segments:
52
- - 0
53
- version: "0"
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: autotest-standalone
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
54
48
  type: :development
55
- version_requirements: *id003
56
- - !ruby/object:Gem::Dependency
57
- name: peach
58
49
  prerelease: false
59
- requirement: &id004 !ruby/object:Gem::Requirement
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- segments:
64
- - 0
65
- version: "0"
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: peach
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
66
62
  type: :runtime
67
- version_requirements: *id004
68
- - !ruby/object:Gem::Dependency
69
- name: trollop
70
63
  prerelease: false
71
- requirement: &id005 !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- segments:
76
- - 0
77
- version: "0"
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: trollop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
78
76
  type: :runtime
79
- version_requirements: *id005
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
80
83
  description: Execute remote commands via ssh on groups of machines
81
- email:
84
+ email:
82
85
  - pbb7c@virginia.edu
83
- executables:
86
+ executables:
84
87
  - cast
85
88
  extensions: []
86
-
87
- extra_rdoc_files:
89
+ extra_rdoc_files:
88
90
  - LICENSE.md
89
91
  - README.md
90
- files:
92
+ files:
91
93
  - LICENSE.md
92
94
  - README.md
93
95
  - cast.gemspec
@@ -96,42 +98,36 @@ files:
96
98
  - .travis.yml
97
99
  - lib/cast.rb
98
100
  - bin/cast
99
- - spec/lib/cast/cast_spec.rb
101
+ - spec/lib/cast_spec.rb
100
102
  - spec/spec_helper.rb
101
103
  - spec/test.yml
102
- has_rdoc: true
103
104
  homepage: http://github.com/bakks/cast
104
- licenses:
105
+ licenses:
105
106
  - MIT
107
+ metadata: {}
106
108
  post_install_message:
107
- rdoc_options:
109
+ rdoc_options:
108
110
  - --charset=UTF-8
109
- require_paths:
111
+ require_paths:
110
112
  - lib
111
- required_ruby_version: !ruby/object:Gem::Requirement
112
- requirements:
113
- - - ">="
114
- - !ruby/object:Gem::Version
115
- segments:
116
- - 0
117
- version: "0"
118
- required_rubygems_version: !ruby/object:Gem::Requirement
119
- requirements:
120
- - - ">="
121
- - !ruby/object:Gem::Version
122
- segments:
123
- - 1
124
- - 3
125
- - 6
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
126
122
  version: 1.3.6
127
123
  requirements: []
128
-
129
124
  rubyforge_project:
130
- rubygems_version: 1.3.6
125
+ rubygems_version: 2.0.3
131
126
  signing_key:
132
- specification_version: 3
127
+ specification_version: 4
133
128
  summary: Execute remote commands via ssh on groups of machines
134
- test_files:
135
- - spec/lib/cast/cast_spec.rb
129
+ test_files:
130
+ - spec/lib/cast_spec.rb
136
131
  - spec/spec_helper.rb
137
132
  - spec/test.yml
133
+ has_rdoc: