diff options
Diffstat (limited to 'lib/chef/provider/dsc_resource.rb')
-rw-r--r-- | lib/chef/provider/dsc_resource.rb | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/lib/chef/provider/dsc_resource.rb b/lib/chef/provider/dsc_resource.rb index 0f25065925..9c147cb634 100644 --- a/lib/chef/provider/dsc_resource.rb +++ b/lib/chef/provider/dsc_resource.rb @@ -1,7 +1,7 @@ # # Author:: Adam Edwards (<adamed@chef.io>) # -# Copyright:: Copyright 2014-2016, Chef Software, Inc. +# Copyright:: Copyright 2014-2017, 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. @@ -24,11 +24,12 @@ class Chef class Provider class DscResource < Chef::Provider include Chef::Mixin::PowershellTypeCoercions - provides :dsc_resource, os: "windows" + provides :dsc_resource def initialize(new_resource, run_context) super @new_resource = new_resource @module_name = new_resource.module_name + @module_version = new_resource.module_version @reboot_resource = nil end @@ -44,10 +45,6 @@ class Chef def load_current_resource end - def whyrun_supported? - true - end - def define_resource_requirements requirements.assert(:run) do |a| a.assertion { supports_dsc_invoke_resource? } @@ -65,6 +62,13 @@ class Chef a.whyrun err + ["Assuming a previous resource sets the RefreshMode."] a.block_action! end + requirements.assert(:run) do |a| + a.assertion { module_usage_valid? } + err = ["module_name must be supplied along with module_version."] + a.failure_message Chef::Exceptions::DSCModuleNameMissing, + err + a.block_action! + end end protected @@ -92,6 +96,10 @@ class Chef Chef::Platform.supports_refresh_mode_enabled?(node) end + def module_usage_valid? + !(!@module_name && @module_version) + end + def generate_description @converge_description end @@ -148,10 +156,14 @@ class Chef end end + def module_info_object + @module_version.nil? ? module_name : "@{ModuleName='#{module_name}';ModuleVersion='#{@module_version}'}" + end + def invoke_resource(method, output_format = :object) - properties = translate_type(@new_resource.properties) - switches = "-Method #{method} -Name #{@new_resource.resource}"\ - " -Property #{properties} -Module #{module_name} -Verbose" + properties = translate_type(new_resource.properties) + switches = "-Method #{method} -Name #{new_resource.resource}"\ + " -Property #{properties} -Module #{module_info_object} -Verbose" cmdlet = Chef::Util::Powershell::Cmdlet.new( node, "Invoke-DscResource #{switches}", @@ -172,22 +184,22 @@ class Chef def create_reboot_resource @reboot_resource = Chef::Resource::Reboot.new( - "Reboot for #{@new_resource.name}", + "Reboot for #{new_resource.name}", run_context ).tap do |r| - r.reason("Reboot for #{@new_resource.resource}.") + r.reason("Reboot for #{new_resource.resource}.") end end def reboot_if_required - reboot_action = @new_resource.reboot_action + reboot_action = new_resource.reboot_action unless @reboot_resource.nil? case reboot_action when :nothing - Chef::Log.debug("A reboot was requested by the DSC resource, but reboot_action is :nothing.") - Chef::Log.debug("This dsc_resource will not reboot the node.") + logger.trace("A reboot was requested by the DSC resource, but reboot_action is :nothing.") + logger.trace("This dsc_resource will not reboot the node.") else - Chef::Log.debug("Requesting node reboot with #{reboot_action}.") + logger.trace("Requesting node reboot with #{reboot_action}.") @reboot_resource.run_action(reboot_action) end end |