Module: Chef::Mixin::WindowsArchitectureHelper

Included in:
PowershellOut, Provider::WindowsScript, Resource::WindowsScript
Defined in:
lib/chef/mixin/windows_architecture_helper.rb

Instance Method Summary collapse

Instance Method Details

#assert_valid_windows_architecture!(architecture) ⇒ Object



84
85
86
87
88
89
# File 'lib/chef/mixin/windows_architecture_helper.rb', line 84

def assert_valid_windows_architecture!(architecture)
  unless valid_windows_architecture?(architecture)
    raise Chef::Exceptions::Win32ArchitectureIncorrect,
      "The specified architecture was not valid. It must be one of :i386 or :x86_64"
  end
end

#disable_wow64_file_redirection(node) ⇒ Object



99
100
101
102
103
# File 'lib/chef/mixin/windows_architecture_helper.rb', line 99

def disable_wow64_file_redirection( node )
  if ( node_windows_architecture(node) == :x86_64) && ::ChefUtils.windows?
    Chef::ReservedNames::Win32::System.wow64_disable_wow64_fs_redirection
  end
end

#forced_32bit_override_required?(node, desired_architecture) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
42
# File 'lib/chef/mixin/windows_architecture_helper.rb', line 38

def forced_32bit_override_required?(node, desired_architecture)
  desired_architecture == :i386 &&
    node_windows_architecture(node) == :x86_64 &&
    !is_i386_process_on_x86_64_windows?
end

#is_i386_process_on_x86_64_windows?Boolean

Returns:

  • (Boolean)


91
92
93
94
95
96
97
# File 'lib/chef/mixin/windows_architecture_helper.rb', line 91

def is_i386_process_on_x86_64_windows?
  if ChefUtils.windows?
    Chef::ReservedNames::Win32::Process.is_wow64_process
  else
    false
  end
end

#node_supports_windows_architecture?(node, desired_architecture) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
78
# File 'lib/chef/mixin/windows_architecture_helper.rb', line 75

def node_supports_windows_architecture?(node, desired_architecture)
  assert_valid_windows_architecture!(desired_architecture)
  ( node_windows_architecture(node) == :x86_64 ) || ( desired_architecture == :i386 )
end

#node_windows_architecture(node) ⇒ Object



28
29
30
# File 'lib/chef/mixin/windows_architecture_helper.rb', line 28

def node_windows_architecture(node)
  node[:kernel][:machine].to_sym
end

#restore_wow64_file_redirection(node, original_redirection_state) ⇒ Object



105
106
107
108
109
# File 'lib/chef/mixin/windows_architecture_helper.rb', line 105

def restore_wow64_file_redirection( node, original_redirection_state )
  if (node_windows_architecture(node) == :x86_64) && ::ChefUtils.windows?
    Chef::ReservedNames::Win32::System.wow64_revert_wow64_fs_redirection(original_redirection_state)
  end
end

#valid_windows_architecture?(architecture) ⇒ Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/chef/mixin/windows_architecture_helper.rb', line 80

def valid_windows_architecture?(architecture)
  ( architecture == :x86_64 ) || ( architecture == :i386 )
end

#with_os_architecture(node, architecture: nil) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/chef/mixin/windows_architecture_helper.rb', line 48

def with_os_architecture(node, architecture: nil)
  node ||= begin
    os_arch = ENV["PROCESSOR_ARCHITEW6432"] ||
      ENV["PROCESSOR_ARCHITECTURE"]
    {}.tap do |n|
      n[:kernel] = {}
      n[:kernel][:machine] = os_arch == "AMD64" ? :x86_64 : :i386
    end
  end

  architecture ||= node_windows_architecture(node)

  wow64_redirection_state = nil

  if wow64_architecture_override_required?(node, architecture)
    wow64_redirection_state = disable_wow64_file_redirection(node)
  end

  begin
    yield
  ensure
    if wow64_redirection_state
      restore_wow64_file_redirection(node, wow64_redirection_state)
    end
  end
end

#wow64_architecture_override_required?(node, desired_architecture) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
# File 'lib/chef/mixin/windows_architecture_helper.rb', line 32

def wow64_architecture_override_required?(node, desired_architecture)
  desired_architecture == :x86_64 &&
    node_windows_architecture(node) == :x86_64 &&
    is_i386_process_on_x86_64_windows?
end

#wow64_directoryObject



44
45
46
# File 'lib/chef/mixin/windows_architecture_helper.rb', line 44

def wow64_directory
  Chef::ReservedNames::Win32::System.get_system_wow64_directory
end