class Chef::Provider::LWRPBase

Chef::Provider::LWRPBase

Base class from which LWRP providers inherit.

Public Class Methods

action(name, &block) click to toggle source

DSL for defining a provider's actions.

# File lib/chef/provider/lwrp_base.rb, line 136
def self.action(name, &block)
  define_method("action_#{name}") do
    instance_eval(&block)
  end
end
build_from_file(cookbook_name, filename, run_context) click to toggle source
# File lib/chef/provider/lwrp_base.rb, line 83
def self.build_from_file(cookbook_name, filename, run_context)
  provider_name = filename_to_qualified_string(cookbook_name, filename)

  # Add log entry if we override an existing light-weight provider.
  class_name = convert_to_class_name(provider_name)

  if Chef::Provider.const_defined?(class_name)
    Chef::Log.info("#{class_name} light-weight provider already initialized -- overriding!")
  end

  provider_class = Class.new(self)
  provider_class.class_from_file(filename)

  class_name = convert_to_class_name(provider_name)
  Chef::Provider.const_set(class_name, provider_class)
  Chef::Log.debug("Loaded contents of #{filename} into a provider named #{provider_name} defined in Chef::Provider::#{class_name}")

  provider_class
end
use_inline_resources() click to toggle source

Enables inline evaluation of resources in provider actions.

Without this option, any resources declared inside the LWRP are added to the resource collection after the current position at the time the action is executed. Because they are added to the primary resource collection for the chef run, they can notify other resources outside the LWRP, and potentially be notified by resources outside the LWRP (but this is complicated by the fact that they don't exist until the provider executes). In this mode, it is impossible to correctly set the updated_by_last_action flag on the parent LWRP resource, since it executes and returns before its component resources are run.

With this option enabled, each action creates a temporary run_context with its own resource collection, evaluates the action's code in that context, and then converges the resources created. If any resources were updated, then this provider's new_resource will be marked updated.

In this mode, resources created within the LWRP cannot interact with external resources via notifies, though notifications to other resources within the LWRP will work. Delayed notifications are executed at the conclusion of the provider's action, not at the end of the main chef run.

This mode of evaluation is experimental, but is believed to be a better set of tradeoffs than the append-after mode, so it will likely become the default in a future major release of Chef.

# File lib/chef/provider/lwrp_base.rb, line 130
def self.use_inline_resources
  extend InlineResources::ClassMethods
  include InlineResources
end

Public Instance Methods

load_current_resource() click to toggle source

no-op `load_current_resource`. Allows simple LWRP providers to work without defining this method explicitly (silences Chef::Exceptions::Override exception)

# File lib/chef/provider/lwrp_base.rb, line 145
def load_current_resource
end