Module: Chef::Mixin::WindowsArchitectureHelper

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

Instance Method Summary collapse

Instance Method Details

#assert_valid_windows_architecture!(architecture) ⇒ Object



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

def assert_valid_windows_architecture!(architecture)
  if ! 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



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

def disable_wow64_file_redirection( node )
  if ( node_windows_architecture(node) == :x86_64) && ::Chef::Platform.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)


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

def is_i386_process_on_x86_64_windows?
  if Chef::Platform.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
79
# File 'lib/chef/mixin/windows_architecture_helper.rb', line 75

def node_supports_windows_architecture?(node, desired_architecture)
  assert_valid_windows_architecture!(desired_architecture)
  return (node_windows_architecture(node) == :x86_64 ||
          desired_architecture == :i386) ? true : false
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



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

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

#valid_windows_architecture?(architecture) ⇒ Boolean

Returns:

  • (Boolean)


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

def valid_windows_architecture?(architecture)
  return (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"]
    Hash.new.tap do |n|
      n[:kernel] = Hash.new
      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