In Files

Parent

Files

Class/Module Index [+]

Quicksearch

Chef::Provider

Attributes

action[RW]
current_resource[RW]
new_resource[RW]
run_context[RW]

Public Class Methods

new(new_resource, run_context) click to toggle source
# File lib/chef/provider.rb, line 41
def initialize(new_resource, run_context)
  @new_resource = new_resource
  @action = action
  @current_resource = nil
  @run_context = run_context
  @converge_actions = nil
end

Public Instance Methods

action_nothing() click to toggle source
# File lib/chef/provider.rb, line 80
def action_nothing
  Chef::Log.debug("Doing nothing for #{@new_resource.to_s}")
  true
end
cleanup_after_converge() click to toggle source
# File lib/chef/provider.rb, line 77
def cleanup_after_converge
end
cookbook_name() click to toggle source
# File lib/chef/provider.rb, line 66
def cookbook_name
  new_resource.cookbook_name
end
define_resource_requirements() click to toggle source
# File lib/chef/provider.rb, line 74
def define_resource_requirements
end
events() click to toggle source
# File lib/chef/provider.rb, line 85
def events
  run_context.events
end
load_current_resource() click to toggle source
# File lib/chef/provider.rb, line 70
def load_current_resource
  raise Chef::Exceptions::Override, "You must override load_current_resource in #{self.to_s}"
end
node() click to toggle source
# File lib/chef/provider.rb, line 57
def node
  run_context && run_context.node
end
process_resource_requirements() click to toggle source
# File lib/chef/provider.rb, line 126
def process_resource_requirements
  requirements.run(:all_actions) unless @action == :nothing
  requirements.run(@action)
end
requirements() click to toggle source
# File lib/chef/provider.rb, line 140
def requirements
  @requirements ||= ResourceRequirements.new(@new_resource, run_context)
end
resource_collection() click to toggle source

Used by providers supporting embedded recipes

# File lib/chef/provider.rb, line 62
def resource_collection
  run_context && run_context.resource_collection
end
run_action(action=nil) click to toggle source
# File lib/chef/provider.rb, line 89
def run_action(action=nil)
  @action = action unless action.nil?

  # TODO: it would be preferable to get the action to be executed in the
  # constructor...

  # user-defined LWRPs may include unsafe load_current_resource methods that cannot be run in whyrun mode
  if !whyrun_mode? || whyrun_supported?
    load_current_resource
    events.resource_current_state_loaded(@new_resource, @action, @current_resource)
  elsif whyrun_mode? && !whyrun_supported?
    events.resource_current_state_load_bypassed(@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_supported? && !requirements.action_blocked?(@action)
    send("action_#{@action}")
  elsif whyrun_mode?
    events.resource_bypassed(@new_resource, @action, self)
  else
    send("action_#{@action}")
  end

  set_updated_status

  cleanup_after_converge
end
set_updated_status() click to toggle source
# File lib/chef/provider.rb, line 131
def set_updated_status
  if converge_actions.empty? && !@new_resource.updated_by_last_action?
    events.resource_up_to_date(@new_resource, @action)
  else
    events.resource_updated(@new_resource, @action)
    new_resource.updated_by_last_action(true) 
  end
end
whyrun_mode?() click to toggle source
# File lib/chef/provider.rb, line 49
def whyrun_mode?
  Chef::Config[:why_run]
end
whyrun_supported?() click to toggle source
# File lib/chef/provider.rb, line 53
def whyrun_supported?
  false
end

Protected Instance Methods

converge_actions() click to toggle source
# File lib/chef/provider.rb, line 146
def converge_actions
  @converge_actions ||= ConvergeActions.new(@new_resource, run_context, @action)
end
converge_by(descriptions, &block) click to toggle source
# File lib/chef/provider.rb, line 150
def converge_by(descriptions, &block)
  converge_actions.add_action(descriptions, &block)
end
recipe_eval(&block) click to toggle source
# File lib/chef/provider.rb, line 155
def recipe_eval(&block)
  # This block has new resource definitions within it, which
  # essentially makes it an in-line Chef run. Save our current
  # run_context and create one anew, so the new Chef run only
  # executes the embedded resources.
  #
  # TODO: timh,cw: 2010-5-14: This means that the resources within
  # this block cannot interact with resources outside, e.g.,
  # manipulating notifies.

  converge_by ("would evaluate block and run any associated actions") do
    saved_run_context = @run_context
    @run_context = @run_context.dup
    @run_context.resource_collection = Chef::ResourceCollection.new
    instance_eval(&block)
    Chef::Runner.new(@run_context).converge
    @run_context = saved_run_context
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.