diff options
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/parser/ast/collection.rb | 47 | ||||
-rw-r--r-- | lib/puppet/parser/scope.rb | 63 | ||||
-rw-r--r-- | lib/puppet/transportable.rb | 4 |
3 files changed, 85 insertions, 29 deletions
diff --git a/lib/puppet/parser/ast/collection.rb b/lib/puppet/parser/ast/collection.rb index 030f1c239..8e9acce57 100644 --- a/lib/puppet/parser/ast/collection.rb +++ b/lib/puppet/parser/ast/collection.rb @@ -6,29 +6,58 @@ class Puppet::Parser::AST class Collection < AST::Branch attr_accessor :type + # We cannot evaluate directly here; instead we need to store a + # CollectType object, which will do the collection. This is + # the only way to find certain exported types in the current + # configuration. def evaluate(hash) scope = hash[:scope] - type = @type.safeevaluate(:scope => scope) + @convertedtype = @type.safeevaluate(:scope => scope) - count = 0 - # Now perform the actual collection, yo. + scope.newcollection(self) + end + # Now perform the actual collection, yo. + def perform(scope) # First get everything from the export table. # FIXME This will only find objects that are before us in the tree, # which is a problem. - objects = scope.exported(type) + objects = scope.exported(@convertedtype) + # We want to return all of these objects, and then whichever objects + # we find in the db. array = objects.values + # Mark all of these objects as collected, so that they also get + # returned to the client. We don't store them in our scope + # or anything, which is a little odd, but eh. + array.each do |obj| + obj.collected = true + end + + count = array.length + + # Now we also have to see if there are any exported objects + # in our own scope. + scope.lookupexported(@convertedtype).each do |obj| + objects[obj.name] = obj + obj.collected = true + end + + bucket = Puppet::TransBucket.new + Puppet::Rails::RailsObject.find_all_by_collectable(true).each do |obj| + # FIXME This should check that the source of the object is the + # host we're running on, else it's a bad conflict. if objects.include?(obj.name) - debug("%s[%s] is already exported" % [type, obj.name]) + scope.debug("%s[%s] is already exported" % [@convertedtype, obj.name]) next end count += 1 trans = obj.to_trans + bucket.push(trans) args = { :name => trans.name, @@ -43,6 +72,7 @@ class Puppet::Parser::AST args[:arguments] = {} trans.each do |p,v| args[:arguments][p] = v end + # XXX Because the scopes don't expect objects to return values, # we have to manually add our objects to the scope. This is @@ -50,13 +80,10 @@ class Puppet::Parser::AST scope.setobject(args) end - - scope.debug("Collected %s objects of type %s" % - [count, type]) + [count, @convertedtype]) - # The return value is entirely ignored right now, unfortunately. - return nil + return bucket end end end diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index baef76bfa..e0afbae4a 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -523,6 +523,30 @@ module Puppet::Parser return values end + # Look up all of the exported objects of a given type. Just like + # lookupobject, this only searches up through parent classes, not + # the whole scope tree. + def lookupexported(type) + found = [] + sub = proc { |table| + # We always return nil so that it will search all the way + # up the scope tree. + if table.has_key?(type) + table[type].each do |name, obj| + found << obj + end + nil + else + info table.keys.inspect + nil + end + } + + value = lookup("object",sub, false) + + return found + end + # Look up a node by name def lookupnode(name) #Puppet.debug "Looking up type %s" % name @@ -573,19 +597,18 @@ module Puppet::Parser # Look up a variable. The simplest value search we do. def lookupvar(name) - #Puppet.debug "Looking up variable %s" % name value = lookup("variable", name) if value == :undefined return "" - #error = Puppet::ParseError.new( - # "Undefined variable '%s'" % name - #) - #raise error else return value end end + def newcollection(coll) + @children << coll + end + # Add a new object to our object table. def newobject(hash) if @objectable[hash[:type]].include?(hash[:name]) @@ -894,7 +917,8 @@ module Puppet::Parser @children.dup.each do |child| if @@done.include?(child) - raise Puppet::DevError, "Already translated %s" % child.object_id + raise Puppet::DevError, "Already translated %s" % + child.object_id else @@done << child end @@ -906,7 +930,6 @@ module Puppet::Parser result = nil case child when Scope - #raise Puppet::DevError, "got a child scope" result = child.to_trans when Puppet::TransObject # These objects can map to defined types or builtin types. @@ -941,14 +964,24 @@ module Puppet::Parser :collectable => child.collectable ) else - # If it's collectable, then store it. + # If it's collectable, then store it. It will be + # stripped out in the interpreter using the collectstrip + # method. If we don't do this, then these objects + # don't get stored in the DB. if child.collectable exportobject(child) - result = nil - else - # It's a builtin type, so just return it directly - result = child end + result = child + end + # This is pretty hackish, but the collection has to actually + # be performed after all of the classes and definitions are + # evaluated, otherwise we won't catch objects that are exported + # in them. I think this will still be pretty limited in some + # cases, especially those where you are both exporting and + # collecting, but it's the best I can do for now. + when Puppet::Parser::AST::Collection + child.perform(self).each do |obj| + results << obj end else raise Puppet::DevError, @@ -1033,11 +1066,7 @@ module Puppet::Parser if usecontext and self.context != @parent.context return :undefined else - #if defined? @superscope and val = @superscope.lookup(type,sub, usecontext) and val != :undefined - # return val - #else - return @parent.lookup(type,sub, usecontext) - #end + return @parent.lookup(type,sub, usecontext) end else return :undefined diff --git a/lib/puppet/transportable.rb b/lib/puppet/transportable.rb index bca2e688c..501dd8d89 100644 --- a/lib/puppet/transportable.rb +++ b/lib/puppet/transportable.rb @@ -8,7 +8,7 @@ module Puppet # YAML. class TransObject include Enumerable - attr_accessor :type, :name, :file, :line, :collectable + attr_accessor :type, :name, :file, :line, :collectable, :collected attr_writer :tags @@ -109,7 +109,7 @@ module Puppet if child.is_a? self.class child.collectstrip! else - if child.collectable + if child.collectable and ! child.collected @children.delete(child) end end |