lib/chef/win32/version.rb in chef-11.4.4 vs lib/chef/win32/version.rb in chef-11.6.0.hotfix.1

- old
+ new

@@ -27,11 +27,21 @@ # Ruby implementation of # http://msdn.microsoft.com/en-us/library/ms724833(v=vs.85).aspx # http://msdn.microsoft.com/en-us/library/ms724358(v=vs.85).aspx + private + + def self.get_system_metrics(n_index) + Win32API.new('user32', 'GetSystemMetrics', 'I', 'I').call(n_index) + end + + public + WIN_VERSIONS = { + "Windows 8" => {:major => 6, :minor => 2, :callable => lambda{ @product_type == VER_NT_WORKSTATION }}, + "Windows Server 2012" => {:major => 6, :minor => 2, :callable => lambda{ @product_type != VER_NT_WORKSTATION }}, "Windows 7" => {:major => 6, :minor => 1, :callable => lambda{ @product_type == VER_NT_WORKSTATION }}, "Windows Server 2008 R2" => {:major => 6, :minor => 1, :callable => lambda{ @product_type != VER_NT_WORKSTATION }}, "Windows Server 2008" => {:major => 6, :minor => 0, :callable => lambda{ @product_type != VER_NT_WORKSTATION }}, "Windows Vista" => {:major => 6, :minor => 0, :callable => lambda{ @product_type == VER_NT_WORKSTATION }}, "Windows Server 2003 R2" => {:major => 5, :minor => 2, :callable => lambda{ get_system_metrics(SM_SERVERR2) != 0 }}, @@ -46,11 +56,21 @@ ver_info = get_version_ex @product_type = ver_info[:w_product_type] @suite_mask = ver_info[:w_suite_mask] @sp_major_version = ver_info[:w_service_pack_major] @sp_minor_version = ver_info[:w_service_pack_minor] - @sku = get_product_info(@major_version, @minor_version, @sp_major_version, @sp_minor_version) + + # Obtain sku information for the purpose of identifying + # datacenter, cluster, and core skus, the latter 2 only + # exist in releases after Windows Server 2003 + if ! Chef::Platform::windows_server_2003? + @sku = get_product_info(@major_version, @minor_version, @sp_major_version, @sp_minor_version) + else + # The get_product_info API is not supported on Win2k3, + # use an alternative to identify datacenter skus + @sku = get_datacenter_product_info_windows_server_2003(ver_info) + end end marketing_names = Array.new # General Windows checks @@ -75,15 +95,10 @@ define_method("#{m}?") do self.class.constants.any? do |c| (self.class.const_get(c) == @sku) && (c.to_s =~ /#{m}/i ) end - # if @sku - # !(PRODUCT_TYPE[@sku][:name] =~ /#{m}/i).nil? - # else - # false - # end end end private @@ -108,11 +123,13 @@ out = FFI::MemoryPointer.new(:uint32) GetProductInfo(major, minor, sp_major, sp_minor, out) out.get_uint(0) end - def get_system_metrics(n_index) - GetSystemMetrics(n_index) + def get_datacenter_product_info_windows_server_2003(ver_info) + # The intent is not to get the actual sku, just identify + # Windows Server 2003 datacenter + sku = (ver_info[:w_suite_mask] & VER_SUITE_DATACENTER) ? PRODUCT_DATACENTER_SERVER : 0 end end end end