class Chef::Resource::WindowsFeaturePowershell
Public Instance Methods
Source
# File lib/chef/resource/windows_feature_powershell.rb, line 223 def add_to_feature_mash(feature_type, feature_details) # add the lowercase feature name to the mash so we can compare it lowercase later node.override["powershell_features_cache"][feature_type] << feature_details.downcase end
add the features values to the appropriate array @return [void]
Source
# File lib/chef/resource/windows_feature_powershell.rb, line 230 def fail_if_removed return if new_resource.source # if someone provides a source then all is well return if registry_key_exists?('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Servicing') && registry_value_exists?('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Servicing', name: "LocalSourcePath") # if source is defined in the registry, still fine removed = new_resource.feature_name & node["powershell_features_cache"]["removed"] raise "The Windows feature#{"s" if removed.count > 1} #{removed.join(",")} #{removed.count > 1 ? "are" : "is"} removed from the host and cannot be installed." unless removed.empty? end
Fail if any of the packages are in a removed state @return [void]
Source
# File lib/chef/resource/windows_feature_powershell.rb, line 160 def features_to_delete # the intersection of the features to remove & enabled/disabled features are what needs removing @remove ||= begin all_available = node["powershell_features_cache"]["enabled"] + node["powershell_features_cache"]["disabled"] new_resource.feature_name & all_available end end
@return [Array] features the user has requested to delete which need deleting
Source
# File lib/chef/resource/windows_feature_powershell.rb, line 144 def features_to_install # the intersection of the features to install & disabled/removed features are what needs installing @features_to_install ||= begin features = node["powershell_features_cache"]["disabled"] features |= node["powershell_features_cache"]["removed"] if new_resource.source new_resource.feature_name & features end end
@return [Array] features the user has requested to install which need installation
Source
# File lib/chef/resource/windows_feature_powershell.rb, line 154 def features_to_remove # the intersection of the features to remove & enabled features are what needs removing @remove ||= new_resource.feature_name & node["powershell_features_cache"]["enabled"] end
@return [Array] features the user has requested to remove which need removing
Source
# File lib/chef/resource/windows_feature_powershell.rb, line 215 def parsed_feature_list # Grab raw feature information from WindowsFeature raw_list_of_features = powershell_exec!("Get-WindowsFeature | Select-Object -Property Name,InstallState", timeout: new_resource.timeout).result raw_list_of_features || [] end
fetch the list of available feature names and state in JSON and parse the JSON
Source
# File lib/chef/resource/windows_feature_powershell.rb, line 188 def reload_cached_powershell_data Chef::Log.debug("Caching Windows features available via Get-WindowsFeature.") # # FIXME FIXME FIXME # The node object should not be used for caching state like this and this is not a public API and may break. # FIXME FIXME FIXME # node.override["powershell_features_cache"] = Mash.new node.override["powershell_features_cache"]["enabled"] = [] node.override["powershell_features_cache"]["disabled"] = [] node.override["powershell_features_cache"]["removed"] = [] parsed_feature_list.each do |feature_details_raw| case feature_details_raw["InstallState"] when 5 # matches 'Removed' InstallState add_to_feature_mash("removed", feature_details_raw["Name"]) when 1, 3 # matches 'Installed' or 'InstallPending' states add_to_feature_mash("enabled", feature_details_raw["Name"]) when 0, 2 # matches 'Available' or 'UninstallPending' states add_to_feature_mash("disabled", feature_details_raw["Name"]) end end Chef::Log.debug("The powershell cache contains\n#{node["powershell_features_cache"]}") end
run Get-WindowsFeature to get a list of all available features and their state and save that to the node at node.override level. @return [void]
Source
# File lib/chef/resource/windows_feature_powershell.rb, line 82 def to_formatted_array(x) x = x.split(/\s*,\s*/) if x.is_a?(String) # split multiple forms of a comma separated list # features aren't case sensitive so let's compare in lowercase x.map(&:downcase) end
Converts strings of features into an Array. Array objects are lowercased @return [Array] array of features