Class: Chef::Knife::WinrmSession
- Inherits:
-
Object
- Object
- Chef::Knife::WinrmSession
- Defined in:
- lib/chef/knife/helpers/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.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/chef/knife/helpers/winrm_session.rb', line 28 def initialize() configure_proxy @host = [:host] @port = [:port] @user = [:user] @shell_args = [ [:shell] ] @shell_args << { codepage: [:codepage] } if [:shell] == :cmd url = "#{[:host]}:#{[:port]}/wsman" scheme = [:transport] == :ssl ? "https" : "http" @endpoint = "#{scheme}://#{url}" opts = {} opts = { user: @user, password: [:password], basic_auth_only: [:basic_auth_only], disable_sspi: [:disable_sspi], no_ssl_peer_verification: [:no_ssl_peer_verification], ssl_peer_fingerprint: [:ssl_peer_fingerprint], endpoint: endpoint, transport: [:transport], } [:transport] == :kerberos ? opts.merge!({ service: [:service], realm: [:realm] }) : opts.merge!({ ca_trust_path: [:ca_trust_path] }) opts[:operation_timeout] = [:operation_timeout] if [:operation_timeout] Chef::Log.debug("WinRM::WinRMWebService options: #{opts}") Chef::Log.debug("Endpoint: #{endpoint}") Chef::Log.debug("Transport: #{[:transport]}") @winrm_session = WinRM::Connection.new(opts) @winrm_session.logger = Chef::Log transport = @winrm_session.send(:transport) http_client = transport.instance_variable_get(:@httpcli) Chef::HTTP::DefaultSSLPolicy.new(http_client.ssl_config).set_custom_certs end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
26 27 28 |
# File 'lib/chef/knife/helpers/winrm_session.rb', line 26 def endpoint @endpoint end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
26 27 28 |
# File 'lib/chef/knife/helpers/winrm_session.rb', line 26 def error @error end |
#exit_code ⇒ Object (readonly)
Returns the value of attribute exit_code.
26 27 28 |
# File 'lib/chef/knife/helpers/winrm_session.rb', line 26 def exit_code @exit_code end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
26 27 28 |
# File 'lib/chef/knife/helpers/winrm_session.rb', line 26 def host @host end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
26 27 28 |
# File 'lib/chef/knife/helpers/winrm_session.rb', line 26 def output @output end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
26 27 28 |
# File 'lib/chef/knife/helpers/winrm_session.rb', line 26 def port @port end |
Instance Method Details
#relay_command(command) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/chef/knife/helpers/winrm_session.rb', line 65 def relay_command(command) session_result = WinRM::Output.new @winrm_session.shell(*@shell_args) do |shell| shell.username = @user.split("\\").last if shell.respond_to?(:username) session_result = shell.run(command) do |stdout, stderr| print_data(@host, stdout) if stdout print_data(@host, stderr, :red) if stderr end end @exit_code = session_result.exitcode session_result rescue WinRM::WinRMHTTPTransportError, WinRM::WinRMAuthorizationError => e @exit_code = 401 raise e end |