Sha256: 4e3a4777556f11e97de15d20ce990f7aa1e85281c807dd5c50817752626c4b64

Contents?: true

Size: 1.24 KB

Versions: 108

Compression:

Stored size: 1.24 KB

Contents

module Specinfra
  module Backend
    class Winrm < Base
      include PowerShell::ScriptHelper

      def os_info
        { :family => 'windows', :release => nil, :arch => nil }
      end

      def run_command(cmd, opts={})
        script = create_script(cmd)
        winrm = get_config(:winrm)

        stdout, stderr = ''
        exitcode = 0

        if Gem.loaded_specs['winrm'].version < Gem::Version.create('2.0')
          # Use winrm V1 API
          result = winrm.powershell(script)
          stdout, stderr = [:stdout, :stderr].map do |s|
            result[:data].select {|item| item.key? s}.map {|item| item[s]}.join
          end
          exitcode = result[:exitcode]
        else
          # Use winrm V2 API
          winrm.shell(:powershell) do |shell|
            result = shell.run(script)
            stdout = result.stdout.to_s
            stderr = result.stderr.to_s
            exitcode = result.exitcode
          end
        end

        exitcode = 1 if exitcode == 0 and !stderr.empty?

        if @example
          @example.metadata[:command] = script
          @example.metadata[:stdout]  = stdout + stderr
        end

        CommandResult.new :stdout => stdout, :stderr => stderr, :exit_status => exitcode
      end
    end
  end
end

Version data entries

108 entries across 108 versions & 1 rubygems

Version Path
specinfra-2.82.25 lib/specinfra/backend/winrm.rb
specinfra-2.82.24 lib/specinfra/backend/winrm.rb
specinfra-2.82.23 lib/specinfra/backend/winrm.rb
specinfra-2.82.22 lib/specinfra/backend/winrm.rb
specinfra-2.82.21 lib/specinfra/backend/winrm.rb
specinfra-2.82.20 lib/specinfra/backend/winrm.rb
specinfra-2.82.19 lib/specinfra/backend/winrm.rb
specinfra-2.82.18 lib/specinfra/backend/winrm.rb
specinfra-2.82.17 lib/specinfra/backend/winrm.rb
specinfra-2.82.16 lib/specinfra/backend/winrm.rb
specinfra-2.82.15 lib/specinfra/backend/winrm.rb
specinfra-2.82.14 lib/specinfra/backend/winrm.rb
specinfra-2.82.13 lib/specinfra/backend/winrm.rb
specinfra-2.82.12 lib/specinfra/backend/winrm.rb
specinfra-2.82.11 lib/specinfra/backend/winrm.rb
specinfra-2.82.10 lib/specinfra/backend/winrm.rb
specinfra-2.82.9 lib/specinfra/backend/winrm.rb
specinfra-2.82.8 lib/specinfra/backend/winrm.rb
specinfra-2.82.7 lib/specinfra/backend/winrm.rb
specinfra-2.82.6 lib/specinfra/backend/winrm.rb