em-winrm 0.0.2 → 0.0.3

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.
@@ -6,20 +6,22 @@ Gem::Specification.new do |s|
6
6
  s.name = "em-winrm"
7
7
  s.version = EventMachine::WinRM::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
+ s.has_rdoc = true
10
+ s.extra_rdoc_files = ["README.rdoc", "LICENSE" ]
9
11
  s.authors = ["Seth Chisamore"]
10
12
  s.email = ["schisamo@opscode.com"]
11
13
  s.homepage = "http://github.com/schisamo/em-winrm"
12
14
  s.summary = %q{EventMachine based, asynchronous parallel WinRM client}
13
15
  s.description = s.summary
14
16
 
15
- s.rubyforge_project = "em-winrm"
17
+ s.required_ruby_version = '>= 1.9.1'
18
+ s.add_dependency "eventmachine", ">= 1.0.0.beta.2"
19
+ s.add_dependency "winrm", ">= 1.0.0rc2"
20
+ s.add_dependency "mixlib-log", ">= 1.2.0"
21
+ s.add_dependency "uuidtools", ">= 2.1.1"
16
22
 
17
23
  s.files = `git ls-files`.split("\n")
18
24
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
25
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
26
  s.require_paths = ["lib"]
21
-
22
- s.add_dependency "eventmachine", ">= 1.0.0.beta.2"
23
- s.add_dependency "winrm", ">= 1.0.0rc2"
24
- s.add_dependency "mixlib-log", ">= 1.2.0"
25
27
  end
@@ -16,6 +16,8 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
+ require 'uuidtools'
20
+
19
21
  module EventMachine
20
22
  module WinRM
21
23
  class Server
@@ -37,6 +39,7 @@ module EventMachine
37
39
  # create a shell and run command
38
40
  #
39
41
  def run_command(data)
42
+ cid = UUIDTools::UUID.random_create.to_s
40
43
  EM.epoll
41
44
  EM.run do
42
45
  EM.defer(proc do
@@ -49,11 +52,12 @@ module EventMachine
49
52
  @master.relay_error_from_backend(@host, error)
50
53
  end
51
54
  @shell.on_close do |result|
52
- unbind
55
+ @master.command_complete(@host, cid)
53
56
  end
54
57
  @shell.run_command(data)
55
58
  end)
56
59
  end
60
+ cid
57
61
  end
58
62
 
59
63
  #
@@ -23,7 +23,9 @@ module EventMachine
23
23
  ##### Proxy Methods
24
24
  def on_output(&blk); @on_output = blk; end
25
25
  def on_error(&blk); @on_error = blk; end
26
+ def on_command_complete(&blk); @on_command_complete = blk; end
26
27
  def on_finish(&blk); @on_finish = blk; end
28
+ def on_close(&blk); @on_close = blk; end
27
29
 
28
30
  def initialize(options={})
29
31
  if options[:logger]
@@ -33,6 +35,8 @@ module EventMachine
33
35
  WinRM::Log.level(log_level)
34
36
  end
35
37
  @servers = {}
38
+ @commands = []
39
+ WinRM::Log.debug(":session => :init")
36
40
  end
37
41
 
38
42
  #
@@ -46,7 +50,7 @@ module EventMachine
46
50
  servers.each do |s|
47
51
  operation = proc do
48
52
  WinRM::Log.debug(":relayed => #{s.host}")
49
- s.run_command(data)
53
+ @commands << s.run_command(data)
50
54
  end
51
55
  EM.defer(operation)
52
56
  end
@@ -57,8 +61,35 @@ module EventMachine
57
61
  # initialize connections to a server
58
62
  #
59
63
  def use(host, options)
