Value object that loads and tracks the context of a Chef run
Needs to be settable so deploy can run a resource_collection independent of any cookbooks.
Needs to be settable so deploy can run a resource_collection independent of any cookbooks.
Needs to be settable so deploy can run a resource_collection independent of any cookbooks.
Creates a new Chef::RunContext object and populates its fields. This object gets used by the Chef Server to generate a fully compiled recipe list for a node.
object<Chef::RunContext> |
Duh. :) |
# File lib/chef/run_context.rb, line 47 def initialize(node, cookbook_collection, events) @node = node @cookbook_collection = cookbook_collection @resource_collection = Chef::ResourceCollection.new @immediate_notification_collection = Hash.new {|h,k| h[k] = []} @delayed_notification_collection = Hash.new {|h,k| h[k] = []} @definitions = Hash.new @events = events # TODO: 5/18/2010 cw/timh - See note on Chef::Node's # cookbook_collection attr_accessor node.cookbook_collection = cookbook_collection end
# File lib/chef/run_context.rb, line 124 def delayed_notifications(resource) if resource.instance_of?(Chef::Resource) return @delayed_notification_collection[resource.name] else return @delayed_notification_collection[resource.to_s] end end
# File lib/chef/run_context.rb, line 116 def immediate_notifications(resource) if resource.instance_of?(Chef::Resource) return @immediate_notification_collection[resource.name] else return @immediate_notification_collection[resource.to_s] end end
# File lib/chef/run_context.rb, line 61 def load(run_list_expansion) load_libraries load_lwrps load_attributes load_resource_definitions # Precendence rules state that roles' attributes come after # cookbooks. Now we've loaded attributes from cookbooks with # load_attributes, apply the expansion attributes (loaded from # roles) to the node. @node.apply_expansion_attributes(run_list_expansion) @events.recipe_load_start(run_list_expansion.recipes.size) run_list_expansion.recipes.each do |recipe| begin # TODO: timh/cw, 5-14-2010: It's distasteful to be including # the DSL in a class outside the context of the DSL include_recipe(recipe) rescue Chef::Exceptions::RecipeNotFound => e @events.recipe_not_found(e) raise rescue Exception => e path = resolve_recipe(recipe) @events.recipe_file_load_failed(path, e) raise end end @events.recipe_load_complete end
# File lib/chef/run_context.rb, line 107 def notifies_delayed(notification) nr = notification.notifying_resource if nr.instance_of?(Chef::Resource) @delayed_notification_collection[nr.name] << notification else @delayed_notification_collection[nr.to_s] << notification end end
# File lib/chef/run_context.rb, line 98 def notifies_immediately(notification) nr = notification.notifying_resource if nr.instance_of?(Chef::Resource) @immediate_notification_collection[nr.name] << notification else @immediate_notification_collection[nr.to_s] << notification end end
# File lib/chef/run_context.rb, line 92 def resolve_recipe(recipe_name) cookbook_name, recipe_short_name = Chef::Recipe.parse_recipe_name(recipe_name) cookbook = cookbook_collection[cookbook_name] cookbook.recipe_filenames_by_name[recipe_short_name] end
Generated with the Darkfish Rdoc Generator 2.