diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-08-17 05:08:36 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-08-17 05:08:36 +0000 |
commit | beba3e480c7ad7f942414a8aa31f96b5b42b53e4 (patch) | |
tree | d3c2949930af4462b5a1d03a46b0f8d76e087d0c /lib | |
parent | 607d7c6afec7ab73203382676cc98b6d52898e1d (diff) | |
download | puppet-beba3e480c7ad7f942414a8aa31f96b5b42b53e4.tar.gz puppet-beba3e480c7ad7f942414a8aa31f96b5b42b53e4.tar.xz puppet-beba3e480c7ad7f942414a8aa31f96b5b42b53e4.zip |
Finishing changes to support titles instead of two types of names. This is basically a bug-fix commit.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1472 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/type.rb | 101 | ||||
-rw-r--r-- | lib/puppet/type/component.rb | 36 | ||||
-rw-r--r-- | lib/puppet/type/pfile.rb | 11 | ||||
-rwxr-xr-x | lib/puppet/type/pfile/checksum.rb | 8 | ||||
-rwxr-xr-x | lib/puppet/type/pfile/content.rb | 2 | ||||
-rwxr-xr-x | lib/puppet/type/pfile/ensure.rb | 4 | ||||
-rwxr-xr-x | lib/puppet/type/pfile/source.rb | 4 | ||||
-rwxr-xr-x | lib/puppet/type/symlink.rb | 7 |
8 files changed, 101 insertions, 72 deletions
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index b39950f7e..2ebc2b977 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -331,8 +331,11 @@ class Type < Puppet::Element # remove a specified object def self.delete(object) return unless defined? @objects - if @objects.include?(object.name) - @objects.delete(object.name) + if @objects.include?(object.title) + @objects.delete(object.title) + end + if @aliases.include?(object.title) + @aliases.delete(object.title) end end @@ -790,20 +793,22 @@ class Type < Puppet::Element # What type of parameter are we dealing with? Cache the results, because # this method gets called so many times. - def self.attrtype(name) + def self.attrtype(attr) @attrtypes ||= {} - unless @attrtypes.include?(name) - @attrtypes[name] = case - when @validstates.include?(name): :state - when @@metaparamhash.include?(name): :meta - when @paramhash.include?(name): :param + unless @attrtypes.include?(attr) + @attrtypes[attr] = case + when @validstates.include?(attr): :state + when @@metaparamhash.include?(attr): :meta + when @paramhash.include?(attr): :param else - raise Puppet::DevError, "Invalid attribute '%s' for class '%s'" % - [name, self.name] + Puppet.err "raising a warning, yo: %s" % attr + raise Puppet::DevError, + "Invalid attribute '%s' for class '%s'" % + [attr, self.name] end end - @attrtypes[name] + @attrtypes[attr] end # All parameters, in the appropriate order. The namevar comes first, @@ -1177,7 +1182,7 @@ class Type < Puppet::Element def parent=(parent) if self.parentof?(parent) devfail "%s[%s] is already the parent of %s[%s]" % - [self.class.name, self.name, parent.class.name, parent.name] + [self.class.name, self.title, parent.class.name, parent.title] end @parent = parent end @@ -1205,7 +1210,7 @@ class Type < Puppet::Element childs.each { |child| # Make sure we don't have any loops here. if parentof?(child) - devfail "Already the parent of %s[%s]" % [child.class.name, child.name] + devfail "Already the parent of %s[%s]" % [child.class.name, child.title] end unless child.is_a?(Puppet::Element) self.debug "Got object of type %s" % child.class @@ -1351,8 +1356,6 @@ class Type < Puppet::Element name = nil unless hash.is_a? TransObject - # if it's not a transobject, then make it one, just to make people's - # lives easier hash = self.hash2trans(hash) end @@ -1422,13 +1425,22 @@ class Type < Puppet::Element # Convert a hash to a TransObject. def self.hash2trans(hash) title = nil - [:title, self.namevar, :name].each { |param| - if hash.include? param - title = hash[param] - hash.delete(param) - break + if hash.include? :title + title = hash[:title] + hash.delete(:title) + elsif hash.include? self.namevar + title = hash[self.namevar] + hash.delete(self.namevar) + + if hash.include? :name + raise ArgumentError, "Cannot provide both name and %s to %s" % + [self.namevar, self.name] end - } + elsif hash[:name] + title = hash[:name] + hash.delete :name + end + unless title raise Puppet::Error, "You must specify a title for objects of type %s" % self.to_s @@ -1531,6 +1543,7 @@ class Type < Puppet::Element namevar = self.class.namevar orighash = hash + # If we got passed a transportable object, we just pull a bunch of info # directly from it. This is the main object instantiation mechanism. if hash.is_a?(Puppet::TransObject) @@ -1562,16 +1575,16 @@ class Type < Puppet::Element # Munge up the namevar stuff so we only have one value. hash = self.argclean(hash) - # If we've got a title via some other mechanism, set it as an alias. - if defined? @title and @title - if aliases = hash[:alias] - aliases = [aliases] unless aliases.is_a? Array - aliases << @title - hash[:alias] = aliases - else - hash[:alias] = @title - end - end + # If we've got both a title via some other mechanism, set it as an alias. +# if defined? @title and @title and ! hash[:name] +# if aliases = hash[:alias] +# aliases = [aliases] unless aliases.is_a? Array +# aliases << @title +# hash[:alias] = aliases +# else +# hash[:alias] = @title +# end +# end # Let's do the name first, because some things need to happen once # we have the name but before anything else @@ -1591,6 +1604,10 @@ class Type < Puppet::Element self.devfail "I was not passed a namevar" end + if self.name != self.title + self.class.alias(self.name, self) + end + # The information to cache to disk. We have to do this after # the name is set because it uses the name and/or path, but before # everything else is set because the states need to be able to @@ -1653,7 +1670,7 @@ class Type < Puppet::Element # Now change our dependency to just the string, instead of # the object itself. - dep = dep.name + dep = dep.title else # Skip autorequires that we aren't managing unless obj = typeobj[dep] @@ -1664,7 +1681,7 @@ class Type < Puppet::Element # Skip autorequires that we already require next if self.requires?(obj) - debug "Autorequiring %s %s" % [obj.class.name, obj.name] + debug "Autorequiring %s %s" % [obj.class.name, obj.title] self[:require] = [type, dep] } @@ -1797,6 +1814,7 @@ class Type < Puppet::Element obj.value = value else #self.debug "No default for %s" % obj.name + # "obj" is a Parameter. self.delete(obj.name) end } @@ -1834,10 +1852,10 @@ class Type < Puppet::Element newvals = oldvals & value if newvals.empty? self.fail "No common values for %s on %s(%s)" % - [param, self.class.name, self.name] + [param, self.class.name, self.title] elsif newvals.length > 1 self.fail "Too many values for %s on %s(%s)" % - [param, self.class.name, self.name] + [param, self.class.name, self.title] else self.debug "Reduced old values %s and new values %s to %s" % [oldvals.inspect, value.inspect, newvals.inspect] @@ -1909,6 +1927,9 @@ class Type < Puppet::Element # Do a simple translation for those cases where they've passed :name # but that's not our namevar if hash.include? :name and namevar != :name + if hash.include? namevar + raise ArgumentError, "Cannot provide both name and %s" % namevar + end hash[namevar] = hash[:name] hash.delete(:name) end @@ -1937,7 +1958,7 @@ class Type < Puppet::Element # convert to a string def to_s - self.name + self.title end # Convert to a transportable object @@ -1945,7 +1966,7 @@ class Type < Puppet::Element # Collect all of the "is" values retrieve() - trans = TransObject.new(self.name, self.class.name) + trans = TransObject.new(self.title, self.class.name) states().each do |state| trans[state.name] = state.is @@ -1953,7 +1974,7 @@ class Type < Puppet::Element @parameters.each do |name, param| # Avoid adding each instance name as both the name and the namevar - next if param.class.isnamevar? and param.value == self.name + next if param.class.isnamevar? and param.value == self.title trans[name] = param.value end @@ -2031,7 +2052,7 @@ class Type < Puppet::Element #Puppet.err "Evaluating %s" % self.path.join(":") unless defined? @evalcount self.err "No evalcount defined on '%s' of type '%s'" % - [self.name,self.class] + [self.title,self.class] @evalcount = 0 end @evalcount += 1 @@ -2516,7 +2537,7 @@ class Type < Puppet::Element unless obj == @parent self.fail( "%s can not create alias %s: object already exists" % - [@parent.name, other] + [@parent.title, other] ) end next diff --git a/lib/puppet/type/component.rb b/lib/puppet/type/component.rb index 9123bbe75..c159ccc83 100644 --- a/lib/puppet/type/component.rb +++ b/lib/puppet/type/component.rb @@ -73,6 +73,16 @@ module Puppet @children.each { |child| yield child } end + # flatten all children, sort them, and evaluate them in order + # this is only called on one component over the whole system + # this also won't work with scheduling, but eh + def evaluate + self.finalize unless self.finalized? + transaction = Puppet::Transaction.new(self.flatten) + transaction.component = self + return transaction + end + # Do all of the polishing off, mostly doing autorequires and making # dependencies. This will get run once on the top-level component, # and it will do everything necessary. @@ -84,7 +94,7 @@ module Puppet self.delve do |object| # Make sure we don't get into loops if started.has_key?(object) - debug "Already finished %s" % object.name + debug "Already finished %s" % object.title next else started[object] = true @@ -119,26 +129,16 @@ module Puppet super(args) end - # flatten all children, sort them, and evaluate them in order - # this is only called on one component over the whole system - # this also won't work with scheduling, but eh - def evaluate - self.finalize unless self.finalized? - transaction = Puppet::Transaction.new(self.flatten) - transaction.component = self - return transaction - end - - def name - #return self[:name] - unless defined? @name + # We have a different way of setting the title + def title + unless defined? @title if self[:type] == self[:name] or self[:name] =~ /--\d+$/ - @name = self[:type] + @title = self[:type] else - @name = "%s[%s]" % [self[:type],self[:name]] + @title = "%s[%s]" % [self[:type],self[:name]] end end - return @name + return @title end def refresh @@ -151,7 +151,7 @@ module Puppet end def to_s - return "component(%s)" % self.name + return "component(%s)" % self.title end end end diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb index ee84b0699..a6892c88e 100644 --- a/lib/puppet/type/pfile.rb +++ b/lib/puppet/type/pfile.rb @@ -369,6 +369,10 @@ module Puppet def initialize(hash) # Store a copy of the arguments for later. tmphash = hash.to_hash + + # Used for caching clients + @clients = {} + super # Clean out as many references to any file paths as possible. # This was the source of many, many bugs. @@ -379,10 +383,11 @@ module Puppet @arghash.delete(:source) end - @stat = nil + if @arghash.include?(:parent) + @arghash.delete(:parent) + end - # Used for caching clients - @clients = {} + @stat = nil end # Create a new file or directory object as a child to the current diff --git a/lib/puppet/type/pfile/checksum.rb b/lib/puppet/type/pfile/checksum.rb index d5de955e6..cd82a4439 100755 --- a/lib/puppet/type/pfile/checksum.rb +++ b/lib/puppet/type/pfile/checksum.rb @@ -183,7 +183,7 @@ module Puppet def handlesum if @is.nil? raise Puppet::Error, "Checksum state for %s is somehow nil" % - @parent.name + @parent.title end if @is == :absent @@ -277,14 +277,14 @@ module Puppet result = false state = nil unless state = @parent.cached(:checksums) - self.debug "Initializing checksum hash for %s" % @parent.name + self.debug "Initializing checksum hash for %s" % @parent.title state = {} @parent.cache(:checksums, state) end if @is.is_a?(Symbol) error = Puppet::Error.new("%s has invalid checksum" % - @parent.name) + @parent.title) raise error end @@ -297,7 +297,7 @@ module Puppet ) end self.debug "Replacing %s checksum %s with %s" % - [@parent.name, state[@checktypes[0]],@is] + [@parent.title, state[@checktypes[0]],@is] #@parent.debug "@is: %s; @should: %s" % [@is,@should] result = true else diff --git a/lib/puppet/type/pfile/content.rb b/lib/puppet/type/pfile/content.rb index 67840361b..5853b99f6 100755 --- a/lib/puppet/type/pfile/content.rb +++ b/lib/puppet/type/pfile/content.rb @@ -49,7 +49,7 @@ module Puppet rescue => detail @is = nil raise Puppet::Error, "Could not read %s: %s" % - [@parent.name, detail] + [@parent.title, detail] end end diff --git a/lib/puppet/type/pfile/ensure.rb b/lib/puppet/type/pfile/ensure.rb index d15d1c6b9..f22e43637 100755 --- a/lib/puppet/type/pfile/ensure.rb +++ b/lib/puppet/type/pfile/ensure.rb @@ -112,11 +112,11 @@ module Puppet if ! FileTest.exists?(basedir) raise Puppet::Error, "Can not create %s; parent directory does not exist" % - @parent.name + @parent.title elsif ! FileTest.directory?(basedir) raise Puppet::Error, "Can not create %s; %s is not a directory" % - [@parent.name, dirname] + [@parent.title, dirname] end end diff --git a/lib/puppet/type/pfile/source.rb b/lib/puppet/type/pfile/source.rb index 606d8ec32..2bdce9240 100755 --- a/lib/puppet/type/pfile/source.rb +++ b/lib/puppet/type/pfile/source.rb @@ -78,7 +78,7 @@ module Puppet unless defined? @shouldorig raise Puppet::DevError, "No sources defined for %s" % - @parent.name + @parent.title end @source = nil unless defined? @source @@ -211,7 +211,7 @@ module Puppet self.retrieve # try again if @is == :notdescribed @parent.log "Could not retreive information on %s" % - @parent.name + @parent.title return nil end if @is == @should diff --git a/lib/puppet/type/symlink.rb b/lib/puppet/type/symlink.rb index 356fd6688..63f109dcf 100755 --- a/lib/puppet/type/symlink.rb +++ b/lib/puppet/type/symlink.rb @@ -176,9 +176,12 @@ module Puppet end def initialize(hash) - @arghash = self.argclean(hash.dup) - @arghash.delete(self.class.namevar) + tmphash = hash.to_hash super + @arghash = tmphash + @arghash.delete(self.class.namevar) + #@arghash = self.argclean(hash.dup) + #@arghash.delete(self.class.namevar) end end # Puppet.type(:symlink) end |