summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/ast
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2008-10-11 17:26:50 +0200
committerJames Turnbull <james@lovedthanlost.net>2009-03-14 11:31:28 +1100
commitb15028f55ba608a701efae1ee392d50374b2be54 (patch)
treebf4c4053dcc797c1bef3b89cf634bdd3b2828d3f /lib/puppet/parser/ast
parentb24b9f5de02f4dfc6a7e89d5432aec32ea39cae1 (diff)
downloadpuppet-b15028f55ba608a701efae1ee392d50374b2be54.tar.gz
puppet-b15028f55ba608a701efae1ee392d50374b2be54.tar.xz
puppet-b15028f55ba608a701efae1ee392d50374b2be54.zip
Fix #1088 - Collections overrides
This changeset defines a new syntax to override collection of resources (virtual or not). This feature is not constrained to the override in inherited context as usual resource override. The collection of resource supports a query like regular collection of virtual or exported resources. Usage example: file { "/tmp/testing": content => "whatever" } File<| |> { mode => 0600 } It also introduces a different behaviour for collection of catalog resources. Before this patch, only virtual resources were collected, now all resources (virtual or no) are collected and can be overriden. That means it is now possible to do: File <| |> { mode => 0600 } And all the Files resources will have mode 0600. It is then possible to have this puppet pattern: file { "/tmp/a": content => "a" } file { "/tmp/b": content => "b" } File <| title != "/tmp/a" |> { require => File["/tmp/b"] } which means that every File requires a file. Moreover it is now possible to define resource overriding without respecting the override on inheritance rule: class a { file { "/tmp/testing": content => "whatever" } } class b { include a File<| |> { mode => 0600 } } include b Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'lib/puppet/parser/ast')
-rw-r--r--lib/puppet/parser/ast/collection.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/puppet/parser/ast/collection.rb b/lib/puppet/parser/ast/collection.rb
index a51b9b4d2..55e99fc08 100644
--- a/lib/puppet/parser/ast/collection.rb
+++ b/lib/puppet/parser/ast/collection.rb
@@ -7,6 +7,7 @@ require 'puppet/parser/collector'
class Puppet::Parser::AST
class Collection < AST::Branch
attr_accessor :type, :query, :form
+ attr_reader :override
associates_doc
@@ -22,7 +23,37 @@ class Collection < AST::Branch
scope.compiler.add_collection(newcoll)
+ # overrides if any
+ # Evaluate all of the specified params.
+ if @override
+ params = @override.collect do |param|
+ param.safeevaluate(scope)
+ end
+
+ newcoll.add_override(
+ :params => params,
+ :file => @file,
+ :line => @line,
+ :source => scope.source,
+ :scope => scope
+ )
+ end
+
newcoll
end
+
+ # Handle our parameter ourselves
+ def override=(override)
+ if override.is_a?(AST::ASTArray)
+ @override = override
+ else
+ @override = AST::ASTArray.new(
+ :line => override.line,
+ :file => override.file,
+ :children => [override]
+ )
+ end
+ end
+
end
end