Class: Chef::Knife::WinrmSession
- Inherits:
-
Object
- Object
- Chef::Knife::WinrmSession
- Defined in:
- lib/chef/knife/winrm_session.rb
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#exit_code ⇒ Object
readonly
Returns the value of attribute exit_code.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(options) ⇒ WinrmSession
constructor
A new instance of WinrmSession.
- #relay_command(command) ⇒ Object
Constructor Details
#initialize(options) ⇒ WinrmSession
Returns a new instance of WinrmSession.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/chef/knife/winrm_session.rb', line 27 def initialize() configure_proxy @host = [:host] @port = [:port] url = "#{[:host]}:#{[:port]}/wsman" scheme = [:transport] == :ssl ? 'https' : 'http' @endpoint = "#{scheme}://#{url}" opts = Hash.new opts = {:user => [:user], :pass => [:password], :basic_auth_only => [:basic_auth_only], :disable_sspi => [:disable_sspi], :no_ssl_peer_verification => [:no_ssl_peer_verification]} [:transport] == :kerberos ? opts.merge!({:service => [:service], :realm => [:realm], :keytab => [:keytab]}) : opts.merge!({:ca_trust_path => [:ca_trust_path]}) Chef::Log.debug("WinRM::WinRMWebService options: #{opts}") Chef::Log.debug("Endpoint: #{endpoint}") Chef::Log.debug("Transport: #{[:transport]}") @winrm_session = WinRM::WinRMWebService.new(@endpoint, [:transport], opts) @winrm_session.set_timeout([:operation_timeout]) if [:operation_timeout] end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
25 26 27 |
# File 'lib/chef/knife/winrm_session.rb', line 25 def endpoint @endpoint end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
25 26 27 |
# File 'lib/chef/knife/winrm_session.rb', line 25 def error @error end |
#exit_code ⇒ Object (readonly)
Returns the value of attribute exit_code.
25 26 27 |
# File 'lib/chef/knife/winrm_session.rb', line 25 def exit_code @exit_code end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
25 26 27 |
# File 'lib/chef/knife/winrm_session.rb', line 25 def host @host end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
25 26 27 |
# File 'lib/chef/knife/winrm_session.rb', line 25 def output @output end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
25 26 27 |
# File 'lib/chef/knife/winrm_session.rb', line 25 def port @port end |
Instance Method Details
#relay_command(command) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/chef/knife/winrm_session.rb', line 48 def relay_command(command) remote_id = @winrm_session.open_shell command_id = @winrm_session.run_command(remote_id, command) Chef::Log.debug("#{@host}[#{remote_id}] => :run_command[#{command}]") session_result = get_output(remote_id, command_id) @winrm_session.cleanup_command(remote_id, command_id) Chef::Log.debug("#{@host}[#{remote_id}] => :command_cleanup[#{command}]") @exit_code = session_result[:exitcode] @winrm_session.close_shell(remote_id) Chef::Log.debug("#{@host}[#{remote_id}] => :shell_close") end |