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 | |
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')
-rw-r--r-- | lib/puppet/parser/interpreter.rb | 30 | ||||
-rw-r--r-- | lib/puppet/parser/scope.rb | 66 | ||||
-rw-r--r-- | lib/puppet/server/master.rb | 4 |
3 files changed, 70 insertions, 30 deletions
diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb index 9335d81aa..2b036018f 100644 --- a/lib/puppet/parser/interpreter.rb +++ b/lib/puppet/parser/interpreter.rb @@ -10,21 +10,23 @@ require 'puppet/parser/scope' module Puppet module Parser class Interpreter - attr_accessor :ast, :topscope + attr_accessor :ast # just shorten the constant path a bit, using what amounts to an alias AST = Puppet::Parser::AST # create our interpreter def initialize(hash) unless hash.include?(:Manifest) - raise Puppet::DevError, "Interpreter was not passed a file" + raise Puppet::DevError, "Interpreter was not passed a manifest" end @file = hash[:Manifest] if hash.include?(:UseNodes) + Puppet.warning "Usenodes is %s" % hash[:UseNodes] @usenodes = hash[:UseNodes] else + Puppet.warning "Usenodes is missing" @usenodes = true end @@ -38,6 +40,9 @@ module Puppet def run(client, facts) parsefiles() + # Really, we should stick multiple names in here + # but for now just make a simple array + names = [client] begin if @usenodes unless client @@ -46,13 +51,13 @@ module Puppet end # We've already evaluated the AST, in this case - @scope.evalnode(client, facts) + @scope.evalnode(names, facts) else - scope = Puppet::Parser::Scope.new() # no parent scope - scope.interp = self - scope.evaluate(@ast, facts) + @scope = Puppet::Parser::Scope.new() # no parent scope + @scope.interp = self + @scope.evaluate(@ast, facts) end - @ast.evaluate(@scope) + #@ast.evaluate(@scope) rescue Puppet::DevError, Puppet::Error, Puppet::ParseError => except #Puppet.err "File %s, line %s: %s" % # [except.file, except.line, except.message] @@ -79,10 +84,10 @@ module Puppet # to pass to the client # this will be heirarchical, and will (at this point) contain # only TransObjects and TransSettings - @topscope.name = "top" - @topscope.type = "puppet" + @scope.name = "top" + @scope.type = "puppet" begin - topbucket = @topscope.to_trans + topbucket = @scope.to_trans rescue => detail Puppet.warning detail raise @@ -114,11 +119,10 @@ module Puppet # this doesn't actually do anything, because we have to evaluate the # entire configuration each time we get a connect. def evaluate - @scope = Puppet::Parser::Scope.new() # no parent scope - @topscope = @scope - @scope.interp = self if @usenodes + @scope = Puppet::Parser::Scope.new() # no parent scope + @scope.interp = self Puppet.debug "Nodes defined" @ast.safeevaluate(@scope) else 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 diff --git a/lib/puppet/server/master.rb b/lib/puppet/server/master.rb index bf6998bac..08706bea7 100644 --- a/lib/puppet/server/master.rb +++ b/lib/puppet/server/master.rb @@ -38,7 +38,9 @@ class Server args = {:Manifest => @file} - if @local + if hash.include?(:UseNodes) + args[:UseNodes] = hash[:UseNodes] + elsif @local args[:UseNodes] = false end |