summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/platform/query_helpers.rb6
-rw-r--r--lib/chef/resource/windows_feature_dism.rb11
-rw-r--r--lib/chef/resource/windows_feature_powershell.rb25
3 files changed, 19 insertions, 23 deletions
diff --git a/lib/chef/platform/query_helpers.rb b/lib/chef/platform/query_helpers.rb
index b49010efc0..448885dfbc 100644
--- a/lib/chef/platform/query_helpers.rb
+++ b/lib/chef/platform/query_helpers.rb
@@ -20,6 +20,12 @@ class Chef
class Platform
class << self
+ # a simple helper to determine if we're on a windows release pre-2012 / 8
+ # @return [Boolean] Is the system older than Windows 8 / 2012
+ def older_than_win_2012_or_8?
+ node["platform_version"].to_f < 6.2
+ end
+
def windows?
ChefConfig.windows?
end
diff --git a/lib/chef/resource/windows_feature_dism.rb b/lib/chef/resource/windows_feature_dism.rb
index 0364432571..349e97036b 100644
--- a/lib/chef/resource/windows_feature_dism.rb
+++ b/lib/chef/resource/windows_feature_dism.rb
@@ -17,6 +17,7 @@
#
require "chef/resource"
+require "chef/platform/query_helpers"
class Chef
class Resource
@@ -49,13 +50,7 @@ class Chef
x = x.split(/\s*,\s*/) if x.is_a?(String) # split multiple forms of a comma separated list
# feature installs on windows < 2012 are case sensitive so only downcase when on 2012+
- older_than_2012_or_8? ? x : x.map(&:downcase)
- end
-
- # a simple helper to determine if we're on a windows release pre-2012 / 8
- # @return [Boolean] Is the system older than Windows 8 / 2012
- def older_than_2012_or_8?
- node["platform_version"].to_f < 6.2
+ Chef::Platform.older_than_win_2012_or_8? ? x : x.map(&:downcase)
end
action :install do
@@ -206,7 +201,7 @@ class Chef
# dism on windows 2012+ isn't case sensitive so it's best to compare
# lowercase lists so the user input doesn't need to be case sensitive
# @todo when we're ready to remove windows 2008R2 the gating here can go away
- feature_details.downcase! unless older_than_2012_or_8?
+ feature_details.downcase! unless Chef::Platform.older_than_win_2012_or_8
node.override["dism_features_cache"][feature_type] << feature_details
end
diff --git a/lib/chef/resource/windows_feature_powershell.rb b/lib/chef/resource/windows_feature_powershell.rb
index 449a70bbff..dfe1b87a9f 100644
--- a/lib/chef/resource/windows_feature_powershell.rb
+++ b/lib/chef/resource/windows_feature_powershell.rb
@@ -19,6 +19,7 @@
require "chef/mixin/powershell_out"
require "chef/json_compat"
require "chef/resource"
+require "chef/platform/query_helpers"
class Chef
class Resource
@@ -54,19 +55,13 @@ class Chef
description: "",
default: false
- # a simple helper to determine if we're on a windows release pre-2012 / 8
- # @return [Boolean] Is the system older than Windows 8 / 2012
- def older_than_2012_or_8?
- node["platform_version"].to_f < 6.2
- end
-
# Converts strings of features into an Array. Array objects are lowercased unless we're on < 8/2k12+.
# @return [Array] array of features
def to_formatted_array(x)
x = x.split(/\s*,\s*/) if x.is_a?(String) # split multiple forms of a comma separated list
# feature installs on windows < 8/2012 are case sensitive so only downcase when on 2012+
- older_than_2012_or_8? ? x : x.map(&:downcase)
+ Chef::Platform.older_than_win_2012_or_8? ? x : x.map(&:downcase)
end
include Chef::Mixin::PowershellOut
@@ -83,7 +78,7 @@ class Chef
converge_by("install Windows feature#{'s' if features_to_install.count > 1} #{features_to_install.join(',')}") do
install_command = "#{install_feature_cmdlet} #{features_to_install.join(',')}"
install_command << " -IncludeAllSubFeature" if new_resource.all
- if older_than_2012_or_8? && (new_resource.source || new_resource.management_tools)
+ if Chef::Platform.older_than_win_2012_or_8? && (new_resource.source || new_resource.management_tools)
Chef::Log.warn("The 'source' and 'management_tools' properties are only available on Windows 8/2012 or greater. Skipping these properties!")
else
install_command << " -Source \"#{new_resource.source}\"" if new_resource.source
@@ -158,16 +153,16 @@ class Chef
raise "The windows_feature_powershell resource requires PowerShell 3.0 or later. Please install PowerShell 3.0+ before running this resource." if powershell_version < 3
end
- # The appropirate cmdlet to install a windows feature based on windows release
+ # The appropriate cmdlet to install a windows feature based on windows release
# @return [String]
def install_feature_cmdlet
- older_than_2012_or_8? ? "Add-WindowsFeature" : "Install-WindowsFeature"
+ Chef::Platform.older_than_win_2012_or_8? ? "Add-WindowsFeature" : "Install-WindowsFeature"
end
- # The appropirate cmdlet to remove a windows feature based on windows release
+ # The appropriate cmdlet to remove a windows feature based on windows release
# @return [String]
def remove_feature_cmdlet
- older_than_2012_or_8? ? "Remove-WindowsFeature" : "Uninstall-WindowsFeature"
+ Chef::Platform.older_than_win_2012_or_8? ? "Remove-WindowsFeature" : "Uninstall-WindowsFeature"
end
# @return [Array] features the user has requested to install which need installation
@@ -235,7 +230,7 @@ class Chef
def parsed_feature_list
# Grab raw feature information from dism command line
# Windows < 2012 doesn't present a state value so we have to check if the feature is installed or not
- raw_list_of_features = if older_than_2012_or_8? # make the older format look like the new format, warts and all
+ raw_list_of_features = if Chef::Platform.older_than_win_2012_or_8? # make the older format look like the new format, warts and all
powershell_out!('Get-WindowsFeature | Select-Object -Property Name, @{Name=\"InstallState\"; Expression = {If ($_.Installed) { 1 } Else { 0 }}} | ConvertTo-Json -Compress', timeout: new_resource.timeout).stdout
else
powershell_out!("Get-WindowsFeature | Select-Object -Property Name,InstallState | ConvertTo-Json -Compress", timeout: new_resource.timeout).stdout
@@ -248,7 +243,7 @@ class Chef
# @return [void]
def add_to_feature_mash(feature_type, feature_details)
# add the lowercase feature name to the mash unless we're on < 2012 where they're case sensitive
- node.override["powershell_features_cache"][feature_type] << (older_than_2012_or_8? ? feature_details : feature_details.downcase)
+ node.override["powershell_features_cache"][feature_type] << (Chef::Platform.older_than_win_2012_or_8? ? feature_details : feature_details.downcase)
end
# Fail if any of the packages are in a removed state
@@ -264,7 +259,7 @@ class Chef
# Fail unless we're on windows 8+ / 2012+ where deleting a feature is supported
def raise_if_delete_unsupported
- raise Chef::Exceptions::UnsupportedAction, "#{self} :delete action not support on Windows releases before Windows 8/2012. Cannot continue!" if older_than_2012_or_8?
+ raise Chef::Exceptions::UnsupportedAction, "#{self} :delete action not support on Windows releases before Windows 8/2012. Cannot continue!" if Chef::Platform.older_than_win_2012_or_8
end
end
end