diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2005-09-22 17:59:50 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2005-09-22 17:59:50 +0000 |
commit | 55901486d236f98ecfb2717509c5904687969f25 (patch) | |
tree | 87c704c49302c470263e2136c99ff25156b7448f /lib/puppet/parser/scope.rb | |
parent | f7d9b83a83bf43b13846c4b621794257f04832bb (diff) | |
download | puppet-55901486d236f98ecfb2717509c5904687969f25.tar.gz puppet-55901486d236f98ecfb2717509c5904687969f25.tar.xz puppet-55901486d236f98ecfb2717509c5904687969f25.zip |
Okay, all tests pass again. The work done on nodes will take a little while to clarify and such, but it should work pretty well.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@698 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/parser/scope.rb')
-rw-r--r-- | lib/puppet/parser/scope.rb | 66 |
1 files changed, 50 insertions, 16 deletions
diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index 56bf620dd..d813ea804 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -79,7 +79,7 @@ module Puppet # Yield each child scope in turn def each - @children.each { |child| + @children.reject { |child| yield child } end @@ -90,7 +90,8 @@ module Puppet def evalnode(names, facts) scope = code = nil names.each { |node| - scope, code = self.findnode(node) + scope = self.findnode(node) + code = scope.node(node) if scope and code break end @@ -124,14 +125,27 @@ module Puppet # Find a given node's definition; searches downward recursively. def findnode(node) if @nodetable.include?(node) - return [self, @nodetable[node]] + return self else - self.find { |child| - child.findnode(node) + scope = nil + self.reject { |child| + ! child.is_a?(Scope) + }.each { |child| + if scope = child.findnode(node) + break + end } + + return scope end end + # Retrieve a specific node. This is basically only used from within + # 'findnode'. + def node(name) + @nodetable[name] + end + # Evaluate normally, with no node definitions def evaluate(objects, facts = {}) facts.each { |var, value| @@ -245,15 +259,6 @@ module Puppet end end - # Look up hosts from the global table. - def lookuphost(name) - if @@hosttable.include?(name) - return @@hosttable[name] - else - return nil - end - end - # Collect all of the defaults set at any higher scopes. # This is a different type of lookup because it's additive -- # it collects all of the defaults, with defaults in closer scopes @@ -390,12 +395,41 @@ module Puppet } end + # Check whether a node is already defined. + # FIXME Should this system replace the 'UseNodes' flags and such? + def nodedefined?(name) + if defined? @nodemarkers + return @nodemarkers[name] + else + if @parent + return @parent.nodedefined?(name) + else + return false + end + end + end + + # Mark that a node is defined. We don't want to allow more than one + # node definition per name, because, well, that would make things not + # work any more. + def marknode(name) + if @parent + @parent.marknode(name) + else + unless defined? @nodemarkers + @nodemarkers = {} + end + @nodemarkers[name] = true + end + end + # Store a host in the global table. def setnode(name,code) - if @nodetable.include?(name) - raise Puppet::Error, "Host %s is already defined" % name + if self.nodedefined?(name) + raise Puppet::ParseError, "Host %s is already defined" % name else @nodetable[name] = code + self.marknode(name) end #self.nodescope = true |