capistrano_winrm 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,49 @@
1
+ --------------------------------------------------------------------------
2
+ WinRM for Capistrano
3
+ --------------------------------------------------------------------------
4
+ This is a library that adds WinRM functionality to Capistrano in order to
5
+ talk to Micrsoft Windows systems. The set-up for WinRM is beyond the
6
+ scope of this document so I encourage you to read the Microsoft WinRM
7
+ installation documentation.
8
+ http://msdn.microsoft.com/en-us/library/aa384426(v=VS.85).aspx
9
+
10
+
11
+ My Info:
12
+ BLOG: http://distributed-frostbite.blogspot.com/
13
+ Add me in LinkedIn: http://www.linkedin.com/in/danwanek
14
+
15
+ --------------------------------------------------------------------------
16
+
17
+ TO USE:
18
+ require 'capistrano_winrm'
19
+ set :winrm_user, 'myuser'
20
+ set :winrm_password, 'mypass'
21
+ set :winrm_ssl_ca_store, '/path/to/ssl/certs' # usually /etc/ssl/certs
22
+
23
+ --------------------------------------------------------------------------
24
+
25
+ LICENSE:
26
+
27
+ (The MIT License)
28
+
29
+ Copyright (c) 2010 Dan Wanek <dan.wanek@gmail.com>
30
+ Copyright (c) 2005-2008 Jamis Buck <jamis@37signals.com>
31
+
32
+ Permission is hereby granted, free of charge, to any person obtaining
33
+ a copy of this software and associated documentation files (the
34
+ 'Software'), to deal in the Software without restriction, including
35
+ without limitation the rights to use, copy, modify, merge, publish,
36
+ distribute, sublicense, and/or sell copies of the Software, and to
37
+ permit persons to whom the Software is furnished to do so, subject to
38
+ the following conditions:
39
+
40
+ The above copyright notice and this permission notice shall be
41
+ included in all copies or substantial portions of the Software.
42
+
43
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
44
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
45
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
46
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
47
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
48
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
49
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ module Capistrano
2
+ class Command
3
+ # Processes the command in parallel on all specified hosts. If the command
4
+ # fails (non-zero return code) on any of the hosts, this will raise a
5
+ # Capistrano::CommandError.
6
+ def process!
7
+ if(@tree.configuration.variables[:winrm_running])
8
+ @channels.each do |ch|
9
+ ch.process_data do |c, stream, data|
10
+ c[:branch].callback[c, stream, data]
11
+ end
12
+ end
13
+ else
14
+ loop do
15
+ break unless process_iteration { @channels.any? { |ch| !ch[:closed] } }
16
+ end
17
+ end
18
+
19
+ logger.trace "command finished" if logger
20
+
21
+ if (failed = @channels.select { |ch| ch[:status] != 0 }).any?
22
+ commands = failed.inject({}) { |map, ch| (map[ch[:command]] ||= []) << ch[:server]; map }
23
+ message = commands.map { |command, list| "#{command.inspect} on #{list.join(',')}" }.join("; ")
24
+ error = CommandError.new("failed: #{message}")
25
+ error.hosts = commands.values.flatten
26
+ raise error
27
+ end
28
+
29
+ self
30
+ end
31
+
32
+ end # end Command
33
+ end # end Capistrano
@@ -0,0 +1,35 @@
1
+ module Capistrano
2
+ class Configuration
3
+ module Connections
4
+ class WinRMConnectionFactory #:nodoc:
5
+ def initialize(options)
6
+ @options = options
7
+ @winrm = WINRM.new(options[:winrm_user], options[:winrm_password], nil, options[:winrm_ssl_ca_store])
8
+ end
9
+
10
+ def connect_to(server)
11
+ @winrm.setup_connection(server, @options)
12
+ @winrm
13
+ end
14
+ end
15
+
16
+ # Returns the object responsible for establishing new SSH connections.
17
+ # The factory will respond to #connect_to, which can be used to
18
+ # establish connections to servers defined via ServerDefinition objects.
19
+ def connection_factory
20
+ @connection_factory ||= begin
21
+ if exists?(:gateway)
22
+ logger.debug "establishing connection to gateway `#{fetch(:gateway)}'"
23
+ GatewayConnectionFactory.new(fetch(:gateway), self)
24
+ elsif(exists?(:winrm_running))
25
+ logger.debug "establishing connection to WinRM"
26
+ WinRMConnectionFactory.new(self)
27
+ else
28
+ DefaultConnectionFactory.new(self)
29
+ end
30
+ end
31
+ end
32
+
33
+ end # Connections
34
+ end # Configuration
35
+ end # Capistrano
@@ -0,0 +1,20 @@
1
+ module CapistranoWinRM
2
+ def self.included(base)
3
+ base.send(:alias_method, :winrm, :winrm_run)
4
+ end
5
+
6
+ def winrm_run(cmd, options={}, &block)
7
+ set :winrm_running, true
8
+ options[:shell] = false
9
+ block ||= self.class.default_io_proc
10
+ tree = Capistrano::Command::Tree.new(self) { |t| t.else(cmd, &block) }
11
+ run_tree(tree, options)
12
+ set :winrm_running, false
13
+ end
14
+ end # CapistranoWinRM
15
+
16
+ Capistrano::Configuration.send(:include, CapistranoWinRM)
17
+
18
+ require 'winrm_connection'
19
+ require 'capistrano_winrm/command'
20
+ require 'capistrano_winrm/configuration/connections'
@@ -0,0 +1,57 @@
1
+ require 'winrm'
2
+
3
+ class WINRM
4
+ attr_reader :server
5
+ alias :xserver :server
6
+
7
+ def initialize(user, pass, endpoint = nil, ssl_ca_store = nil)
8
+ @user = user
9
+ @pass = pass
10
+ @endpoint = endpoint
11
+ @ssl_ca_store = ssl_ca_store
12
+ @int_hash = {}
13
+ end
14
+
15
+ def [](key)
16
+ @int_hash[key.to_sym]
17
+ end
18
+
19
+ def []=(key, value)
20
+ @int_hash[key.to_sym] = value
21
+ end
22
+
23
+ def setup_connection(server, options)
24
+ @server = server
25
+ @int_hash[:options] = options
26
+ @int_hash[:server] = server
27
+ end
28
+
29
+ def open_channel
30
+ yield self
31
+ end
32
+
33
+ def exec(cmd)
34
+ http_method = ( server.port.to_s=~/(443|5986)/ ? 'https' : 'http' )
35
+ endpoint = @endpoint ? @endpoint : "#{http_method}://#{server}/wsman"
36
+ WinRM::WinRM.endpoint = endpoint
37
+ WinRM::WinRM.set_auth(@user, @pass)
38
+ WinRM::WinRM.set_ca_trust_path(@ssl_ca_store) unless @ssl_ca_store.nil?
39
+ inst = WinRM::WinRM.instance
40
+ @ios = inst.cmd(cmd)
41
+ end
42
+
43
+ def process_data
44
+ @ios[:data].each do |ds|
45
+ key = ds.keys.first
46
+ stream = (key == :stdout) ? :out : :err
47
+ yield self, stream, ds[key]
48
+ end
49
+ self[:status] = @ios[:exitcode]
50
+ end
51
+
52
+ def on_data; self; end
53
+ def on_extended_data; self; end
54
+ def on_request(req_type); self; end
55
+ def on_close; self; end
56
+
57
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano_winrm
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Dan Wanek
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-09-24 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: capistrano
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: winrm
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 0
44
+ - 4
45
+ version: 0.0.4
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ description: " WinRM extensions for Capistrano\n"
49
+ email: dan.wanek@gmail.com
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ extra_rdoc_files:
55
+ - README
56
+ files:
57
+ - lib/capistrano_winrm.rb
58
+ - lib/capistrano_winrm/command.rb
59
+ - lib/capistrano_winrm/configuration/connections.rb
60
+ - lib/winrm_connection.rb
61
+ - README
62
+ has_rdoc: true
63
+ homepage: http://github.com/zenchild/capistrano_winrm
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options:
68
+ - -x
69
+ - test/
70
+ - -x
71
+ - examples/
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ segments:
80
+ - 1
81
+ - 8
82
+ - 7
83
+ version: 1.8.7
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ requirements: []
93
+
94
+ rubyforge_project:
95
+ rubygems_version: 1.3.7
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: WinRM extensions for Capistrano
99
+ test_files: []
100
+