summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser
diff options
context:
space:
mode:
authorLuke Kanies <luke@puppetlabs.com>2010-05-14 13:30:43 -0700
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commit61a719f41c5448ca9ab7bdbd6a05f6c97ee80b7f (patch)
tree4f4534536aac89bb713f6f42852950f3c4cde6b6 /lib/puppet/parser
parentd13f8ac4d5b8e4cf677c6c04fe875630216d6303 (diff)
downloadpuppet-61a719f41c5448ca9ab7bdbd6a05f6c97ee80b7f.tar.gz
puppet-61a719f41c5448ca9ab7bdbd6a05f6c97ee80b7f.tar.xz
puppet-61a719f41c5448ca9ab7bdbd6a05f6c97ee80b7f.zip
Adding #2658 - Adding support for run stages
This allows you to specify a run stage for either a class or a resource. By default, all classes get directly added to the 'main' stage. You can create new stages as resources: stage { [pre, post]: } To order stages, use standard relationships: stage { pre: before => Stage[main] } Or use the new relationship syntax: stage { pre: } -> Stage[main] -> stage { post: } Then use the new class parameters to specify a stage: class { foo: stage => pre } If you set a stage on an individual resource, it will fail; stages can only be set on class resources. Signed-off-by: Luke Kanies <luke@puppetlabs.com>
Diffstat (limited to 'lib/puppet/parser')
-rw-r--r--lib/puppet/parser/compiler.rb42
-rw-r--r--lib/puppet/parser/resource.rb4
2 files changed, 30 insertions, 16 deletions
diff --git a/lib/puppet/parser/compiler.rb b/lib/puppet/parser/compiler.rb
index ae4af7622..6cc71a62e 100644
--- a/lib/puppet/parser/compiler.rb
+++ b/lib/puppet/parser/compiler.rb
@@ -51,16 +51,31 @@ class Puppet::Parser::Compiler
# Note that this will fail if the resource is not unique.
@catalog.add_resource(resource)
- # And in the resource graph. At some point, this might supercede
- # the global resource table, but the table is a lot faster
- # so it makes sense to maintain for now.
- if resource.type.to_s.downcase == "class" and main = @catalog.resource(:class, :main)
- @catalog.add_edge(main, resource)
- else
- @catalog.add_edge(scope.resource, resource)
+ set_container_resource(scope, resource)
+ end
+
+ def set_container_resource(scope, resource)
+ # Add our container edge. If we're a class, then we get treated specially - we can
+ # control the stage that the class is applied in. Otherwise, we just
+ # get added to our parent container.
+ return if resource.type.to_s.downcase == "stage"
+
+ if resource.type.to_s.downcase != "class"
+ if resource[:stage]
+ raise ArgumentError, "Only classes can set 'stage'; normal resources like #{resource} cannot change run stage"
+ end
+ return @catalog.add_edge(scope.resource, resource)
end
+
+ unless stage = @catalog.resource(:stage, resource[:stage] || :main)
+ raise ArgumentError, "Could not find stage #{resource[:stage] || :main} specified by #{resource}"
+ end
+
+ @catalog.add_edge(stage, resource)
end
+ private :set_container_resource
+
# Do we use nodes found in the code, vs. the external node sources?
def ast_nodes?
known_resource_types.nodes?
@@ -169,7 +184,6 @@ class Puppet::Parser::Compiler
end
initvars()
- init_main()
end
# Create a new scope, with either a specified parent scope or
@@ -407,12 +421,6 @@ class Puppet::Parser::Compiler
data
end
- # Initialize the top-level scope, class, and resource.
- def init_main
- # Create our initial scope and a resource that will evaluate main.
- @topscope = Puppet::Parser::Scope.new(:compiler => self)
- end
-
# Set up all of our internal variables.
def initvars
# The list of objects that will available for export.
@@ -435,6 +443,12 @@ class Puppet::Parser::Compiler
@catalog = Puppet::Resource::Catalog.new(@node.name)
@catalog.version = known_resource_types.version
+ # Create our initial scope and a resource that will evaluate main.
+ @topscope = Puppet::Parser::Scope.new(:compiler => self)
+
+ @main_stage_resource = Puppet::Parser::Resource.new("stage", :main, :scope => @topscope)
+ @catalog.add_resource(@main_stage_resource)
+
# local resource array to maintain resource ordering
@resources = []
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index a4587723e..78d90d4f1 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -22,9 +22,9 @@ class Puppet::Parser::Resource < Puppet::Resource
include Puppet::Parser::YamlTrimmer
attr_accessor :source, :scope, :rails_id
- attr_accessor :virtual, :override, :translated, :catalog
+ attr_accessor :virtual, :override, :translated, :catalog, :evaluated
- attr_reader :exported, :evaluated, :parameters
+ attr_reader :exported, :parameters
# Determine whether the provided parameter name is a relationship parameter.
def self.relationship_parameter?(name)