summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/interpreter.rb
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-04-05 03:40:03 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-04-05 03:40:03 +0000
commitee652796206b8d2eb52befa2e1fe3032b21c19b3 (patch)
treeff5e311cba34d3bf6667dfe72c81ae88aec0e179 /lib/puppet/parser/interpreter.rb
parentc3c413ea4549743a9a7718654d36054df72c16e6 (diff)
downloadpuppet-ee652796206b8d2eb52befa2e1fe3032b21c19b3.tar.gz
puppet-ee652796206b8d2eb52befa2e1fe3032b21c19b3.tar.xz
puppet-ee652796206b8d2eb52befa2e1fe3032b21c19b3.zip
Fixing #103. There are now no such things as node scopes; the entire tree is evaluated on every node connection, and node facts are set at the top-level scope. This includes,um, the code; the last commit was accidentally just test changes.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1073 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/parser/interpreter.rb')
-rw-r--r--lib/puppet/parser/interpreter.rb95
1 files changed, 47 insertions, 48 deletions
diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb
index 730b59e15..35c122c43 100644
--- a/lib/puppet/parser/interpreter.rb
+++ b/lib/puppet/parser/interpreter.rb
@@ -85,6 +85,7 @@ module Puppet
require 'ldap'
rescue LoadError
@ldap = nil
+ return
end
begin
@ldap = LDAP::Conn.new(Puppet[:ldapserver], Puppet[:ldapport])
@@ -95,6 +96,25 @@ module Puppet
end
end
+ # Search for our node in the various locations.
+ def nodesearch(node)
+ # At this point, stop at the first source that defines
+ # the node
+ @nodesources.each do |source|
+ method = "nodesearch_%s" % source
+ if self.respond_to? method
+ parent, nodeclasses = self.send(method, node)
+ end
+
+ if nodeclasses
+ Puppet.info "Found %s in %s" % [client, source]
+ return parent, nodeclasses
+ end
+ end
+
+ return nil, nil
+ end
+
# Find the ldap node and extra the info, returning just
# the critical data.
def nodesearch_ldap(node)
@@ -171,63 +191,42 @@ module Puppet
names << "#{client}.#{facts['domain']}"
end
- begin
- if @usenodes
- unless client
- raise Puppet::Error,
- "Cannot evaluate nodes with a nil client"
- end
+ scope = Puppet::Parser::Scope.new() # no parent scope
+ scope.name = "top"
+ scope.type = "puppet"
+ scope.interp = self
- classes = nil
- parent = nil
- # At this point, stop at the first source that defines
- # the node
- @nodesources.each do |source|
- method = "nodesearch_%s" % source
- if self.respond_to? method
- parent, classes = self.send(method, client)
- end
+ classes = @classes.dup
- if classes
- Puppet.info "Found %s in %s" % [client, source]
- break
- end
- end
+ args = {:ast => @ast, :facts => facts, :classes => classes}
- # We've already evaluated the AST, in this case
- #return @scope.evalnode(names, facts, classes, parent)
- return @scope.evalnode(
- :name => names,
- :facts => facts,
- :classes => classes,
- :parent => parent
- )
- else
- # We've already evaluated the AST, in this case
- @scope = Puppet::Parser::Scope.new() # no parent scope
- @scope.interp = self
- #return @scope.evaluate(@ast, facts, @classes)
- return @scope.evaluate(
- :ast => @ast,
- :facts => facts,
- :classes => @classes
- )
+ if @usenodes
+ unless client
+ raise Puppet::Error,
+ "Cannot evaluate nodes with a nil client"
end
- #@ast.evaluate(@scope)
+
+ Puppet.debug "Nodes defined"
+ args[:names] = names
+
+ parent, nodeclasses = nodesearch(client)
+
+ classes += nodeclasses if nodeclasses
+
+ args[:parentnode] = parent if parent
+ end
+
+ begin
+ return scope.evaluate(args)
rescue Puppet::DevError, Puppet::Error, Puppet::ParseError => except
- #Puppet.err "File %s, line %s: %s" %
- # [except.file, except.line, except.message]
- if Puppet[:debug]
- puts except.backtrace
- end
- #exit(1)
raise
rescue => except
error = Puppet::DevError.new("%s: %s" %
[except.class, except.message])
- if Puppet[:debug]
- puts except.backtrace
- end
+ error.backtrace = except.backtrace
+ #if Puppet[:debug]
+ # puts except.backtrace
+ #end
raise error
end
end