60
- srv = Server.new(self, host, options)
61
- @servers[host] = srv
64
+ @servers[host] = Server.new(self, host, options)
65
+ end
66
+
67
+ #
68
+ # return an array of the current servers in the session
69
+ #
70
+ def servers
71
+ @servers.values
72
+ end
73
+
74
+ #
75
+ # set the current servers in the session
76
+ #
77
+ def servers=(servers)
78
+ @servers = {}
79
+ servers.each{|s| @servers[s.host] = s}
80
+ end
81
+
82
+ #
83
+ # returns a new EventMachine::WinRM::Session instance
84
+ # consisting of a specific sub-set of servers
85
+ #
86
+ # inspired by Net::SSH::Multi::Session.on
87
+ #
88
+ def on(*new_servers)
89
+ subsession = self.clone
90
+ subsession.servers = new_servers & servers
91
+ yield subsession if block_given?
92
+ subsession
62
93
  end
63
94
 
64
95
  #
@@ -77,6 +108,19 @@ module EventMachine
77
108
  data = @on_error.call(host, data) if @on_error
78
109
  end
79
110
 
111
+ #
112
+ # called by backend server when it completes a command
113
+ #
114
+ def command_complete(host, cid)
115
+ WinRM::Log.debug(":command_complete => #{host}")
116
+ @commands.delete(cid)
117
+ @on_command_complete.call(host) if @on_command_complete
118
+ if @commands.compact.size.zero?
119
+ @on_command_complete.call(:all) if @on_command_complete
120
+ EM.stop
121
+ end
122
+ end
123
+
80
124
  def unbind
81
125
  WinRM::Log.debug(":unbind => :connection")
82
126
  # terminate any unfinished connections
@@ -89,10 +133,8 @@ module EventMachine
89
133
  WinRM::Log.debug(":unbind_backend => #{host}")
90
134
  @servers[host] = nil
91
135
  @on_finish.call(host) if @on_finish
92
-
93
136
  if @servers.values.compact.size.zero?
94
- @on_finish.call(:done) if @on_finish
95
- close
137
+ @on_finish.call(:all) if @on_finish
96
138
  end
97
139
  end
98
140
 
@@ -102,7 +144,10 @@ module EventMachine
102
144
  #
103
145
  def close
104
146
  unbind
105
- EM.stop
147
+ # try to stop eventmachine loop
148
+ EM.stop rescue
149
+ @on_close.call if @on_close
150
+ WinRM::Log.debug(":session => :close")
106
151
  end
107
152
  end
108
153
  end
@@ -18,7 +18,7 @@
18
18
 
19
19
  module EventMachine
20
20
  module WinRM
21
- VERSION = "0.0.2"
21
+ VERSION = "0.0.3"
22
22
  MAJOR, MINOR, TINY = VERSION.split('.')
23
23
  end
24
24
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: em-winrm
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Seth Chisamore
@@ -46,6 +46,17 @@ dependencies:
46
46
  version: 1.2.0
47
47
  type: :runtime
48
48
  version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: uuidtools
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 2.1.1
58
+ type: :runtime
59
+ version_requirements: *id004
49
60
  description: EventMachine based, asynchronous parallel WinRM client
50
61
  email:
51
62
  - schisamo@opscode.com
@@ -53,8 +64,9 @@ executables: []
53
64
 
54
65
  extensions: []
55
66
 
56
- extra_rdoc_files: []
57
-
67
+ extra_rdoc_files:
68
+ - README.rdoc
69
+ - LICENSE
58
70
  files:
59
71
  - .gitignore
60
72
  - Gemfile
@@ -81,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
81
93
  requirements:
82
94
  - - ">="
83
95
  - !ruby/object:Gem::Version
84
- version: "0"
96
+ version: 1.9.1
85
97
  required_rubygems_version: !ruby/object:Gem::Requirement
86
98
  none: false
87
99
  requirements:
@@ -90,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
102
  version: "0"
91
103
  requirements: []
92
104
 
93
- rubyforge_project: em-winrm
105
+ rubyforge_project:
94
106
  rubygems_version: 1.5.2
95
107
  signing_key:
96
108
  specification_version: 3