Class: Chef::Compile

Inherits:
Object show all
Includes:
Mixin::LanguageIncludeRecipe
Defined in:
lib/chef/compile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mixin::LanguageIncludeRecipe

#include_recipe, #require_recipe

Constructor Details

#initialize(node = nil) ⇒ Compile

Creates a new Chef::Compile object and populates its fields. This object gets used by the Chef Server to generate a fully compiled recipe list for a node.

Returns

object<Chef::Compile>

Duh. :)



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/chef/compile.rb', line 39

def initialize(node=nil)
  @node = node 
  @cookbook_loader = Chef::CookbookLoader.new
  @node.cookbook_loader = @cookbook_loader
  @collection = Chef::ResourceCollection.new
  @definitions = Hash.new
  @recipes = Array.new
  @default_attributes = Array.new
  @override_attributes = Array.new

  load_libraries
  load_providers
  load_resources
  load_attributes
  load_definitions
  load_recipes
end

Instance Attribute Details

#collectionObject

Returns the value of attribute collection.



30
31
32
# File 'lib/chef/compile.rb', line 30

def collection
  @collection
end

#cookbook_loaderObject

Returns the value of attribute cookbook_loader.



30
31
32
# File 'lib/chef/compile.rb', line 30

def cookbook_loader
  @cookbook_loader
end

#definitionsObject

Returns the value of attribute definitions.



30
31
32
# File 'lib/chef/compile.rb', line 30

def definitions
  @definitions
end

#nodeObject

Returns the value of attribute node.



30
31
32
# File 'lib/chef/compile.rb', line 30

def node
  @node
end

Instance Method Details

#expand_nodeObject



150
151
152
153
154
155
# File 'lib/chef/compile.rb', line 150

def expand_node
  @recipes, @default_attributes, @override_attributes = @node.run_list.expand
  @node.default_attrs = @default_attributes
  @node.override_attrs = @override_attributes
  return @recipes, @default_attributes, @override_attributes
end

#load_attributesObject

Load all the attributes, from every cookbook

Returns

true

Always returns true



76
77
78
79
80
81
82
# File 'lib/chef/compile.rb', line 76

def load_attributes()
  @cookbook_loader.each do |cookbook|
    cookbook.load_attributes(@node)
  end

  true
end

#load_definitionsObject

Load all the definitions, from every cookbook, so they are available when we process the recipes.

Results available via the definitions accessor.

Returns

true

Always returns true



91
92
93
94
95
96
97
# File 'lib/chef/compile.rb', line 91

def load_definitions()
  @cookbook_loader.each do |cookbook|
    hash = cookbook.load_definitions
    @definitions.merge!(hash)
  end
  true
end

#load_librariesObject

Load all the libraries, from every cookbook, so they are available when we process the recipes.

Returns

true

Always returns true



104
105
106
107
108
109
# File 'lib/chef/compile.rb', line 104

def load_libraries()
  @cookbook_loader.each do |cookbook|
    cookbook.load_libraries
  end
  true
end

#load_node(name) ⇒ Object

Looks up the node via the “name” argument, first from CouchDB, then by calling Chef::Node.find_file(name)

The first step in compiling the catalog. Results available via the node accessor.

Returns

node<Chef::Node>

The loaded Chef Node



64
65
66
67
68
69
70
# File 'lib/chef/compile.rb', line 64

def load_node(name)
  Chef::Log.debug("Loading Chef Node #{name} from CouchDB")
  @node = Chef::Node.load(name)
  Chef::Log.debug("Loading Recipe for Chef Node #{name}")
  @node.find_file(name)
  @node
end

#load_providersObject

Load all the providers, from every cookbook, so they are available when we process the recipes.

Returns

true

Always returns true



116
117
118
119
120
121
# File 'lib/chef/compile.rb', line 116

def load_providers()
  @cookbook_loader.each do |cookbook|
    cookbook.load_providers
  end
  true
end

#load_recipesObject

Load all the recipes specified in the node data (loaded via load_node, above.)

The results are available via the collection accessor (which returns a Chef::ResourceCollection object)

Returns

true

Always returns true



142
143
144
145
146
147
148
# File 'lib/chef/compile.rb', line 142

def load_recipes
  expand_node
  @recipes.each do |recipe|
    include_recipe(recipe)
  end
  true
end

#load_resourcesObject

Load all the resources, from every cookbook, so they are available when we process the recipes.

Returns

true

Always returns true



128
129
130
131
132
133
# File 'lib/chef/compile.rb', line 128

def load_resources()
  @cookbook_loader.each do |cookbook|
    cookbook.load_resources
  end
  true
end