summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/compiler.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@puppetlabs.com>2010-05-10 23:50:05 -0700
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commit2c153b12921d67354ea0968ad81590a124ac8b75 (patch)
treee1667858786446a5a56306823663960c2ec4905b /lib/puppet/parser/compiler.rb
parent052f98fdac20af4593372ecedaa13af97664a482 (diff)
downloadpuppet-2c153b12921d67354ea0968ad81590a124ac8b75.tar.gz
puppet-2c153b12921d67354ea0968ad81590a124ac8b75.tar.xz
puppet-2c153b12921d67354ea0968ad81590a124ac8b75.zip
Fixing #448 - relationships have their own syntax
You can now specify relationships directly in the language: File[/foo] -> Service[bar] Specifies a normal dependency while: File[/foo] ~> Service[bar] Specifies a subscription. You can also do relationship chaining, specifying multiple relationships on a single line: File[/foo] -> Package[baz] -> Service[bar] Note that while it's confusing, you don't have to have all of the arrows be the same direction: File[/foo] -> Service[bar] <~ Package[baz] This can provide some succinctness at the cost of readability. You can also specify full resources, rather than just resource refs: file { "/foo": ensure => present } -> package { bar: ensure => installed } But wait! There's more! You can also specify a subscription on either side of the relationship marker: yumrepo { foo: .... } package { bar: provider => yum, ... } Yumrepo <| |> -> Package <| provider == yum |> This, finally, provides easy many to many relationships in Puppet, but it also opens the door to massive dependency cycles. This last feature is a very powerful stick, and you can considerably hurt yourself with it. Signed-off-by: Luke Kanies <luke@puppetlabs.com>
Diffstat (limited to 'lib/puppet/parser/compiler.rb')
-rw-r--r--lib/puppet/parser/compiler.rb15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/puppet/parser/compiler.rb b/lib/puppet/parser/compiler.rb
index 8e84f5a5b..fd7d9680b 100644
--- a/lib/puppet/parser/compiler.rb
+++ b/lib/puppet/parser/compiler.rb
@@ -21,13 +21,17 @@ class Puppet::Parser::Compiler
raise Puppet::Error, "#{detail} on node #{node.name}"
end
- attr_reader :node, :facts, :collections, :catalog, :node_scope, :resources
+ attr_reader :node, :facts, :collections, :catalog, :node_scope, :resources, :relationships
# Add a collection to the global list.
def add_collection(coll)
@collections << coll
end
+ def add_relationship(dep)
+ @relationships << dep
+ end
+
# Store a resource override.
def add_override(override)
# If possible, merge the override in immediately.
@@ -144,6 +148,10 @@ class Puppet::Parser::Compiler
found
end
+ def evaluate_relationships
+ @relationships.each { |rel| rel.evaluate(catalog) }
+ end
+
# Return a resource by either its ref or its type and title.
def findresource(*args)
@catalog.resource(*args)
@@ -337,6 +345,8 @@ class Puppet::Parser::Compiler
# Make sure all of our resources and such have done any last work
# necessary.
def finish
+ evaluate_relationships()
+
resources.each do |resource|
# Add in any resource overrides.
if overrides = resource_overrides(resource)
@@ -374,6 +384,9 @@ class Puppet::Parser::Compiler
# but they each refer back to the scope that created them.
@collections = []
+ # The list of relationships to evaluate.
+ @relationships = []
+
# For maintaining the relationship between scopes and their resources.
@catalog = Puppet::Resource::Catalog.new(@node.name)
@catalog.version = known_resource_types.version