Update the mediawiki cookbook and upstream cookbooks

Compatibility with Chef 14
This commit is contained in:
Greg Karékinian
2019-04-08 11:20:12 +02:00
parent 6e3e8cde1b
commit 777b85c2ab
312 changed files with 5603 additions and 14219 deletions

View File

@@ -3,8 +3,8 @@
# Cookbook:: windows
# Resource:: pagefile
#
# Copyright:: 2012-2017, Nordstrom, Inc.
# Copyright:: 2017, Chef Software, Inc.
# Copyright:: 2012-2018, Nordstrom, Inc.
# Copyright:: 2017-2018, Chef Software Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -19,17 +19,19 @@
# limitations under the License.
#
property :name, String, name_property: true
chef_version_for_provides '< 14.0' if respond_to?(:chef_version_for_provides)
resource_name :windows_pagefile
property :path, String, coerce: proc { |x| x.tr('/', '\\') }, name_property: true
property :system_managed, [true, false]
property :automatic_managed, [true, false], default: false
property :initial_size, Integer
property :maximum_size, Integer
include Chef::Mixin::ShellOut
include Windows::Helper
action :set do
pagefile = new_resource.name
pagefile = new_resource.path
initial_size = new_resource.initial_size
maximum_size = new_resource.maximum_size
system_managed = new_resource.system_managed
@@ -58,16 +60,22 @@ end
action :delete do
validate_name
pagefile = new_resource.name
delete(pagefile) if exists?(pagefile)
delete(new_resource.path) if exists?(new_resource.path)
end
action_class do
# make sure the provided name property matches the appropriate format
# we do this here and not in the property itself because if automatic_managed
# is set then this validation is not necessary / doesn't make sense at all
def validate_name
return if /^.:.*.sys/ =~ new_resource.name
raise "#{new_resource.name} does not match the format DRIVE:\\path\\file.sys for pagefiles. Example: C:\\pagefile.sys"
return if /^.:.*.sys/ =~ new_resource.path
raise "#{new_resource.path} does not match the format DRIVE:\\path\\file.sys for pagefiles. Example: C:\\pagefile.sys"
end
# See if the pagefile exists
#
# @param [String] pagefile path to the pagefile
# @return [Boolean]
def exists?(pagefile)
@exists ||= begin
Chef::Log.debug("Checking if #{pagefile} exists by runing: #{wmic} pagefileset where SettingID=\"#{get_setting_id(pagefile)}\" list /format:list")
@@ -76,6 +84,12 @@ action_class do
end
end
# is the max/min pagefile size set?
#
# @param [String] pagefile path to the pagefile
# @param [String] min the minimum size of the pagefile
# @param [String] max the minimum size of the pagefile
# @return [Boolean]
def max_and_min_set?(pagefile, min, max)
@max_and_min_set ||= begin
Chef::Log.debug("Checking if #{pagefile} min: #{min} and max #{max} are set")
@@ -84,14 +98,20 @@ action_class do
end
end
# create a pagefile
#
# @param [String] pagefile path to the pagefile
def create(pagefile)
converge_by("create pagefile #{pagefile}") do
Chef::Log.debug("Running #{wmic} pagefileset create name=\"#{win_friendly_path(pagefile)}\"")
cmd = shell_out("#{wmic} pagefileset create name=\"#{win_friendly_path(pagefile)}\"")
Chef::Log.debug("Running #{wmic} pagefileset create name=\"#{pagefile}\"")
cmd = shell_out("#{wmic} pagefileset create name=\"#{pagefile}\"")
check_for_errors(cmd.stderr)
end
end
# delete a pagefile
#
# @param [String] pagefile path to the pagefile
def delete(pagefile)
converge_by("remove pagefile #{pagefile}") do
Chef::Log.debug("Running #{wmic} pagefileset where SettingID=\"#{get_setting_id(pagefile)}\" delete")
@@ -100,6 +120,9 @@ action_class do
end
end
# see if the pagefile is automatically managed by Windows
#
# @return [Boolean]
def automatic_managed?
@automatic_managed ||= begin
Chef::Log.debug('Checking if pagefiles are automatically managed')
@@ -108,6 +131,7 @@ action_class do
end
end
# turn on automatic management of all pagefiles by Windows
def set_automatic_managed
converge_by('set pagefile to Automatic Managed') do
Chef::Log.debug("Running #{wmic} computersystem where name=\"%computername%\" set AutomaticManagedPagefile=True")
@@ -116,6 +140,7 @@ action_class do
end
end
# turn off automatic management of all pagefiles by Windows
def unset_automatic_managed
converge_by('set pagefile to User Managed') do
Chef::Log.debug("Running #{wmic} computersystem where name=\"%computername%\" set AutomaticManagedPagefile=False")
@@ -124,6 +149,11 @@ action_class do
end
end
# set a custom size for the pagefile (vs the defaults)
#
# @param [String] pagefile path to the pagefile
# @param [String] min the minimum size of the pagefile
# @param [String] max the minimum size of the pagefile
def set_custom_size(pagefile, min, max)
converge_by("set #{pagefile} to InitialSize=#{min} & MaximumSize=#{max}") do
Chef::Log.debug("Running #{wmic} pagefileset where SettingID=\"#{get_setting_id(pagefile)}\" set InitialSize=#{min},MaximumSize=#{max}")
@@ -132,7 +162,10 @@ action_class do
end
end
def set_system_managed(pagefile) # rubocop: disable Style/AccessorMethodName
# set a pagefile size to be system managed
#
# @param [String] pagefile path to the pagefile
def set_system_managed(pagefile) # rubocop: disable Naming/AccessorMethodName
converge_by("set #{pagefile} to System Managed") do
Chef::Log.debug("Running #{wmic} pagefileset where SettingID=\"#{get_setting_id(pagefile)}\" set InitialSize=0,MaximumSize=0")
cmd = shell_out("#{wmic} pagefileset where SettingID=\"#{get_setting_id(pagefile)}\" set InitialSize=0,MaximumSize=0", returns: [0])
@@ -141,11 +174,11 @@ action_class do
end
def get_setting_id(pagefile)
pagefile = win_friendly_path(pagefile)
pagefile = pagefile.split('\\')
"#{pagefile[1]} @ #{pagefile[0]}"
split_path = pagefile.split('\\')
"#{split_path[1]} @ #{split_path[0]}"
end
# raise if there's an error on stderr on a shellout
def check_for_errors(stderr)
raise stderr.chomp unless stderr.empty?
end