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.
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 64 |
# File 'lib/chef/knife/helpers/winrm_session.rb', line 29 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.
27 28 29 |
# File 'lib/chef/knife/helpers/winrm_session.rb', line 27 def endpoint @endpoint end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
27 28 29 |
# File 'lib/chef/knife/helpers/winrm_session.rb', line 27 def error @error end |
#exit_code ⇒ Object (readonly)
Returns the value of attribute exit_code.
27 28 29 |
# File 'lib/chef/knife/helpers/winrm_session.rb', line 27 def exit_code @exit_code end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
27 28 29 |
# File 'lib/chef/knife/helpers/winrm_session.rb', line 27 def host @host end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
27 28 29 |
# File 'lib/chef/knife/helpers/winrm_session.rb', line 27 def output @output end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
27 28 29 |
# File 'lib/chef/knife/helpers/winrm_session.rb', line 27 def port @port end |
Instance Method Details
#relay_command(command) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/chef/knife/helpers/winrm_session.rb', line 66 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 |