Class: Chef::Provider::LWRPBase

Inherits:
Chef::Provider show all
Extended by:
Mixin::ConvertToClassName, Mixin::FromFile
Includes:
DSL::DataQuery, DSL::PlatformIntrospection, DSL::Recipe
Defined in:
lib/chef/provider/lwrp_base.rb

Overview

Chef::Provider::LWRPBase

Base class from which LWRP providers inherit.

Defined Under Namespace

Modules: InlineResources

Instance Attribute Summary

Attributes inherited from Chef::Provider

#action, #current_resource, #new_resource, #run_context

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixin::ConvertToClassName

convert_to_class_name, convert_to_snake_case, filename_to_qualified_string, snake_case_basename

Methods included from Mixin::FromFile

class_from_file, from_file

Methods included from DSL::DataQuery

#data_bag, #data_bag_item, #search

Methods included from DSL::PlatformIntrospection

#platform?, #platform_family?, #value_for_platform, #value_for_platform_family

Methods included from DSL::Recipe

#method_missing

Methods inherited from Chef::Provider

#action_nothing, #cleanup_after_converge, #cookbook_name, #define_resource_requirements, #events, #initialize, #node, #process_resource_requirements, #requirements, #resource_collection, #run_action, #set_updated_status, #whyrun_mode?, #whyrun_supported?

Constructor Details

This class inherits a constructor from Chef::Provider

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Chef::DSL::Recipe

Class Method Details

.action(name, &block) ⇒ Object

DSL for defining a provider’s actions.



136
137
138
139
140
# 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) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# 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_resourcesObject

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.



130
131
132
133
# File 'lib/chef/provider/lwrp_base.rb', line 130

def self.use_inline_resources
  extend InlineResources::ClassMethods
  include InlineResources
end

Instance Method Details

#load_current_resourceObject

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



145
146
# File 'lib/chef/provider/lwrp_base.rb', line 145

def load_current_resource
end