Class: Chef::Provider
- Inherits:
-
Object
- Object
- Chef::Provider
- Extended by:
- DSL::Universal, Mixin::Provides, Forwardable
- Includes:
- DSL::Recipe, Mixin::WhyRun
- Defined in:
- lib/chef/provider.rb,
lib/chef/provider/git.rb,
lib/chef/provider/cron.rb,
lib/chef/provider/file.rb,
lib/chef/provider/link.rb,
lib/chef/provider/noop.rb,
lib/chef/provider/user.rb,
lib/chef/provider/batch.rb,
lib/chef/provider/group.rb,
lib/chef/provider/mount.rb,
lib/chef/provider/route.rb,
lib/chef/provider/script.rb,
lib/chef/provider/execute.rb,
lib/chef/provider/launchd.rb,
lib/chef/provider/package.rb,
lib/chef/provider/service.rb,
lib/chef/provider/user/pw.rb,
lib/chef/provider/cron/aix.rb,
lib/chef/provider/group/pw.rb,
lib/chef/provider/ifconfig.rb,
lib/chef/provider/template.rb,
lib/chef/provider/user/aix.rb,
lib/chef/provider/user/mac.rb,
lib/chef/provider/cron/unix.rb,
lib/chef/provider/directory.rb,
lib/chef/provider/group/aix.rb,
lib/chef/provider/lwrp_base.rb,
lib/chef/provider/mount/aix.rb,
lib/chef/provider/user/dscl.rb,
lib/chef/provider/dsc_script.rb,
lib/chef/provider/group/dscl.rb,
lib/chef/provider/group/suse.rb,
lib/chef/provider/ruby_block.rb,
lib/chef/provider/subversion.rb,
lib/chef/provider/user/linux.rb,
lib/chef/provider/mount/mount.rb,
lib/chef/provider/package/apt.rb,
lib/chef/provider/package/bff.rb,
lib/chef/provider/package/cab.rb,
lib/chef/provider/package/deb.rb,
lib/chef/provider/package/dnf.rb,
lib/chef/provider/package/ips.rb,
lib/chef/provider/package/msu.rb,
lib/chef/provider/package/rpm.rb,
lib/chef/provider/package/yum.rb,
lib/chef/provider/remote_file.rb,
lib/chef/provider/service/aix.rb,
lib/chef/provider/windows_env.rb,
lib/chef/provider/dsc_resource.rb,
lib/chef/provider/file/content.rb,
lib/chef/provider/http_request.rb,
lib/chef/provider/ifconfig/aix.rb,
lib/chef/provider/package/dpkg.rb,
lib/chef/provider/package/snap.rb,
lib/chef/provider/registry_key.rb,
lib/chef/provider/service/init.rb,
lib/chef/provider/systemd_unit.rb,
lib/chef/provider/user/solaris.rb,
lib/chef/provider/user/windows.rb,
lib/chef/provider/windows_path.rb,
lib/chef/provider/windows_task.rb,
lib/chef/provider/cookbook_file.rb,
lib/chef/provider/group/gpasswd.rb,
lib/chef/provider/group/solaris.rb,
lib/chef/provider/group/usermod.rb,
lib/chef/provider/group/windows.rb,
lib/chef/provider/mount/solaris.rb,
lib/chef/provider/mount/windows.rb,
lib/chef/provider/group/groupadd.rb,
lib/chef/provider/group/groupmod.rb,
lib/chef/provider/package/pacman.rb,
lib/chef/provider/package/zypper.rb,
lib/chef/provider/service/debian.rb,
lib/chef/provider/service/macosx.rb,
lib/chef/provider/service/redhat.rb,
lib/chef/provider/service/simple.rb,
lib/chef/provider/windows_script.rb,
lib/chef/provider/yum_repository.rb,
lib/chef/provider/ifconfig/debian.rb,
lib/chef/provider/ifconfig/redhat.rb,
lib/chef/provider/package/openbsd.rb,
lib/chef/provider/package/paludis.rb,
lib/chef/provider/package/portage.rb,
lib/chef/provider/package/smartos.rb,
lib/chef/provider/package/solaris.rb,
lib/chef/provider/package/windows.rb,
lib/chef/provider/remote_file/ftp.rb,
lib/chef/provider/resource_update.rb,
lib/chef/provider/service/aixinit.rb,
lib/chef/provider/service/freebsd.rb,
lib/chef/provider/service/insserv.rb,
lib/chef/provider/service/openbsd.rb,
lib/chef/provider/service/solaris.rb,
lib/chef/provider/service/upstart.rb,
lib/chef/provider/template_finder.rb,
lib/chef/provider/package/homebrew.rb,
lib/chef/provider/package/macports.rb,
lib/chef/provider/package/rubygems.rb,
lib/chef/provider/remote_directory.rb,
lib/chef/provider/remote_file/http.rb,
lib/chef/provider/remote_file/sftp.rb,
lib/chef/provider/template/content.rb,
lib/chef/provider/powershell_script.rb,
lib/chef/provider/service/invokercd.rb,
lib/chef/provider/zypper_repository.rb,
lib/chef/provider/package/chocolatey.rb,
lib/chef/provider/package/powershell.rb,
lib/chef/provider/package/dnf/version.rb,
lib/chef/provider/package/windows/exe.rb,
lib/chef/provider/package/windows/msi.rb,
lib/chef/provider/package/yum/version.rb,
lib/chef/provider/remote_file/content.rb,
lib/chef/provider/remote_file/fetcher.rb,
lib/chef/provider/package/freebsd/base.rb,
lib/chef/provider/package/freebsd/port.rb,
lib/chef/provider/cookbook_file/content.rb,
lib/chef/provider/package/freebsd/pkgng.rb,
lib/chef/provider/package/yum/rpm_utils.rb,
lib/chef/provider/package/yum/yum_cache.rb,
lib/chef/provider/remote_file/local_file.rb,
lib/chef/provider/whyrun_safe_ruby_block.rb,
lib/chef/provider/remote_file/network_file.rb,
lib/chef/provider/package/dnf/python_helper.rb,
lib/chef/provider/package/yum/python_helper.rb,
lib/chef/provider/remote_file/cache_control_data.rb,
lib/chef/provider/package/windows/registry_uninstall_entry.rb
Direct Known Subclasses
Cron, DscResource, DscScript, Execute, File, Git, Group, HttpRequest, Ifconfig, LWRPBase, Launchd, Link, Mount, Noop, Package, RegistryKey, Route, RubyBlock, Service, Subversion, SystemdUnit, User, WindowsEnv, WindowsPath, WindowsTask, YumRepository, ZypperRepository, Resource::ActionClass
Defined Under Namespace
Classes: Batch, CookbookFile, Cron, Directory, DscResource, DscScript, Execute, File, Git, Group, HttpRequest, Ifconfig, LWRPBase, Launchd, Link, Mount, Noop, Package, PowershellScript, RegistryKey, RemoteDirectory, RemoteFile, ResourceUpdate, Route, RubyBlock, Script, Service, Subversion, SystemdUnit, Template, TemplateFinder, User, WhyrunSafeRubyBlock, WindowsEnv, WindowsPath, WindowsScript, WindowsTask, YumRepository, ZypperRepository
Instance Attribute Summary collapse
-
#action ⇒ Object
constructor; however, many/most subclasses override the constructor so changing the arity would be a breaking change.
-
#after_resource ⇒ Object
Returns the value of attribute after_resource.
-
#current_resource ⇒ Object
Returns the value of attribute current_resource.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#new_resource ⇒ Object
Returns the value of attribute new_resource.
-
#recipe_name ⇒ Object
readonly
Returns the value of attribute recipe_name.
-
#run_context ⇒ Object
Returns the value of attribute run_context.
Class Method Summary collapse
-
.action(name, &block) ⇒ void
Defines an action method on the provider, running the block to compile the resources, converging them, and then checking if any were updated (and updating new-resource if so).
-
.include_resource_dsl? ⇒ Boolean
Include attributes, public and protected methods from this Resource in the provider.
-
.include_resource_dsl_module(resource) ⇒ Object
private
Create the resource DSL module that forwards resource methods to new_resource.
- .provides(short_name, opts = {}, &block) ⇒ Object
- .provides?(node, resource) ⇒ Boolean
-
.supports?(resource, action) ⇒ Boolean
supports the given resource and action (late binding).
-
.use(partial) ⇒ Object
Use a partial code fragment.
-
.use_inline_resources ⇒ void
Deprecation stub for the old use_inline_resources mode.
Instance Method Summary collapse
-
#action_nothing ⇒ Object
the :nothing action which is available on all resources by default.
-
#check_resource_semantics! ⇒ Object
hook that subclasses can use to do lazy validation for where properties aren't flexible enough.
- #cleanup_after_converge ⇒ Object
-
#compile_and_converge_action(&block) ⇒ Object
private
Create a child run_context, compile the block, and converge it.
- #converge_by(descriptions, &block) ⇒ Object
-
#converge_if_changed(*properties, &converge_block) ⇒ Boolean
Handle patchy convergence safely.
- #cookbook_name ⇒ Object
- #define_resource_requirements ⇒ Object
- #description(description = "NOT_PASSED") ⇒ Object
- #events ⇒ Object
-
#initialize(new_resource, run_context) ⇒ Provider
constructor
A new instance of Provider.
- #introduced(introduced = "NOT_PASSED") ⇒ Object
- #load_after_resource ⇒ Object
-
#load_current_resource ⇒ Object
a simple placeholder method that will be called / raise if a resource tries to use current_resource without defining a load_current_resource method.
- #node ⇒ Object
- #process_resource_requirements ⇒ Object
- #requirements ⇒ Object
-
#resource_collection ⇒ Object
Used by providers supporting embedded recipes.
- #resource_updated? ⇒ Boolean
- #run_action(action = nil) ⇒ Object
- #set_updated_status ⇒ Object
- #validate_required_properties! ⇒ Object
-
#whyrun_mode? ⇒ Boolean
has why-run mode been enabled?.
-
#whyrun_supported? ⇒ Boolean
as of Chef 13 we enable why-run by default and require resources to override this to set false.
Methods included from Mixin::LazyModuleInclude
#descendants, #include, #included
Methods included from Mixin::PowershellOut
#powershell_out, #powershell_out!
Methods included from Mixin::WindowsArchitectureHelper
#assert_valid_windows_architecture!, #disable_wow64_file_redirection, #forced_32bit_override_required?, #is_i386_process_on_x86_64_windows?, #node_supports_windows_architecture?, #node_windows_architecture, #restore_wow64_file_redirection, #valid_windows_architecture?, #with_os_architecture, #wow64_architecture_override_required?, #wow64_directory
Methods included from Mixin::PowershellExec
#powershell_exec, #powershell_exec!
Methods included from DSL::Powershell
Methods included from DSL::RegistryHelper
#registry_data_exists?, #registry_get_subkeys, #registry_get_values, #registry_has_subkeys?, #registry_key_exists?, #registry_value_exists?
Methods included from DSL::ChefVault
#chef_vault, #chef_vault_item, #chef_vault_item_for_environment
Methods included from DSL::DataQuery
#data_bag, #data_bag_item, #search, #tagged?
Methods included from EncryptedDataBagItem::CheckEncrypted
Methods included from DSL::PlatformIntrospection
#older_than_win_2012_or_8?, #platform?, #platform_family?, #value_for_platform, #value_for_platform_family
Methods included from Mixin::Provides
provided_as, provides, provides?
Methods included from Mixin::DescendantsTracker
#descendants, descendants, #direct_descendants, direct_descendants, #find_descendants_by_name, find_descendants_by_name, #inherited, store_inherited
Methods included from DSL::Recipe
#exec, #have_resource_class_for?, #resource_class_for
Methods included from DSL::Definitions
add_definition, #evaluate_resource_definition, #has_resource_definition?
Methods included from DSL::Resources
add_resource_dsl, remove_resource_dsl
Methods included from DSL::Cheffish
Methods included from DSL::RebootPending
Methods included from DSL::IncludeRecipe
Methods included from Mixin::NotifyingBlock
#notifying_block, #subcontext_block
Methods included from DSL::DeclareResource
#build_resource, #declare_resource, #delete_resource, #delete_resource!, #edit_resource, #edit_resource!, #find_resource, #find_resource!, #resources, #with_run_context
Constructor Details
#initialize(new_resource, run_context) ⇒ Provider
Returns a new instance of Provider.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/chef/provider.rb', line 108 def initialize(new_resource, run_context) @new_resource = new_resource @action = action @current_resource = nil @after_resource = nil @run_context = run_context @converge_actions = nil @logger = if run_context run_context.logger.with_child({ resource: new_resource.name, cookbook: cookbook_name, recipe: recipe_name }) else Chef::Log.with_child({ resource: new_resource.name, cookbook: cookbook_name, recipe: recipe_name }) end @recipe_name = nil @cookbook_name = nil self.class.include_resource_dsl_module(new_resource) end |
Instance Attribute Details
#action ⇒ Object
this should be a reader, and the action should be passed in the
constructor; however, many/most subclasses override the constructor so changing the arity would be a breaking change. Change this at the next major release
106 107 108 |
# File 'lib/chef/provider.rb', line 106 def action @action end |
#after_resource ⇒ Object
Returns the value of attribute after_resource
38 39 40 |
# File 'lib/chef/provider.rb', line 38 def after_resource @after_resource end |
#current_resource ⇒ Object
Returns the value of attribute current_resource
37 38 39 |
# File 'lib/chef/provider.rb', line 37 def current_resource @current_resource end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger
42 43 44 |
# File 'lib/chef/provider.rb', line 42 def logger @logger end |
#new_resource ⇒ Object
Returns the value of attribute new_resource
36 37 38 |
# File 'lib/chef/provider.rb', line 36 def new_resource @new_resource end |
#recipe_name ⇒ Object (readonly)
Returns the value of attribute recipe_name
41 42 43 |
# File 'lib/chef/provider.rb', line 41 def recipe_name @recipe_name end |
#run_context ⇒ Object
Returns the value of attribute run_context
39 40 41 |
# File 'lib/chef/provider.rb', line 39 def run_context @run_context end |
Class Method Details
.action(name, &block) ⇒ void
This method returns an undefined value.
Defines an action method on the provider, running the block to compile the resources, converging them, and then checking if any were updated (and updating new-resource if so)
66 67 68 69 70 71 72 73 74 |
# File 'lib/chef/provider.rb', line 66 def self.action(name, &block) # We need the block directly in a method so that `return` works. define_method("compile_action_#{name}", &block) class_eval <<-EOM def action_#{name} compile_and_converge_action { compile_action_#{name} } end EOM end |
.include_resource_dsl? ⇒ Boolean
Include attributes, public and protected methods from this Resource in the provider.
If this is set to true, delegate methods are included in the provider so
that you can call (for example) attrname
and it will call
new_resource.attrname
.
The actual include does not happen until the first time the Provider is instantiated (so that we don't have to worry about load order issues).
392 393 394 |
# File 'lib/chef/provider.rb', line 392 def self.include_resource_dsl? false end |
.include_resource_dsl_module(resource) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create the resource DSL module that forwards resource methods to new_resource
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 |
# File 'lib/chef/provider.rb', line 399 def self.include_resource_dsl_module(resource) if include_resource_dsl? && !defined?(@included_resource_dsl_module) provider_class = self @included_resource_dsl_module = Module.new do extend Forwardable define_singleton_method(:to_s) { "forwarder module for #{provider_class}" } define_singleton_method(:inspect) { to_s } # this magic, stated simply, is that any instance method declared directly on # the resource we are building, will be accessible from the action_class(provider) # instance. methods declared on Chef::Resource and properties are not inherited. dsl_methods = resource.class.public_instance_methods + resource.class.protected_instance_methods - provider_class.instance_methods - resource.class.properties.keys - resource.class.properties.keys.map { |k| "#{k}=".to_sym } - Chef::Resource.instance_methods def_delegators(:new_resource, *dsl_methods) end include @included_resource_dsl_module end end |
.provides(short_name, opts = {}, &block) ⇒ Object
370 371 372 |
# File 'lib/chef/provider.rb', line 370 def self.provides(short_name, opts = {}, &block) Chef.provider_handler_map.set(short_name, self, **opts, &block) end |
.provides?(node, resource) ⇒ Boolean
374 375 376 |
# File 'lib/chef/provider.rb', line 374 def self.provides?(node, resource) Chef::ProviderResolver.new(node, resource, :nothing).provided_by?(self) end |
.supports?(resource, action) ⇒ Boolean
supports the given resource and action (late binding)
53 54 55 |
# File 'lib/chef/provider.rb', line 53 def self.supports?(resource, action) true end |
.use(partial) ⇒ Object
Use a partial code fragment. This can be used for code sharing between multiple resources.
Do not wrap the code fragment in a class or module. It also does not support the use of super to subclass any methods defined in the fragment, the methods will just be overwritten.
91 92 93 94 95 96 |
# File 'lib/chef/provider.rb', line 91 def self.use(partial) dirname = ::File.dirname(partial) basename = ::File.basename(partial, ".rb") basename = basename[1..-1] if basename.start_with?("_") class_eval IO.read(::File.("#{dirname}/_#{basename}.rb", ::File.dirname(caller_locations.first.absolute_path))) end |
.use_inline_resources ⇒ void
This method returns an undefined value.
Deprecation stub for the old use_inline_resources mode.
79 80 81 82 |
# File 'lib/chef/provider.rb', line 79 def self.use_inline_resources # Uncomment this in Chef 13.6. # Chef.deprecated(:use_inline_resources, "The use_inline_resources mode is no longer optional and the line enabling it can be removed") end |
Instance Method Details
#action_nothing ⇒ Object
the :nothing action which is available on all resources by default
176 177 178 179 |
# File 'lib/chef/provider.rb', line 176 def action_nothing logger.trace("Doing nothing for #{@new_resource}") true end |
#check_resource_semantics! ⇒ Object
hook that subclasses can use to do lazy validation for where properties aren't flexible enough
156 |
# File 'lib/chef/provider.rb', line 156 def check_resource_semantics!; end |
#cleanup_after_converge ⇒ Object
166 |
# File 'lib/chef/provider.rb', line 166 def cleanup_after_converge; end |
#compile_and_converge_action(&block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a child run_context, compile the block, and converge it.
274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/chef/provider.rb', line 274 def compile_and_converge_action(&block) old_run_context = run_context @run_context = run_context.create_child @run_context.resource_collection.unified_mode = new_resource.class.unified_mode runner = Chef::Runner.new(@run_context) return_value = instance_eval(&block) runner.converge return_value ensure if run_context.resource_collection.any?(&:updated?) new_resource.updated_by_last_action(true) end @run_context = old_run_context end |
#converge_by(descriptions, &block) ⇒ Object
267 268 269 |
# File 'lib/chef/provider.rb', line 267 def converge_by(descriptions, &block) converge_actions.add_action(descriptions, &block) end |
#converge_if_changed(*properties, &converge_block) ⇒ Boolean
Handle patchy convergence safely.
- Does not call the block if the current_resource's properties match the properties the user specified on the resource.
- Calls the block if current_resource does not exist
- Calls the block if the user has specified any properties in the resource whose values are different from current_resource.
- Does not call the block if why-run is enabled (just prints out text).
- Prints out automatic green text saying what properties have changed.
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
# File 'lib/chef/provider.rb', line 306 def converge_if_changed(*properties, &converge_block) unless converge_block raise ArgumentError, "converge_if_changed must be passed a block!" end properties = if properties.empty? new_resource.class.state_properties else properties.map { |property| new_resource.class.properties[property] } end if current_resource # Collect the list of modified properties specified_properties = properties.select { |property| property.is_set?(new_resource) || property.has_default? } specified_properties = specified_properties.map(&:name).map(&:to_sym) modified = specified_properties.select { |p| new_resource.send(p) != current_resource.send(p) } if modified.empty? properties_str = if new_resource.sensitive specified_properties.join(", ") else specified_properties.map do |property| "#{property}=" << if new_resource.class.properties[property].sensitive? "(suppressed sensitive property)" else new_resource.send(property).inspect end end.join(", ") end logger.debug("Skipping update of #{new_resource}: has not changed any of the specified properties #{properties_str}.") return false end # Print the pretty green text and run the block property_size = modified.map(&:size).max modified.map! do |p| properties_str = if new_resource.sensitive || new_resource.class.properties[p].sensitive? "(suppressed sensitive property)" else "#{new_resource.send(p).inspect} (was #{current_resource.send(p).inspect})" end " set #{p.to_s.ljust(property_size)} to #{properties_str}" end converge_by([ "update #{current_resource.identity}" ] + modified, &converge_block) else # The resource doesn't exist. Mark that we are *creating* this, and # write down any properties we are setting. property_size = properties.map(&:name).map(&:to_sym).map(&:size).max created = properties.map do |property| default = " (default value)" unless property.is_set?(new_resource) properties_str = if new_resource.sensitive || property.sensitive? "(suppressed sensitive property)" else new_resource.send(property.name.to_sym).inspect end " set #{property.name.to_sym.to_s.ljust(property_size)} to #{properties_str}#{default}" end converge_by([ "create #{new_resource.identity}" ] + created, &converge_block) end true end |
#cookbook_name ⇒ Object
151 152 153 |
# File 'lib/chef/provider.rb', line 151 def cookbook_name new_resource.cookbook_name end |
#define_resource_requirements ⇒ Object
164 |
# File 'lib/chef/provider.rb', line 164 def define_resource_requirements; end |
#description(description = "NOT_PASSED") ⇒ Object
253 254 255 256 257 258 |
# File 'lib/chef/provider.rb', line 253 def description(description = "NOT_PASSED") if description != "NOT_PASSED" @description = description end @description end |
#events ⇒ Object
181 182 183 |
# File 'lib/chef/provider.rb', line 181 def events run_context.events end |
#introduced(introduced = "NOT_PASSED") ⇒ Object
260 261 262 263 264 265 |
# File 'lib/chef/provider.rb', line 260 def introduced(introduced = "NOT_PASSED") if introduced != "NOT_PASSED" @introduced = introduced end @introduced end |
#load_after_resource ⇒ Object
168 169 170 171 172 173 |
# File 'lib/chef/provider.rb', line 168 def load_after_resource # This is a backwards compatible hack, custom resources properly wire up a new after_resource # via load_current_value. It is acceptable for old style resources that cannot be easily made # into custom resources to override this method and provide a proper after_resource. @after_resource = @new_resource end |
#load_current_resource ⇒ Object
a simple placeholder method that will be called / raise if a resource tries to use current_resource without defining a load_current_resource method.
160 161 162 |
# File 'lib/chef/provider.rb', line 160 def load_current_resource raise Chef::Exceptions::Override, "You must override load_current_resource in #{self}" end |
#node ⇒ Object
142 143 144 |
# File 'lib/chef/provider.rb', line 142 def node run_context && run_context.node end |
#process_resource_requirements ⇒ Object
231 232 233 234 |
# File 'lib/chef/provider.rb', line 231 def process_resource_requirements requirements.run(:all_actions) unless @action == :nothing requirements.run(@action) end |
#requirements ⇒ Object
249 250 251 |
# File 'lib/chef/provider.rb', line 249 def requirements @requirements ||= ResourceRequirements.new(@new_resource, run_context) end |
#resource_collection ⇒ Object
Used by providers supporting embedded recipes
147 148 149 |
# File 'lib/chef/provider.rb', line 147 def resource_collection run_context && run_context.resource_collection end |
#resource_updated? ⇒ Boolean
236 237 238 |
# File 'lib/chef/provider.rb', line 236 def resource_updated? !converge_actions.empty? || @new_resource.updated_by_last_action? end |
#run_action(action = nil) ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/chef/provider.rb', line 190 def run_action(action = nil) @action = action unless action.nil? # hook that subclasses can use to do lazy validation for where properties aren't flexible enough check_resource_semantics! # force the validation of required properties validate_required_properties! # user-defined LWRPs may include unsafe load_current_resource methods that cannot be run in whyrun mode if whyrun_mode? && !whyrun_supported? events.resource_current_state_load_bypassed(@new_resource, @action, @current_resource) else load_current_resource events.resource_current_state_loaded(@new_resource, @action, @current_resource) end define_resource_requirements process_resource_requirements # user-defined providers including LWRPs may # not include whyrun support - if they don't support it # we can't execute any actions while we're running in # whyrun mode. Instead we 'fake' whyrun by documenting that # we can't execute the action. # in non-whyrun mode, this will still cause the action to be # executed normally. if whyrun_mode? && (!whyrun_supported? || requirements.action_blocked?(@action)) events.resource_bypassed(@new_resource, @action, self) else send("action_#{@action}") end set_updated_status cleanup_after_converge load_after_resource events.resource_after_state_loaded(@new_resource, @action, @after_resource) end |
#set_updated_status ⇒ Object
240 241 242 243 244 245 246 247 |
# File 'lib/chef/provider.rb', line 240 def set_updated_status if !resource_updated? events.resource_up_to_date(@new_resource, @action) else events.resource_updated(@new_resource, @action) new_resource.updated_by_last_action(true) end end |
#validate_required_properties! ⇒ Object
185 186 187 188 |
# File 'lib/chef/provider.rb', line 185 def validate_required_properties! # all we do is run through all the required properties for this action and vivify them new_resource.class.properties.each { |name, property| property.required?(action) && property.get(new_resource) } end |
#whyrun_mode? ⇒ Boolean
has why-run mode been enabled?
130 131 132 |
# File 'lib/chef/provider.rb', line 130 def whyrun_mode? Chef::Config[:why_run] end |
#whyrun_supported? ⇒ Boolean
as of Chef 13 we enable why-run by default and require resources to override this to set false. We're keeping this method to prevent breaking the cookbook world for no real gain on our part.
138 139 140 |
# File 'lib/chef/provider.rb', line 138 def whyrun_supported? true end |