summaryrefslogtreecommitdiffstats
path: root/lib/puppet/transportable.rb
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2005-11-01 20:22:19 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2005-11-01 20:22:19 +0000
commit300a1632432b5aa5e0221d28fe0a2ce90c422131 (patch)
treece4e28ba94caab4814abd509ba1768b04bae99fb /lib/puppet/transportable.rb
parent14d8186ebe8740eab1b320e6a1d6c98c255ad70f (diff)
downloadpuppet-300a1632432b5aa5e0221d28fe0a2ce90c422131.tar.gz
puppet-300a1632432b5aa5e0221d28fe0a2ce90c422131.tar.xz
puppet-300a1632432b5aa5e0221d28fe0a2ce90c422131.zip
Further progress towards the next release. Lots of small bugs fixed, the paths look much better now, and Transportable is much cleaner.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@740 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/transportable.rb')
-rw-r--r--lib/puppet/transportable.rb83
1 files changed, 33 insertions, 50 deletions
diff --git a/lib/puppet/transportable.rb b/lib/puppet/transportable.rb
index 5ea00713e..ffa751eb6 100644
--- a/lib/puppet/transportable.rb
+++ b/lib/puppet/transportable.rb
@@ -27,7 +27,10 @@ module Puppet
return "%s(%s) => %s" % [@type,self[:name],super]
end
- def to_type
+ def to_type(parent = nil)
+ if parent
+ self[:parent] = parent
+ end
retobj = nil
if type = Puppet::Type.type(self.type)
unless retobj = type.create(self)
@@ -44,6 +47,10 @@ module Puppet
retobj.tags = @tags
end
+ if parent
+ parent.push retobj
+ end
+
return retobj
end
end
@@ -60,14 +67,15 @@ module Puppet
when Puppet::TransBucket, Puppet::TransObject
# nada
else
- raise "TransBuckets cannot handle objects of type %s" %
- arg.class
+ raise Puppet::DevError,
+ "TransBuckets cannot handle objects of type %s" %
+ arg.class
end
}
super
end
- def to_type
+ def to_type(parent = nil)
# this container will contain the equivalent of all objects at
# this level
#container = Puppet::Component.new(:name => @name, :type => @type)
@@ -88,64 +96,39 @@ module Puppet
hash[param] = value
}
else
- Puppet.debug "%s has no parameters" % @name
+ Puppet.debug "%s[%s] has no parameters" % [@type, @name]
+ end
+
+ if parent
+ hash[:parent] = parent
end
container = Puppet::Type::Component.create(hash)
+ if parent
+ parent.push container
+ end
+
# unless we successfully created the container, return an error
unless container
+ Puppet.warning "Got no container back"
return nil
end
- nametable = {}
self.each { |child|
# the fact that we descend here means that we are
# always going to execute depth-first
# which is _probably_ a good thing, but one never knows...
- if child.is_a?(Puppet::TransBucket)
- # just perform the same operation on any children
- obj = child.to_type
- if obj
- container.push(obj)
- else
- # FIXME we need to figure out error handling.
- # really
- end
- elsif child.is_a?(Puppet::TransObject)
- # do a simple little naming hack to see if the object already
- # exists in our scope
- # this assumes that type/name combinations are globally
- # unique
-
- # FIXME this still might be wrong, because it doesn't search
- # up scopes
- # either that, or it's redundant
- name = [child[:name],child.type].join("--")
-
- if nametable.include?(name)
- object = nametable[name]
- child.each { |var,value|
- # don't rename; this shouldn't be possible anyway
- next if var == :name
-
- Puppet.debug "Adding %s to %s" % [var,name]
- # override any existing values
- object[var] = value
- }
- object.parent = self
- else # the object does not exist yet in our scope
- # now we have the object instantiated, in our scope
- if object = child.to_type
- # the object will be nil if it failed
- nametable[name] = object
-
- # this sets the order of the object
- container.push object
- end
- end
- else
- raise "TransBucket#to_type cannot handle objects of type %s" %
- child.class
+ unless child.is_a?(Puppet::TransBucket) or
+ child.is_a?(Puppet::TransObject)
+ raise Puppet::DevError,
+ "TransBucket#to_type cannot handle objects of type %s" %
+ child.class
+ end
+
+ # Now just call to_type on them with the container as a parent
+ unless obj = child.to_type(container)
+ # nothing; we assume the method already warned
+ Puppet.warning "Could not create child %s" % child.name
end
}