Class: Chef::Compile
- Inherits:
-
Object
- Object
- Chef::Compile
- Defined in:
- lib/chef/compile.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
Returns the value of attribute collection.
-
#cookbook_loader ⇒ Object
Returns the value of attribute cookbook_loader.
-
#definitions ⇒ Object
Returns the value of attribute definitions.
-
#node ⇒ Object
Returns the value of attribute node.
Instance Method Summary collapse
- #expand_node ⇒ Object
-
#initialize(node = nil) ⇒ Compile
constructor
Creates a new Chef::Compile object and populates its fields.
-
#load_attributes ⇒ Object
Load all the attributes, from every cookbook.
-
#load_definitions ⇒ Object
Load all the definitions, from every cookbook, so they are available when we process the recipes.
-
#load_libraries ⇒ Object
Load all the libraries, from every cookbook, so they are available when we process the recipes.
-
#load_node(name) ⇒ Object
Looks up the node via the “name” argument, first from CouchDB, then by calling Chef::Node.find_file(name).
-
#load_providers ⇒ Object
Load all the providers, from every cookbook, so they are available when we process the recipes.
-
#load_recipes ⇒ Object
Load all the recipes specified in the node data (loaded via load_node, above.).
-
#load_resources ⇒ Object
Load all the resources, from every cookbook, so they are available when we process the recipes.
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. :)
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/chef/compile.rb', line 36 def initialize(node=nil) @node = node @cookbook_loader = Chef::CookbookLoader.new @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
#collection ⇒ Object
Returns the value of attribute collection.
29 30 31 |
# File 'lib/chef/compile.rb', line 29 def collection @collection end |
#cookbook_loader ⇒ Object
Returns the value of attribute cookbook_loader.
29 30 31 |
# File 'lib/chef/compile.rb', line 29 def cookbook_loader @cookbook_loader end |
#definitions ⇒ Object
Returns the value of attribute definitions.
29 30 31 |
# File 'lib/chef/compile.rb', line 29 def definitions @definitions end |
#node ⇒ Object
Returns the value of attribute node.
29 30 31 |
# File 'lib/chef/compile.rb', line 29 def node @node end |
Instance Method Details
#expand_node ⇒ Object
162 163 164 165 166 167 |
# File 'lib/chef/compile.rb', line 162 def @recipes, @default_attributes, @override_attributes = @node.run_list. @node.default = @default_attributes @node.override = @override_attributes return @recipes, @default_attributes, @override_attributes end |
#load_attributes ⇒ Object
Load all the attributes, from every cookbook
Returns
- true
-
Always returns true
72 73 74 75 76 77 78 79 80 |
# File 'lib/chef/compile.rb', line 72 def load_attributes() recipes, default_attrs, override_attrs = @cookbook_loader.each do |cookbook| cookbook.load_attributes(@node) end true end |
#load_definitions ⇒ Object
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
89 90 91 92 93 94 95 |
# File 'lib/chef/compile.rb', line 89 def load_definitions() @cookbook_loader.each do |cookbook| hash = cookbook.load_definitions @definitions.merge!(hash) end true end |
#load_libraries ⇒ Object
Load all the libraries, from every cookbook, so they are available when we process the recipes.
Returns
- true
-
Always returns true
102 103 104 105 106 107 |
# File 'lib/chef/compile.rb', line 102 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
60 61 62 63 64 65 66 |
# File 'lib/chef/compile.rb', line 60 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_providers ⇒ Object
Load all the providers, from every cookbook, so they are available when we process the recipes.
Returns
- true
-
Always returns true
114 115 116 117 118 119 |
# File 'lib/chef/compile.rb', line 114 def load_providers() @cookbook_loader.each do |cookbook| cookbook.load_providers end true end |
#load_recipes ⇒ Object
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
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/chef/compile.rb', line 140 def load_recipes @recipes.each do |recipe| if @node.run_state[:seen_recipes].has_key?(recipe) Chef::Log.debug("I am not loading #{recipe}, because I have already seen it.") next end Chef::Log.debug("Loading Recipe #{recipe}") @node.run_state[:seen_recipes][recipe] = true rmatch = recipe.match(/(.+?)::(.+)/) if rmatch cookbook = @cookbook_loader[rmatch[1]] cookbook.load_recipe(rmatch[2], @node, @collection, @definitions, @cookbook_loader) else cookbook = @cookbook_loader[recipe] cookbook.load_recipe("default", @node, @collection, @definitions, @cookbook_loader) end end true end |
#load_resources ⇒ Object
Load all the resources, from every cookbook, so they are available when we process the recipes.
Returns
- true
-
Always returns true
126 127 128 129 130 131 |
# File 'lib/chef/compile.rb', line 126 def load_resources() @cookbook_loader.each do |cookbook| cookbook.load_resources end true end |