em-winrm 0.5.2 → 0.5.4.rc.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,8 +1,14 @@
1
1
  = EM-WinRM
2
2
 
3
- An EventMachine client for Windows Remote Management (WinRM). This allows you to invoke commands on Windows machines from any machine that can run Ruby. This client leverages the EventMachine reactor to run the same command across multiple machines in parallel (think net-ssh-multi).
3
+ An EventMachine client for Windows Remote Management (WinRM). This allows you to
4
+ invoke commands on Windows machines from any machine that can run Ruby. This
5
+ client leverages the EventMachine reactor to run the same command across multiple
6
+ machines in parallel (think net-ssh-multi).
4
7
 
5
- WinRM allows you to call native objects in Windows. This includes, but is not limited to, running batch scripts, powershell scripts and fetching WMI variables. For more information on WinRM, please visit {Microsoft's WinRM site}[http://msdn.microsoft.com/en-us/library/aa384426(v=VS.85).aspx].
8
+ WinRM allows you to call native objects in Windows. This includes, but is not
9
+ limited to, running batch scripts, powershell scripts and fetching WMI variables.
10
+ For more information on WinRM, please visit
11
+ {Microsoft's WinRM site}[http://msdn.microsoft.com/en-us/library/aa384426(v=VS.85).aspx].
6
12
 
7
13
  = Example Usage
8
14
 
@@ -11,11 +17,11 @@ WinRM allows you to call native objects in Windows. This includes, but is not l
11
17
  'ec2-50-xxx-xxx-141.compute-1.amazonaws.com' => {:port => 80, :user => 'Administrator', :password => 'super_secret_passowrd'},
12
18
  'ec2-75-xxx-xxx-192.compute-1.amazonaws.com' => {:port => 80, :user => 'Administrator', :password => 'super_secret_passowrd'}
13
19
  }
14
-
20
+
15
21
  def h
16
22
  @highline ||= HighLine.new
17
23
  end
18
-
24
+
19
25
  def print_data(host, data, color = :cyan)
20
26
  if data =~ /\n/
21
27
  data.split(/\n/).each { |d| print_data(host, d, color) }
@@ -23,15 +29,15 @@ WinRM allows you to call native objects in Windows. This includes, but is not l
23
29
  puts "#{h.color(host, color)} #{data.chomp}"
24
30
  end
25
31
  end
26
-
32
+
27
33
  # create a session
28
34
  session = EventMachine::WinRM::Session.new(:log_level => :info)
29
-
35
+
30
36
  # add some servers
31
37
  servers.each do |host,options|
32
38
  session.use(host,options)
33
39
  end
34
-
40
+
35
41
  # create some callbacks
36
42
  session.on_output do |host, data|
37
43
  print_data(host, data)
@@ -43,7 +49,7 @@ WinRM allows you to call native objects in Windows. This includes, but is not l
43
49
  host = host == :done ? 'All Servers' : host
44
50
  print_data(host, 'done.')
45
51
  end
46
-
52
+
47
53
  # run a command
48
54
  session.relay_command('dir')
49
55
 
@@ -51,9 +57,9 @@ Gives the following output:
51
57
 
52
58
  ec2-75-xxx-xxx-192.compute-1.amazonaws.com Volume in drive C has no label.
53
59
  ec2-75-xxx-xxx-192.compute-1.amazonaws.com Volume Serial Number is 9415-4101
54
- ec2-75-xxx-xxx-192.compute-1.amazonaws.com
60
+ ec2-75-xxx-xxx-192.compute-1.amazonaws.com
55
61
  ec2-75-xxx-xxx-192.compute-1.amazonaws.com Directory of C:\Users\Administrator
56
- ec2-75-xxx-xxx-192.compute-1.amazonaws.com
62
+ ec2-75-xxx-xxx-192.compute-1.amazonaws.com
57
63
  ec2-75-xxx-xxx-192.compute-1.amazonaws.com 03/01/2011 03:30 AM <DIR> .
58
64
  ec2-75-xxx-xxx-192.compute-1.amazonaws.com 03/01/2011 03:30 AM <DIR> ..
59
65
  ec2-75-xxx-xxx-192.compute-1.amazonaws.com 03/01/2011 03:30 AM <DIR> Contacts
@@ -71,9 +77,9 @@ Gives the following output:
71
77
  ec2-75-xxx-xxx-192.compute-1.amazonaws.com 13 Dir(s) 21,553,827,840 bytes free
72
78
  ec2-75-xxx-xxx-127.compute-1.amazonaws.com Volume in drive C has no label.
73
79
  ec2-75-xxx-xxx-127.compute-1.amazonaws.com Volume Serial Number is 9415-4101
74
- ec2-75-xxx-xxx-127.compute-1.amazonaws.com
80
+ ec2-75-xxx-xxx-127.compute-1.amazonaws.com
75
81
  ec2-75-xxx-xxx-127.compute-1.amazonaws.com Directory of C:\Users\Administrator
76
- ec2-75-xxx-xxx-127.compute-1.amazonaws.com
82
+ ec2-75-xxx-xxx-127.compute-1.amazonaws.com
77
83
  ec2-75-xxx-xxx-127.compute-1.amazonaws.com 02/28/2011 06:13 PM <DIR> .
78
84
  ec2-75-xxx-xxx-127.compute-1.amazonaws.com 02/28/2011 06:13 PM <DIR> ..
79
85
  ec2-75-xxx-xxx-127.compute-1.amazonaws.com 02/28/2011 06:13 PM <DIR> Contacts
@@ -91,9 +97,9 @@ Gives the following output:
91
97
  ec2-75-xxx-xxx-127.compute-1.amazonaws.com 13 Dir(s) 21,535,481,856 bytes free
92
98
  ec2-50-xxx-xxx-141.compute-1.amazonaws.com Volume in drive C has no label.
93
99
  ec2-50-xxx-xxx-141.compute-1.amazonaws.com Volume Serial Number is 9415-4101
94
- ec2-50-xxx-xxx-141.compute-1.amazonaws.com
100
+ ec2-50-xxx-xxx-141.compute-1.amazonaws.com
95
101
  ec2-50-xxx-xxx-141.compute-1.amazonaws.com Directory of C:\Users\Administrator
96
- ec2-50-xxx-xxx-141.compute-1.amazonaws.com
102
+ ec2-50-xxx-xxx-141.compute-1.amazonaws.com
97
103
  ec2-50-xxx-xxx-141.compute-1.amazonaws.com 03/01/2011 01:17 AM <DIR> .
98
104
  ec2-50-xxx-xxx-141.compute-1.amazonaws.com 03/01/2011 01:17 AM <DIR> ..
99
105
  ec2-50-xxx-xxx-141.compute-1.amazonaws.com 03/01/2011 01:17 AM <DIR> Contacts
@@ -116,7 +122,13 @@ Gives the following output:
116
122
 
117
123
  = Credit
118
124
 
119
- Thanks to {Dan Wanek}[http://github.com/zenchild] who wrote the {WinRM Ruby client gem}[https://github.com/zenchild/WinRM] that is used heavily in this gem.
125
+ Thanks to {Dan Wanek}[http://github.com/zenchild] who wrote the
126
+ {WinRM Ruby client gem}[https://github.com/zenchild/WinRM] that is used heavily
127
+ by this gem.
128
+
129
+ Also big thanks to {Paul Morton}[https://github.com/pmorton] and
130
+ {Chris McClimans}[https://github.com/hh] (aka Hippie Hacker) for lots of real
131
+ world testing and features!
120
132
 
121
133
  = Contact
122
134
 
@@ -140,4 +152,4 @@ Unless required by applicable law or agreed to in writing, software
140
152
  distributed under the License is distributed on an "AS IS" BASIS,
141
153
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
142
154
  See the License for the specific language governing permissions and
143
- limitations under the License.
155
+ limitations under the License.
data/em-winrm.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
 
17
17
  s.required_ruby_version = '>= 1.9.1'
18
18
  s.add_dependency "eventmachine", "= 1.0.0.beta.3"
19
- s.add_dependency "winrm", "~> 1.0.3"
19
+ s.add_dependency "winrm", "~> 1.1.0"
20
20
  s.add_dependency "mixlib-log", ">= 1.3.0"
21
21
  s.add_dependency "uuidtools", "~> 2.1.1"
22
22
 
@@ -33,7 +33,7 @@ module EventMachine
33
33
  @options[:user] = @options.delete(:user) || ENV['USER'] || ENV['USERNAME'] || "unknown"
34
34
  @options[:pass] = @options.delete(:password)
35
35
  @options[:port] = @options.delete(:port) || 5985
36
- @options[:basic_auth_only] = @options.delete(:basic_auth_only) || true
36
+ @options[:basic_auth_only] = true unless defined? @options[:basic_auth_only]
37
37
  end
38
38
 
39
39
  #
@@ -52,8 +52,8 @@ module EventMachine
52
52
  @shell.on_error do |error|
53
53
  @master.relay_error_from_backend(@host, error)
54
54
  end
55
- @shell.on_close do |result|
56
- @master.command_complete(@host, cid)
55
+ @shell.on_close do |result, exit_code|
56
+ @master.command_complete(@host, cid, exit_code)
57
57
  end
58
58
  @shell.run_command(data)
59
59
  end)
@@ -85,4 +85,4 @@ module EventMachine
85
85
  end
86
86
  end
87
87
  end
88
- end
88
+ end
@@ -20,6 +20,7 @@ module EventMachine
20
20
  module WinRM
21
21
  class Session
22
22
 
23
+ attr_reader :exit_codes
23
24
  ##### Proxy Methods
24
25
  def on_output(&blk); @on_output = blk; end
25
26
  def on_error(&blk); @on_error = blk; end
@@ -36,6 +37,7 @@ module EventMachine
36
37
  end
37
38
  @servers = {}
38
39
  @commands = []
40
+ @exit_codes = {}
39
41
  WinRM::Log.debug(":session => :init")
40
42
  end
41
43
 
@@ -111,10 +113,11 @@ module EventMachine
111
113
  #
112
114
  # called by backend server when it completes a command
113
115
  #
114
- def command_complete(host, cid)
115
- WinRM::Log.debug(":command_complete => #{host}")
116
+ def command_complete(host, cid,exit_code)
117
+ WinRM::Log.debug(":command_complete => #{host} with return code #{exit_code}")
116
118
  @commands.delete(cid)
117
119
  @on_command_complete.call(host) if @on_command_complete
120
+ @exit_codes[host] = exit_code
118
121
  if @commands.compact.size.zero?
119
122
  @on_command_complete.call(:all) if @on_command_complete
120
123
  EM.stop
@@ -59,13 +59,15 @@ module EventMachine
59
59
  def run_command(command)
60
60
  command_id = client.run_command(@remote_id, command)
61
61
  WinRM::Log.debug("#{server.host}[#{@remote_id}] => :run_command[#{command}]")
62
- client.get_command_output(@remote_id, command_id) do |out,error|
62
+ output=client.get_command_output(@remote_id, command_id) do |out,error|
63
63
  @out_channel.push(out) if out
64
64
  @err_channel.push(error) if error
65
65
  end
66
66
  client.cleanup_command(@remote_id, command_id)
67
67
  WinRM::Log.debug("#{server.host}[#{@remote_id}] => :command_cleanup[#{command}]")
68
+ @last_exit_code = output[:exitcode]
68
69
  close
70
+ output[:exitcode]
69
71
  end
70
72
 
71
73
  #
@@ -74,8 +76,8 @@ module EventMachine
74
76
  def close
75
77
  r = client.close_shell(@remote_id)
76
78
  WinRM::Log.debug("#{server.host}[#{@remote_id}] => :shell_close")
77
- @on_close.call(r) if @on_close
79
+ @on_close.call(r,@last_exit_code) if @on_close
78
80
  end
79
81
  end
80
82
  end
81
- end
83
+ end
@@ -6,9 +6,9 @@
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
8
8
  # You may obtain a copy of the License at
9
- #
9
+ #
10
10
  # http://www.apache.org/licenses/LICENSE-2.0
11
- #
11
+ #
12
12
  # Unless required by applicable law or agreed to in writing, software
13
13
  # distributed under the License is distributed on an "AS IS" BASIS,
14
14
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,7 +18,7 @@
18
18
 
19
19
  module EventMachine
20
20
  module WinRM
21
- VERSION = "0.5.2"
21
+ VERSION = "0.5.4.rc.1"
22
22
  MAJOR, MINOR, TINY = VERSION.split('.')
23
23
  end
24
24
  end
metadata CHANGED
@@ -1,73 +1,69 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: em-winrm
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.5.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.4.rc.1
5
+ prerelease: 6
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Seth Chisamore
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-08-09 00:00:00 -04:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
12
+ date: 2012-03-15 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
17
15
  name: eventmachine
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70095016839240 !ruby/object:Gem::Requirement
20
17
  none: false
21
- requirements:
22
- - - "="
23
- - !ruby/object:Gem::Version
18
+ requirements:
19
+ - - =
20
+ - !ruby/object:Gem::Version
24
21
  version: 1.0.0.beta.3
25
22
  type: :runtime
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: winrm
29
23
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70095016839240
25
+ - !ruby/object:Gem::Dependency
26
+ name: winrm
27
+ requirement: &70095016838500 !ruby/object:Gem::Requirement
31
28
  none: false
32
- requirements:
29
+ requirements:
33
30
  - - ~>
34
- - !ruby/object:Gem::Version
35
- version: 1.0.3
31
+ - !ruby/object:Gem::Version
32
+ version: 1.1.0
36
33
  type: :runtime
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
39
- name: mixlib-log
40
34
  prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70095016838500
36
+ - !ruby/object:Gem::Dependency
37
+ name: mixlib-log
38
+ requirement: &70095016837740 !ruby/object:Gem::Requirement
42
39
  none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
46
43
  version: 1.3.0
47
44
  type: :runtime
48
- version_requirements: *id003
49
- - !ruby/object:Gem::Dependency
50
- name: uuidtools
51
45
  prerelease: false
52
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *70095016837740
47
+ - !ruby/object:Gem::Dependency
48
+ name: uuidtools
49
+ requirement: &70095016836700 !ruby/object:Gem::Requirement
53
50
  none: false
54
- requirements:
51
+ requirements:
55
52
  - - ~>
56
- - !ruby/object:Gem::Version
53
+ - !ruby/object:Gem::Version
57
54
  version: 2.1.1
58
55
  type: :runtime
59
- version_requirements: *id004
56
+ prerelease: false
57
+ version_requirements: *70095016836700
60
58
  description: EventMachine based, asynchronous parallel WinRM client
61
- email:
59
+ email:
62
60
  - schisamo@opscode.com
63
61
  executables: []
64
-
65
62
  extensions: []
66
-
67
- extra_rdoc_files:
63
+ extra_rdoc_files:
68
64
  - README.rdoc
69
65
  - LICENSE
70
- files:
66
+ files:
71
67
  - .gitignore
72
68
  - Gemfile
73
69
  - LICENSE
@@ -79,33 +75,28 @@ files:
79
75
  - lib/em-winrm/session.rb
80
76
  - lib/em-winrm/shell.rb
81
77
  - lib/em-winrm/version.rb
82
- has_rdoc: true
83
78
  homepage: http://github.com/schisamo/em-winrm
84
79
  licenses: []
85
-
86
80
  post_install_message:
87
81
  rdoc_options: []
88
-
89
- require_paths:
82
+ require_paths:
90
83
  - lib
91
- required_ruby_version: !ruby/object:Gem::Requirement
84
+ required_ruby_version: !ruby/object:Gem::Requirement
92
85
  none: false
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
96
89
  version: 1.9.1
97
- required_rubygems_version: !ruby/object:Gem::Requirement
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
91
  none: false
99
- requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- version: "0"
92
+ requirements:
93
+ - - ! '>'
94
+ - !ruby/object:Gem::Version
95
+ version: 1.3.1
103
96
  requirements: []
104
-
105
97
  rubyforge_project:
106
- rubygems_version: 1.6.2
98
+ rubygems_version: 1.8.10
107
99
  signing_key:
108
100
  specification_version: 3
109
101
  summary: EventMachine based, asynchronous parallel WinRM client
110
102
  test_files: []
111
-