lib/chef_metal/transport/winrm.rb in chef-metal-0.10.2 vs lib/chef_metal/transport/winrm.rb in chef-metal-0.11.beta

- old
+ new

@@ -3,27 +3,29 @@ require 'timeout' module ChefMetal class Transport class WinRM < ChefMetal::Transport - def initialize(endpoint, type, options = {}) + def initialize(endpoint, type, options, global_config) @endpoint = endpoint @type = type @options = options + @config = global_config end attr_reader :endpoint attr_reader :type attr_reader :options + attr_reader :config def execute(command, execute_options = {}) output = with_execute_timeout(execute_options) do session.run_powershell_script(command) do |stdout, stderr| stream_chunk(execute_options, stdout, stderr) end end - WinRMResult.new(command, execute_options, output) + WinRMResult.new(command, execute_options, config, output) end def read_file(path) result = execute("[Convert]::ToBase64String((Get-Content #{escape(path)} -Encoding byte -ReadCount 0))") if result.exitstatus == 0 @@ -72,13 +74,14 @@ ::WinRM::WinRMWebService.new(endpoint, type, options) end end class WinRMResult - def initialize(command, options, output) + def initialize(command, options, config, output) @command = command @options = options + @config = config @exitstatus = output[:exitcode] @stdout = '' @stderr = '' output[:data].each do |data| @stdout << data[:stdout] if data[:stdout] @@ -93,11 +96,11 @@ attr_reader :options def error! if exitstatus != 0 msg = "Error: command '#{command}' exited with code #{exitstatus}.\n" - msg << "STDOUT: #{stdout}" if !options[:stream] && !options[:stream_stdout] && Chef::Config.log_level != :debug - msg << "STDERR: #{stderr}" if !options[:stream] && !options[:stream_stderr] && Chef::Config.log_level != :debug + msg << "STDOUT: #{stdout}" if !options[:stream] && !options[:stream_stdout] && config[:log_level] != :debug + msg << "STDERR: #{stderr}" if !options[:stream] && !options[:stream_stderr] && config[:log_level] != :debug raise msg end end end end