diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-05-09 22:05:32 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-05-09 22:05:32 +0000 |
commit | de212261e75883036f74e241a548d31340440df9 (patch) | |
tree | c755fb3583efb1e38aa463d197753e76781cf356 | |
parent | 3e7d44e6288bcb67f29e57a9ff886532ce64878b (diff) | |
download | puppet-de212261e75883036f74e241a548d31340440df9.tar.gz puppet-de212261e75883036f74e241a548d31340440df9.tar.xz puppet-de212261e75883036f74e241a548d31340440df9.zip |
Fixing #607 -- parameters and properties now refer to a @resource rather than a @parent. The @parent parameter is still set for now, for backward compatibility.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2500 980ebf18-57e1-0310-9a29-db15c13687c0
39 files changed, 318 insertions, 309 deletions
diff --git a/lib/puppet/metatype/attributes.rb b/lib/puppet/metatype/attributes.rb index 679d6fc2f..9a32c05ff 100644 --- a/lib/puppet/metatype/attributes.rb +++ b/lib/puppet/metatype/attributes.rb @@ -413,8 +413,8 @@ class Puppet::Type # This duplication is here because it might be a transobject. hash = oldhash.dup.to_hash - if hash.include?(:parent) - hash.delete(:parent) + if hash.include?(:resource) + hash.delete(:resource) end namevar = self.class.namevar @@ -573,9 +573,9 @@ class Puppet::Type return nil end - # Add parent information at creation time, so it's available + # Add resource information at creation time, so it's available # during validation. - options[:parent] = self + options[:resource] = self begin # make sure the parameter doesn't have any errors return @parameters[name] = klass.new(options) diff --git a/lib/puppet/metatype/metaparams.rb b/lib/puppet/metatype/metaparams.rb index 37a712c4d..ede201ff4 100644 --- a/lib/puppet/metatype/metaparams.rb +++ b/lib/puppet/metatype/metaparams.rb @@ -16,8 +16,8 @@ class Puppet::Type newvalues(:true, :false) munge do |value| case value - when true, :true, "true": @parent.noop = true - when false, :false, "false": @parent.noop = false + when true, :true, "true": @resource.noop = true + when false, :false, "false": @resource.noop = false end end end @@ -59,7 +59,7 @@ class Puppet::Type munge do |args| # If they've specified all, collect all known properties if args == :all - args = @parent.class.properties.collect do |property| + args = @resource.class.properties.collect do |property| property.name end end @@ -68,7 +68,7 @@ class Puppet::Type args = [args] end - unless defined? @parent + unless defined? @resource self.devfail "No parent for %s, %s?" % [self.class, self.name] end @@ -77,14 +77,14 @@ class Puppet::Type unless property.is_a?(Symbol) property = property.intern end - next if @parent.propertydefined?(property) + next if @resource.propertydefined?(property) - unless propertyklass = @parent.class.validproperty?(property) + unless propertyklass = @resource.class.validproperty?(property) raise Puppet::Error, "%s is not a valid attribute for %s" % [property, self.class.name] end next unless propertyklass.checkable? - @parent.newattr(property) + @resource.newattr(property) } end end @@ -191,20 +191,20 @@ class Puppet::Type unless aliases.is_a?(Array) aliases = [aliases] end - @parent.info "Adding aliases %s" % aliases.collect { |a| + @resource.info "Adding aliases %s" % aliases.collect { |a| a.inspect }.join(", ") aliases.each do |other| - if obj = @parent.class[other] - unless obj == @parent + if obj = @resource.class[other] + unless obj == @resource self.fail( "%s can not create alias %s: object already exists" % - [@parent.title, other] + [@resource.title, other] ) end next end - @parent.class.alias(other, @parent) + @resource.class.alias(other, @resource) end end end @@ -227,7 +227,7 @@ class Puppet::Type tags = [tags] unless tags.is_a? Array tags.each do |tag| - @parent.tag(tag) + @resource.tag(tag) end end end @@ -244,7 +244,7 @@ class Puppet::Type end def munge(rels) - @parent.store_relationship(self.class.name, rels) + @resource.store_relationship(self.class.name, rels) end # Create edges from each of our relationships. :in @@ -278,9 +278,9 @@ class Puppet::Type # for futher info on this. if self.class.direction == :in source = object - target = @parent + target = @resource else - source = @parent + source = @resource target = object end diff --git a/lib/puppet/metatype/providers.rb b/lib/puppet/metatype/providers.rb index a130fc186..a4dd402a0 100644 --- a/lib/puppet/metatype/providers.rb +++ b/lib/puppet/metatype/providers.rb @@ -195,12 +195,12 @@ class Puppet::Type end defaultto { - @parent.class.defaultprovider.name + @resource.class.defaultprovider.name } validate do |value| value = value[0] if value.is_a? Array - if provider = @parent.class.provider(value) + if provider = @resource.class.provider(value) unless provider.suitable? raise ArgumentError, "Provider '%s' is not functional on this platform" % @@ -208,7 +208,7 @@ class Puppet::Type end else raise ArgumentError, "Invalid %s provider '%s'" % - [@parent.class.name, value] + [@resource.class.name, value] end end @@ -217,7 +217,7 @@ class Puppet::Type if provider.is_a? String provider = provider.intern end - @parent.provider = provider + @resource.provider = provider provider end end.parenttype = self diff --git a/lib/puppet/parameter.rb b/lib/puppet/parameter.rb index 6184b8fd4..55fa2d508 100644 --- a/lib/puppet/parameter.rb +++ b/lib/puppet/parameter.rb @@ -240,6 +240,8 @@ class Puppet::Parameter < Puppet::Element # ParamHandler class. proxymethods("required?", "isnamevar?") + attr_accessor :resource + # LAK 2007-05-09: Keep the @parent around for backward compatibility. attr_accessor :parent attr_reader :shadow @@ -257,12 +259,12 @@ class Puppet::Parameter < Puppet::Element error = type.new(args.join(" ")) - if defined? @parent and @parent and @parent.line - error.line = @parent.line + if defined? @resource and @resource and @resource.line + error.line = @resource.line end - if defined? @parent and @parent and @parent.file - error.file = @parent.file + if defined? @resource and @resource and @resource.file + error.file = @resource.file end raise error @@ -271,13 +273,16 @@ class Puppet::Parameter < Puppet::Element # Basic parameter initialization. def initialize(options = {}) options = symbolize_options(options) - if parent = options[:parent] - self.parent = parent - options.delete(:parent) + if resource = options[:resource] + self.resource = resource + options.delete(:resource) else - raise Puppet::DevError, "No parent set for %s" % self.class.name + raise Puppet::DevError, "No resource set for %s" % self.class.name end + # LAK 2007-05-09: Keep the @parent around for backward compatibility. + #@parent = @resource + if ! self.metaparam? and klass = Puppet::Type.metaparamclass(self.class.name) setup_shadow(klass) end @@ -285,15 +290,15 @@ class Puppet::Parameter < Puppet::Element set_options(options) end - # Log a message using the parent's log level. + # Log a message using the resource's log level. def log(msg) - unless @parent[:loglevel] - p @parent + unless @resource[:loglevel] + p @resource self.devfail "Parent %s has no loglevel" % - @parent.name + @resource.name end Puppet::Util::Log.create( - :level => @parent[:loglevel], + :level => @resource[:loglevel], :message => msg, :source => self ) @@ -317,16 +322,21 @@ class Puppet::Parameter < Puppet::Element unless defined? @noop @noop = false end - tmp = @noop || self.parent.noop || Puppet[:noop] || false + tmp = @noop || self.resource.noop || Puppet[:noop] || false #debug "noop is %s" % tmp return tmp end + def parent + puts caller + raise "called parent" + end + # return the full path to us, for logging and rollback; not currently # used def pathbuilder - if defined? @parent and @parent - return [@parent.pathbuilder, self.name] + if defined? @resource and @resource + return [@resource.pathbuilder, self.name] else return [self.name] end @@ -397,7 +407,7 @@ class Puppet::Parameter < Puppet::Element end def remove - @parent = nil + @resource = nil @shadow = nil end @@ -446,17 +456,17 @@ class Puppet::Parameter < Puppet::Element def inspect s = "Parameter(%s = %s" % [self.name, self.value || "nil"] - if defined? @parent - s += ", @parent = %s)" % @parent + if defined? @resource + s += ", @resource = %s)" % @resource else s += ")" end end - # Retrieve the parent's provider. Some types don't have providers, in which - # case we return the parent object itself. + # Retrieve the resource's provider. Some types don't have providers, in which + # case we return the resource object itself. def provider - @parent.provider || @parent + @resource.provider || @resource end # If there's a shadowing metaparam, instantiate it now. @@ -464,7 +474,7 @@ class Puppet::Parameter < Puppet::Element # same name as a metaparameter, and the metaparam will only be # stored as a shadow. def setup_shadow(klass) - @shadow = klass.new(:parent => self.parent) + @shadow = klass.new(:resource => self.resource) end def to_s diff --git a/lib/puppet/propertychange.rb b/lib/puppet/propertychange.rb index 53d8ceec4..ff221cd52 100644 --- a/lib/puppet/propertychange.rb +++ b/lib/puppet/propertychange.rb @@ -42,7 +42,7 @@ module Puppet @property.warning("Property '%s' returned invalid event '%s'; resetting to default" % [@property.class,event]) - event = @property.parent.class.name.id2name + "_changed" + event = @property.resource.class.name.id2name + "_changed" end Puppet::Event.new( @@ -129,7 +129,7 @@ module Puppet end def source - self.proxy || @property.parent + self.proxy || @property.resource end def to_s diff --git a/lib/puppet/provider/parsedfile.rb b/lib/puppet/provider/parsedfile.rb index 334768d6b..295c69168 100755 --- a/lib/puppet/provider/parsedfile.rb +++ b/lib/puppet/provider/parsedfile.rb @@ -318,7 +318,7 @@ class Puppet::Provider::ParsedFile < Puppet::Provider # If the target isn't set, then this is our first modification, so # mark it for flushing. unless @property_hash[:target] - @property_hash[:target] = @model[:target] || self.class.default_target + @property_hash[:target] = @model.should(:target) || self.class.default_target self.class.modified(@property_hash[:target]) end @property_hash[:name] ||= @model.name diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index a276d138c..86d4bfc6e 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -129,7 +129,7 @@ class Transaction # Find all of the changed resources. def changed? @changes.find_all { |change| change.changed }.collect { |change| - change.property.parent + change.property.resource }.uniq end @@ -573,7 +573,7 @@ class Transaction # Now check to see if there are any events for this child. # Kind of hackish, since going backwards goes a change at a # time, not a child at a time. - trigger(change.property.parent) + trigger(change.property.resource) # And return the events for collection events diff --git a/lib/puppet/type/cron.rb b/lib/puppet/type/cron.rb index 3c72224e0..cf4f7cc33 100755 --- a/lib/puppet/type/cron.rb +++ b/lib/puppet/type/cron.rb @@ -182,7 +182,7 @@ Puppet::Type.newtype(:cron) do end # Somewhat uniquely, this property does not actually change anything -- it - # just calls +@parent.sync+, which writes out the whole cron tab for + # just calls +@resource.sync+, which writes out the whole cron tab for # the user in question. There is no real way to change individual cron # jobs without rewriting the entire cron file. # @@ -338,8 +338,8 @@ Puppet::Type.newtype(:cron) do Other providers default accordingly." defaultto { - if provider.is_a?(@parent.class.provider(:crontab)) - if val = @parent.should(:user) + if provider.is_a?(@resource.class.provider(:crontab)) + if val = @resource.should(:user) val else raise ArgumentError, diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb index 9097f6179..79c9ff999 100755 --- a/lib/puppet/type/exec.rb +++ b/lib/puppet/type/exec.rb @@ -87,7 +87,7 @@ module Puppet def retrieve # Default to somethinng - if @parent.check + if @resource.check return :notrun else return self.should @@ -99,25 +99,25 @@ module Puppet olddir = nil # We need a dir to change to, even if it's just the cwd - dir = self.parent[:cwd] || Dir.pwd + dir = self.resource[:cwd] || Dir.pwd event = :executed_command begin - @output, status = @parent.run(self.parent[:command]) + @output, status = @resource.run(self.resource[:command]) rescue Timeout::Error self.fail "Command exceeded timeout" % value.inspect end - loglevel = @parent[:loglevel] + loglevel = @resource[:loglevel] if status.exitstatus.to_s != self.should.to_s self.fail("%s returned %s instead of %s" % - [self.parent[:command], status.exitstatus, self.should.to_s]) + [self.resource[:command], status.exitstatus, self.should.to_s]) end - if log = @parent[:logoutput] + if log = @resource[:logoutput] if log == :true - log = @parent[:loglevel] + log = @resource[:loglevel] end unless log == :false @output.split(/\n/).each { |line| @@ -213,7 +213,7 @@ module Puppet for refreshing." validate do |command| - @parent.validatecmd(command) + @resource.validatecmd(command) end end @@ -342,14 +342,14 @@ module Puppet cmds = [cmds] unless cmds.is_a? Array cmds.each do |cmd| - @parent.validatecmd(cmd) + @resource.validatecmd(cmd) end end # Return true if the command does not return 0. def check(value) begin - output, status = @parent.run(value, true) + output, status = @resource.run(value, true) rescue Timeout::Error err "Check %s exceeded timeout" % value.inspect return false @@ -378,14 +378,14 @@ module Puppet cmds = [cmds] unless cmds.is_a? Array cmds.each do |cmd| - @parent.validatecmd(cmd) + @resource.validatecmd(cmd) end end # Return true if the command returns 0. def check(value) begin - output, status = @parent.run(value, true) + output, status = @resource.run(value, true) rescue Timeout::Error err "Check %s exceeded timeout" % value.inspect return false diff --git a/lib/puppet/type/group.rb b/lib/puppet/type/group.rb index 89c0871c3..5e82140e7 100755 --- a/lib/puppet/type/group.rb +++ b/lib/puppet/type/group.rb @@ -40,7 +40,7 @@ module Puppet # If they're talking about the thing at all, they generally want to # say it should exist. defaultto do - if @parent.managed? + if @resource.managed? :present else nil diff --git a/lib/puppet/type/host.rb b/lib/puppet/type/host.rb index 0d3013dbd..6ff02c155 100755 --- a/lib/puppet/type/host.rb +++ b/lib/puppet/type/host.rb @@ -68,8 +68,8 @@ module Puppet desc "The file in which to store service information. Only used by those providers that write to disk (i.e., not NetInfo)." - defaultto { if @parent.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile) - @parent.class.defaultprovider.default_target + defaultto { if @resource.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile) + @resource.class.defaultprovider.default_target else nil end diff --git a/lib/puppet/type/mount.rb b/lib/puppet/type/mount.rb index e43de0f7b..dd70f87a6 100755 --- a/lib/puppet/type/mount.rb +++ b/lib/puppet/type/mount.rb @@ -58,8 +58,8 @@ module Puppet def syncothers # We have to flush any changes to disk. - currentvalues = @parent.retrieve - oos = @parent.send(:properties).find_all do |prop| + currentvalues = @resource.retrieve + oos = @resource.send(:properties).find_all do |prop| unless currentvalues.include?(prop) raise Puppet::DevError, "Parent has property %s but it doesn't appear in the current vallues", @@ -72,7 +72,7 @@ module Puppet end end.each { |prop| prop.sync }.length if oos > 0 - @parent.flush + @resource.flush end end end @@ -93,7 +93,7 @@ module Puppet # Default to the device but with "dsk" replaced with "rdsk". defaultto do if Facter["operatingsystem"].value == "Solaris" - device = @parent.value(:device) + device = @resource.value(:device) if device =~ %r{/dsk/} device.sub(%r{/dsk/}, "/rdsk/") else @@ -133,8 +133,8 @@ module Puppet desc "The file in which to store the mount table. Only used by those providers that write to disk (i.e., not NetInfo)." - defaultto { if @parent.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile) - @parent.class.defaultprovider.default_target + defaultto { if @resource.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile) + @resource.class.defaultprovider.default_target else nil end @@ -152,7 +152,7 @@ module Puppet def value=(value) warning "'path' is deprecated for mounts. Please use 'name'." - @parent[:name] = value + @resource[:name] = value super end end diff --git a/lib/puppet/type/notify.rb b/lib/puppet/type/notify.rb index 599197f76..2d8e2e4fc 100644 --- a/lib/puppet/type/notify.rb +++ b/lib/puppet/type/notify.rb @@ -9,11 +9,11 @@ module Puppet newproperty(:message) do desc "The message to be sent to the log." def sync - case @parent["withpath"] + case @resource["withpath"] when :true: log(self.should) else - Puppet.send(@parent[:loglevel], self.should) + Puppet.send(@resource[:loglevel], self.should) end return end @@ -26,7 +26,7 @@ module Puppet false end - defaultto { @parent[:name] } + defaultto { @resource[:name] } end newparam(:withpath) do diff --git a/lib/puppet/type/package.rb b/lib/puppet/type/package.rb index 244a79072..68b1315ec 100644 --- a/lib/puppet/type/package.rb +++ b/lib/puppet/type/package.rb @@ -59,7 +59,7 @@ module Puppet unless provider.purgeable? self.fail( "Package provider %s does not purging" % - @parent[:provider] + @resource[:provider] ) end provider.purge @@ -72,7 +72,7 @@ module Puppet unless provider.upgradeable? self.fail( "Package provider %s does not support specifying 'latest'" % - @parent[:provider] + @resource[:provider] ) end @@ -97,7 +97,7 @@ module Puppet unless provider.versionable? self.fail( "Package provider %s does not support specifying versions" % - @parent[:provider] + @resource[:provider] ) end begin @@ -140,7 +140,7 @@ module Puppet unless provider.respond_to?(:latest) self.fail( "Package type %s does not support specifying 'latest'" % - @parent[:provider] + @resource[:provider] ) end @@ -165,7 +165,7 @@ module Puppet return true else self.debug "is is %s, latest %s is %s" % - [is.inspect, @parent.name, @latest.inspect] + [is.inspect, @resource.name, @latest.inspect] end when :absent if is == :absent @@ -181,7 +181,7 @@ module Puppet # This retrieves the current state. LAK: I think this method is unused. def retrieve - return @parent.retrieve + return @resource.retrieve end # Provide a bit more information when logging upgrades. @@ -258,9 +258,9 @@ module Puppet munge do |value| warning "'type' is deprecated; use 'provider' instead" - @parent[:provider] = value + @resource[:provider] = value - @parent[:provider] + @resource[:provider] end end diff --git a/lib/puppet/type/parsedtype.rb b/lib/puppet/type/parsedtype.rb index 1c5870d75..ee02f16ad 100755 --- a/lib/puppet/type/parsedtype.rb +++ b/lib/puppet/type/parsedtype.rb @@ -52,7 +52,7 @@ module Puppet # just collect our current state. Note that this method is not called # during a transaction, since transactions call the parent object method. def retrieve - return @parent.retrieve + return @resource.retrieve end # All this does is return an event; all of the work gets done @@ -63,12 +63,12 @@ module Puppet else if self.class.name == :ensure if self.should == :absent - return (@parent.class.name.to_s + "_removed").intern + return (@resource.class.name.to_s + "_removed").intern else - return (@parent.class.name.to_s + "_created").intern + return (@resource.class.name.to_s + "_created").intern end else - return (@parent.class.name.to_s + "_changed").intern + return (@resource.class.name.to_s + "_changed").intern end end end @@ -158,7 +158,7 @@ module Puppet end defaultto do - if @parent.managed? + if @resource.managed? :present else nil diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb index aaee68ab9..62524f37b 100644 --- a/lib/puppet/type/pfile.rb +++ b/lib/puppet/type/pfile.rb @@ -96,16 +96,16 @@ module Puppet # we have to do it after all of the objects # have been instantiated. if bucketobj = Puppet::Type.type(:filebucket)[value] - @parent.bucket = bucketobj.bucket + @resource.bucket = bucketobj.bucket bucketobj.title else # Set it to the string; finish() turns it into a # filebucket. - @parent.bucket = value + @resource.bucket = value value end when Puppet::Network::Client.client(:Dipper): - @parent.bucket = value + @resource.bucket = value value.name else self.fail "Invalid backup type %s" % @@ -669,12 +669,12 @@ module Puppet # path names, rather than including the full parent's title each # time. def pathbuilder - if defined? @parent + if defined? @resource # We only need to behave specially when our parent is also # a file - if @parent.is_a?(self.class) + if @resource.is_a?(self.class) # Remove the parent file name - list = @parent.pathbuilder + list = @resource.pathbuilder list.pop # remove the parent's path info return list << self.ref else diff --git a/lib/puppet/type/pfile/checksum.rb b/lib/puppet/type/pfile/checksum.rb index 68e1b59e2..6caef23ca 100755 --- a/lib/puppet/type/pfile/checksum.rb +++ b/lib/puppet/type/pfile/checksum.rb @@ -49,7 +49,7 @@ module Puppet cache(type, sum) return type else - if FileTest.directory?(@parent[:path]) + if FileTest.directory?(@resource[:path]) return :time else return symbolize(value) @@ -64,10 +64,10 @@ module Puppet raise ArgumentError, "A type must be specified to cache a checksum" end type = symbolize(type) - unless state = @parent.cached(:checksums) + unless state = @resource.cached(:checksums) self.debug "Initializing checksum hash" state = {} - @parent.cache(:checksums, state) + @resource.cache(:checksums, state) end if sum @@ -125,16 +125,16 @@ module Puppet # Retrieve the cached sum def getcachedsum hash = nil - unless hash = @parent.cached(:checksums) + unless hash = @resource.cached(:checksums) hash = {} - @parent.cache(:checksums, hash) + @resource.cache(:checksums, hash) end sumtype = self.should if hash.include?(sumtype) #self.notice "Found checksum %s for %s" % - # [hash[sumtype] ,@parent[:path]] + # [hash[sumtype] ,@resource[:path]] sum = hash[sumtype] unless sum =~ /^\{\w+\}/ @@ -146,7 +146,7 @@ module Puppet return :nosum else #self.notice "Found checksum for %s but not of type %s" % - # [@parent[:path],sumtype] + # [@resource[:path],sumtype] return :nosum end end @@ -158,13 +158,13 @@ module Puppet checktype = checktype.intern if checktype.is_a? String case checktype when :md5, :md5lite: - if ! FileTest.file?(@parent[:path]) - @parent.debug "Cannot MD5 sum %s; using mtime" % - [@parent.stat.ftype] - sum = @parent.stat.mtime.to_s + if ! FileTest.file?(@resource[:path]) + @resource.debug "Cannot MD5 sum %s; using mtime" % + [@resource.stat.ftype] + sum = @resource.stat.mtime.to_s else begin - File.open(@parent[:path]) { |file| + File.open(@resource[:path]) { |file| text = nil case checktype when :md5 @@ -175,7 +175,7 @@ module Puppet if text.nil? self.debug "Not checksumming empty file %s" % - @parent[:path] + @resource[:path] sum = 0 else sum = Digest::MD5.hexdigest(text) @@ -183,20 +183,20 @@ module Puppet } rescue Errno::EACCES => detail self.notice "Cannot checksum %s: permission denied" % - @parent[:path] - @parent.delete(self.class.name) + @resource[:path] + @resource.delete(self.class.name) rescue => detail self.notice "Cannot checksum: %s" % detail - @parent.delete(self.class.name) + @resource.delete(self.class.name) end end when :timestamp, :mtime: - sum = @parent.stat.mtime.to_s - #sum = File.stat(@parent[:path]).mtime.to_s + sum = @resource.stat.mtime.to_s + #sum = File.stat(@resource[:path]).mtime.to_s when :time: - sum = @parent.stat.ctime.to_s - #sum = File.stat(@parent[:path]).ctime.to_s + sum = @resource.stat.ctime.to_s + #sum = File.stat(@resource[:path]).ctime.to_s else raise Puppet::Error, "Invalid sum type %s" % checktype end @@ -211,24 +211,24 @@ module Puppet currentvalue = self.retrieve if currentvalue.nil? raise Puppet::Error, "Checksum state for %s is somehow nil" % - @parent.title + @resource.title end if self.insync?(currentvalue) self.debug "Checksum is already in sync" return nil end - # @parent.debug "%s(%s): after refresh, is '%s'" % - # [self.class.name,@parent.name,@is] + # @resource.debug "%s(%s): after refresh, is '%s'" % + # [self.class.name,@resource.name,@is] # If we still can't retrieve a checksum, it means that # the file still doesn't exist if currentvalue == :absent # if they're copying, then we won't worry about the file # not existing yet - unless @parent.property(:source) + unless @resource.property(:source) self.warning("File %s does not exist -- cannot checksum" % - @parent[:path] + @resource[:path] ) end return nil @@ -265,13 +265,13 @@ module Puppet end stat = nil - unless stat = @parent.stat + unless stat = @resource.stat return :absent end - if stat.ftype == "link" and @parent[:links] != :follow + if stat.ftype == "link" and @resource[:links] != :follow self.debug "Not checksumming symlink" - # @parent.delete(:checksum) + # @resource.delete(:checksum) return currentvalue end @@ -287,7 +287,7 @@ module Puppet self.updatesum(currentvalue) end - # @parent.debug "checksum state is %s" % self.is + # @resource.debug "checksum state is %s" % self.is return currentvalue end @@ -296,7 +296,7 @@ module Puppet result = false if newvalue.is_a?(Symbol) - raise Puppet::Error, "%s has invalid checksum" % @parent.title + raise Puppet::Error, "%s has invalid checksum" % @resource.title end # if we're replacing, vs. updating @@ -304,7 +304,7 @@ module Puppet # unless defined? @should # raise Puppet::Error.new( # ("@should is not initialized for %s, even though we " + - # "found a checksum") % @parent[:path] + # "found a checksum") % @resource[:path] # ) # end @@ -313,12 +313,12 @@ module Puppet end self.debug "Replacing %s checksum %s with %s" % - [@parent.title, sum, newvalue] - # @parent.debug "currentvalue: %s; @should: %s" % + [@resource.title, sum, newvalue] + # @resource.debug "currentvalue: %s; @should: %s" % # [newvalue,@should] result = true else - @parent.debug "Creating checksum %s" % newvalue + @resource.debug "Creating checksum %s" % newvalue result = false end diff --git a/lib/puppet/type/pfile/content.rb b/lib/puppet/type/pfile/content.rb index 9b8be0d68..7892ed522 100755 --- a/lib/puppet/type/pfile/content.rb +++ b/lib/puppet/type/pfile/content.rb @@ -34,35 +34,35 @@ module Puppet # but I really don't feel like dealing with the complexity right now. def retrieve stat = nil - unless stat = @parent.stat + unless stat = @resource.stat return :absent end - if stat.ftype == "link" and @parent[:links] == :ignore + if stat.ftype == "link" and @resource[:links] == :ignore return self.should end # Don't even try to manage the content on directories - if stat.ftype == "directory" and @parent[:links] == :ignore - @parent.delete(:content) + if stat.ftype == "directory" and @resource[:links] == :ignore + @resource.delete(:content) return nil end begin - currentvalue = File.read(@parent[:path]) + currentvalue = File.read(@resource[:path]) return currentvalue rescue => detail raise Puppet::Error, "Could not read %s: %s" % - [@parent.title, detail] + [@resource.title, detail] end end # Just write our content out to disk. def sync - return_event = @parent.stat ? :file_changed : :file_created + return_event = @resource.stat ? :file_changed : :file_created - @parent.write { |f| f.print self.should } + @resource.write { |f| f.print self.should } return return_event end diff --git a/lib/puppet/type/pfile/ensure.rb b/lib/puppet/type/pfile/ensure.rb index afd2baae3..c5d53de06 100755 --- a/lib/puppet/type/pfile/ensure.rb +++ b/lib/puppet/type/pfile/ensure.rb @@ -36,18 +36,18 @@ module Puppet nodefault newvalue(:absent) do - File.unlink(@parent[:path]) + File.unlink(@resource[:path]) end aliasvalue(:false, :absent) newvalue(:file) do # Make sure we're not managing the content some other way - if property = (@parent.property(:content) || @parent.property(:source)) + if property = (@resource.property(:content) || @resource.property(:source)) property.sync else - @parent.write(false) { |f| f.flush } - mode = @parent.should(:mode) + @resource.write(false) { |f| f.flush } + mode = @resource.should(:mode) end return :file_created end @@ -60,30 +60,30 @@ module Puppet end newvalue(:directory) do - mode = @parent.should(:mode) - parent = File.dirname(@parent[:path]) + mode = @resource.should(:mode) + parent = File.dirname(@resource[:path]) unless FileTest.exists? parent raise Puppet::Error, "Cannot create %s; parent directory %s does not exist" % - [@parent[:path], parent] + [@resource[:path], parent] end - @parent.write_if_writable(parent) do + @resource.write_if_writable(parent) do if mode Puppet::Util.withumask(000) do - Dir.mkdir(@parent[:path],mode) + Dir.mkdir(@resource[:path],mode) end else - Dir.mkdir(@parent[:path]) + Dir.mkdir(@resource[:path]) end end - @parent.send(:property_fix) - @parent.setchecksum + @resource.send(:property_fix) + @resource.setchecksum return :directory_created end newvalue(:link) do - if property = @parent.property(:target) + if property = @resource.property(:target) property.retrieve return property.mklink @@ -103,13 +103,13 @@ module Puppet return value if value.is_a? Symbol - @parent[:target] = value + @resource[:target] = value return :link end def change_to_s(currentvalue, newvalue) - if property = (@parent.property(:content) || @parent.property(:source)) and ! property.insync?(currentvalue) + if property = (@resource.property(:content) || @resource.property(:source)) and ! property.insync?(currentvalue) currentvalue = property.retrieve return property.change_to_s(property.retrieve, property.should) @@ -120,16 +120,16 @@ module Puppet # Check that we can actually create anything def check - basedir = File.dirname(@parent[:path]) + basedir = File.dirname(@resource[:path]) if ! FileTest.exists?(basedir) raise Puppet::Error, "Can not create %s; parent directory does not exist" % - @parent.title + @resource.title elsif ! FileTest.directory?(basedir) raise Puppet::Error, "Can not create %s; %s is not a directory" % - [@parent.title, dirname] + [@resource.title, dirname] end end @@ -148,7 +148,7 @@ module Puppet end def retrieve - if stat = @parent.stat(false) + if stat = @resource.stat(false) return stat.ftype.intern else if self.should == :false @@ -160,7 +160,7 @@ module Puppet end def sync - @parent.remove_existing(self.should) + @resource.remove_existing(self.should) if self.should == :absent return :file_removed end diff --git a/lib/puppet/type/pfile/group.rb b/lib/puppet/type/pfile/group.rb index 6606f3322..d12a418cc 100755 --- a/lib/puppet/type/pfile/group.rb +++ b/lib/puppet/type/pfile/group.rb @@ -56,14 +56,14 @@ module Puppet end end end - stat = @parent.stat(false) + stat = @resource.stat(false) unless stat return :absent end # Set our method appropriately, depending on links. - if stat.ftype == "link" and @parent[:links] != :follow + if stat.ftype == "link" and @resource[:links] != :follow @method = :lchown else @method = :chown @@ -89,13 +89,13 @@ module Puppet # we'll just let it fail, but we should probably set things up so # that users get warned if they try to change to an unacceptable group. def sync - unless @parent.stat(false) - stat = @parent.stat(true) + unless @resource.stat(false) + stat = @resource.stat(true) currentvalue = self.retrieve unless stat self.debug "File '%s' does not exist; cannot chgrp" % - @parent[:path] + @resource[:path] return nil end end @@ -107,10 +107,10 @@ module Puppet begin # set owner to nil so it's ignored - File.send(@method,nil,gid,@parent[:path]) + File.send(@method,nil,gid,@resource[:path]) rescue => detail error = Puppet::Error.new( "failed to chgrp %s to %s: %s" % - [@parent[:path], self.should, detail.message]) + [@resource[:path], self.should, detail.message]) raise error end return :file_changed diff --git a/lib/puppet/type/pfile/mode.rb b/lib/puppet/type/pfile/mode.rb index ceb4c0d56..08dee9903 100755 --- a/lib/puppet/type/pfile/mode.rb +++ b/lib/puppet/type/pfile/mode.rb @@ -62,7 +62,7 @@ module Puppet # If we're a directory, we need to be executable for all cases # that are readable. This should probably be selectable, but eh. def dirmask(value) - if FileTest.directory?(@parent[:path]) + if FileTest.directory?(@resource[:path]) if value & 0400 != 0 value |= 0100 end @@ -78,7 +78,7 @@ module Puppet end def insync?(currentvalue) - if stat = @parent.stat and stat.ftype == "link" and @parent[:links] != :follow + if stat = @resource.stat and stat.ftype == "link" and @resource[:links] != :follow self.debug "Not managing symlink mode" return true else @@ -90,7 +90,7 @@ module Puppet # If we're not following links and we're a link, then we just turn # off mode management entirely. - if stat = @parent.stat(false) + if stat = @resource.stat(false) unless defined? @fixed if defined? @should and @should @should = @should.collect { |s| self.dirmask(s) } @@ -103,8 +103,8 @@ module Puppet end def sync - unless @parent.stat(false) - stat = @parent.stat(true) + unless @resource.stat(false) + stat = @resource.stat(true) unless stat self.debug "File does not exist; cannot set mode" @@ -120,10 +120,10 @@ module Puppet end begin - File.chmod(mode, @parent[:path]) + File.chmod(mode, @resource[:path]) rescue => detail error = Puppet::Error.new("failed to chmod %s: %s" % - [@parent[:path], detail.message]) + [@resource[:path], detail.message]) error.set_backtrace detail.backtrace raise error end diff --git a/lib/puppet/type/pfile/owner.rb b/lib/puppet/type/pfile/owner.rb index d88e9d04c..8b9687531 100755 --- a/lib/puppet/type/pfile/owner.rb +++ b/lib/puppet/type/pfile/owner.rb @@ -97,12 +97,12 @@ module Puppet end end - unless stat = @parent.stat(false) + unless stat = @resource.stat(false) return :absent end # Set our method appropriately, depending on links. - if stat.ftype == "link" and @parent[:links] != :follow + if stat.ftype == "link" and @resource[:links] != :follow @method = :lchown else @method = :chown @@ -125,7 +125,7 @@ module Puppet unless Puppet::Util::SUIDManager.uid == 0 unless defined? @@notifieduid self.notice "Cannot manage ownership unless running as root" - #@parent.delete(self.name) + #@resource.delete(self.name) @@notifieduid = true end return nil @@ -147,8 +147,8 @@ module Puppet return nil end - unless @parent.stat(false) - unless @parent.stat(true) + unless @resource.stat(false) + unless @resource.stat(true) self.debug "File does not exist; cannot set owner" return nil end @@ -156,7 +156,7 @@ module Puppet end begin - File.send(@method, user, nil, @parent[:path]) + File.send(@method, user, nil, @resource[:path]) rescue => detail raise Puppet::Error, "Failed to set owner to '%s': %s" % [user, detail] diff --git a/lib/puppet/type/pfile/source.rb b/lib/puppet/type/pfile/source.rb index d8fe47fee..e186047d0 100755 --- a/lib/puppet/type/pfile/source.rb +++ b/lib/puppet/type/pfile/source.rb @@ -46,7 +46,7 @@ module Puppet uncheckable validate do |source| - unless @parent.uri2obj(source) + unless @resource.uri2obj(source) raise Puppet::Error, "Invalid source %s" % source end end @@ -62,7 +62,7 @@ module Puppet def change_to_s(currentvalue, newvalue) # newvalue = "{md5}" + @stats[:checksum] - if @parent.property(:ensure).retrieve == :absent + if @resource.property(:ensure).retrieve == :absent return "creating from source %s with contents %s" % [@source, @stats[:checksum]] else return "replacing from source %s with contents %s" % [@source, @stats[:checksum]] @@ -79,11 +79,11 @@ module Puppet # Ask the file server to describe our file. def describe(source) - sourceobj, path = @parent.uri2obj(source) + sourceobj, path = @resource.uri2obj(source) server = sourceobj.server begin - desc = server.describe(path, @parent[:links]) + desc = server.describe(path, @resource[:links]) rescue Puppet::Network::XMLRPCClientError => detail self.err "Could not describe %s: %s" % [path, detail] @@ -107,7 +107,7 @@ module Puppet args.delete(:owner) end - if args.empty? or (args[:type] == "link" and @parent[:links] == :ignore) + if args.empty? or (args[:type] == "link" and @resource[:links] == :ignore) return nil else return args @@ -137,13 +137,12 @@ module Puppet end #FIXARB: Inefficient? Needed to call retrieve on parent's ensure and checksum - parentensure = @parent.property(:ensure).retrieve - if parentensure != :absent and ! @parent.replace? + parentensure = @resource.property(:ensure).retrieve + if parentensure != :absent and ! @resource.replace? return true end # Now, we just check to see if the checksums are the same - parentchecksum = @parent.property(:checksum).retrieve - a = (!parentchecksum.nil? and (parentchecksum == @stats[:checksum])) + parentchecksum = @resource.property(:checksum).retrieve return (!parentchecksum.nil? and (parentchecksum == @stats[:checksum])) end @@ -178,8 +177,8 @@ module Puppet case @stats[:type] when "directory", "file": - unless @parent.deleting? - @parent[:ensure] = @stats[:type] + unless @resource.deleting? + @resource[:ensure] = @stats[:type] end else self.info @stats.inspect @@ -196,8 +195,8 @@ module Puppet # was the stat already specified, or should the value # be inherited from the source? - unless @parent.argument?(stat) - @parent[stat] = value + unless @resource.argument?(stat) + @resource[stat] = value end } @@ -215,25 +214,25 @@ module Puppet checks = (pinparams + [:ensure]) checks.delete(:checksum) - @parent[:check] = checks - unless @parent.property(:checksum) - @parent[:checksum] = :md5 + @resource[:check] = checks + unless @resource.property(:checksum) + @resource[:checksum] = :md5 end end def sync unless @stats[:type] == "file" #if @stats[:type] == "directory" - #[@parent.name, @should.inspect] + #[@resource.name, @should.inspect] #end raise Puppet::DevError, "Got told to copy non-file %s" % - @parent[:path] + @resource[:path] end - sourceobj, path = @parent.uri2obj(@source) + sourceobj, path = @resource.uri2obj(@source) begin - contents = sourceobj.server.retrieve(path, @parent[:links]) + contents = sourceobj.server.retrieve(path, @resource[:links]) rescue Puppet::Network::XMLRPCClientError => detail self.err "Could not retrieve %s: %s" % [path, detail] @@ -250,9 +249,9 @@ module Puppet self.notice "Could not retrieve contents for %s" % @source end - exists = File.exists?(@parent[:path]) + exists = File.exists?(@resource[:path]) - @parent.write { |f| f.print contents } + @resource.write { |f| f.print contents } if exists return :file_changed diff --git a/lib/puppet/type/pfile/target.rb b/lib/puppet/type/pfile/target.rb index 8913eb86f..be3481528 100644 --- a/lib/puppet/type/pfile/target.rb +++ b/lib/puppet/type/pfile/target.rb @@ -10,13 +10,13 @@ module Puppet # Anything else, basically newvalue(/./) do - if ! @parent.should(:ensure) - @parent[:ensure] = :link + if ! @resource.should(:ensure) + @resource[:ensure] = :link end # Only call mklink if ensure() didn't call us in the first place. - currentensure = @parent.property(:ensure).retrieve - if @parent.property(:ensure).insync?(currentensure) + currentensure = @resource.property(:ensure).retrieve + if @resource.property(:ensure).insync?(currentensure) mklink() end end @@ -27,21 +27,21 @@ module Puppet # Clean up any existing objects. The argument is just for logging, # it doesn't determine what's removed. - @parent.remove_existing(target) + @resource.remove_existing(target) - if FileTest.exists?(@parent[:path]) + if FileTest.exists?(@resource[:path]) raise Puppet::Error, "Could not remove existing file" end - Dir.chdir(File.dirname(@parent[:path])) do - Puppet::Util::SUIDManager.asuser(@parent.asuser()) do - mode = @parent.should(:mode) + Dir.chdir(File.dirname(@resource[:path])) do + Puppet::Util::SUIDManager.asuser(@resource.asuser()) do + mode = @resource.should(:mode) if mode Puppet::Util.withumask(000) do - File.symlink(target, @parent[:path]) + File.symlink(target, @resource[:path]) end else - File.symlink(target, @parent[:path]) + File.symlink(target, @resource[:path]) end end @@ -50,7 +50,7 @@ module Puppet end def insync?(currentvalue) - if [:nochange, :notlink].include?(self.should) or @parent.recurse? + if [:nochange, :notlink].include?(self.should) or @resource.recurse? return true else return super(currentvalue) @@ -59,9 +59,9 @@ module Puppet def retrieve - if stat = @parent.stat + if stat = @resource.stat if stat.ftype == "link" - return File.readlink(@parent[:path]) + return File.readlink(@resource[:path]) else return :notlink end diff --git a/lib/puppet/type/pfile/type.rb b/lib/puppet/type/pfile/type.rb index 4c2783c71..b0ceb4b23 100755 --- a/lib/puppet/type/pfile/type.rb +++ b/lib/puppet/type/pfile/type.rb @@ -9,7 +9,7 @@ module Puppet def retrieve currentvalue = :absent - if stat = @parent.stat(false) + if stat = @resource.stat(false) currentvalue = stat.ftype end # so this state is never marked out of sync diff --git a/lib/puppet/type/port.rb b/lib/puppet/type/port.rb index 7a0177c12..19c3dae76 100755 --- a/lib/puppet/type/port.rb +++ b/lib/puppet/type/port.rb @@ -90,8 +90,8 @@ require 'puppet/type/parsedtype' # munge do |value| # unless value == "absent" or value == :absent # # Add the :alias metaparam in addition to the property -# @parent.newmetaparam( -# @parent.class.metaparamclass(:alias), value +# @resource.newmetaparam( +# @resource.class.metaparamclass(:alias), value # ) # end # value @@ -102,8 +102,8 @@ require 'puppet/type/parsedtype' # desc "The file in which to store service information. Only used by # those providers that write to disk (i.e., not NetInfo)." # -# defaultto { if @parent.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile) -# @parent.class.defaultprovider.default_target +# defaultto { if @resource.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile) +# @resource.class.defaultprovider.default_target # else # nil # end diff --git a/lib/puppet/type/property.rb b/lib/puppet/type/property.rb index 065da6452..7fbf33df0 100644 --- a/lib/puppet/type/property.rb +++ b/lib/puppet/type/property.rb @@ -153,7 +153,7 @@ class Property < Puppet::Parameter puts detail.backtrace end error = Puppet::Error.new("Could not set %s on %s: %s" % - [value, self.class.name, detail], @parent.line, @parent.file) + [value, self.class.name, detail], @resource.line, @resource.file) error.set_backtrace detail.backtrace raise error end @@ -202,13 +202,13 @@ class Property < Puppet::Parameter else if self.class.name == :ensure event = case self.should - when :present: (@parent.class.name.to_s + "_created").intern - when :absent: (@parent.class.name.to_s + "_removed").intern + when :present: (@resource.class.name.to_s + "_created").intern + when :absent: (@resource.class.name.to_s + "_removed").intern else - (@parent.class.name.to_s + "_changed").intern + (@resource.class.name.to_s + "_changed").intern end else - event = (@parent.class.name.to_s + "_changed").intern + event = (@resource.class.name.to_s + "_changed").intern end end end @@ -274,12 +274,12 @@ class Property < Puppet::Parameter # Send a log message. def log(msg) - unless @parent[:loglevel] + unless @resource[:loglevel] self.devfail "Parent %s has no loglevel" % - @parent.name + @resource.name end Puppet::Util::Log.create( - :level => @parent[:loglevel], + :level => @resource[:loglevel], :message => msg, :source => self ) @@ -298,8 +298,8 @@ class Property < Puppet::Parameter unless defined? @noop @noop = false end - if self.parent.respond_to?(:noop) - tmp = @noop || self.parent.noop || Puppet[:noop] || false + if self.resource.respond_to?(:noop) + tmp = @noop || self.resource.noop || Puppet[:noop] || false else tmp = @noop || Puppet[:noop] || false end @@ -328,7 +328,7 @@ class Property < Puppet::Parameter event, tmp = call_valuemethod(name, value) end unless call == :instead - if @parent.provider + if @resource.provider call_provider(value) else # They haven't provided a block, and our parent does not have @@ -349,7 +349,7 @@ class Property < Puppet::Parameter if defined? @should unless @should.is_a?(Array) self.devfail "should for %s on %s is not an array" % - [self.class.name, @parent.name] + [self.class.name, @resource.name] end return @should[0] else @@ -412,8 +412,8 @@ class Property < Puppet::Parameter unless defined? @tags @tags = [] # This might not be true in testing - if @parent.respond_to? :tags - @tags = @parent.tags + if @resource.respond_to? :tags + @tags = @resource.tags end @tags << self.name end @@ -421,7 +421,7 @@ class Property < Puppet::Parameter end def to_s - return "%s(%s)" % [@parent.name,self.name] + return "%s(%s)" % [@resource.name,self.name] end # Provide a common hook for setting @should, just like params. @@ -436,25 +436,25 @@ class Property < Puppet::Parameter def self.defaultvalues newvalue(:present) do - if @parent.provider and @parent.provider.respond_to?(:create) - @parent.provider.create + if @resource.provider and @resource.provider.respond_to?(:create) + @resource.provider.create else - @parent.create + @resource.create end nil # return nil so the event is autogenerated end newvalue(:absent) do - if @parent.provider and @parent.provider.respond_to?(:destroy) - @parent.provider.destroy + if @resource.provider and @resource.provider.respond_to?(:destroy) + @resource.provider.destroy else - @parent.destroy + @resource.destroy end nil # return nil so the event is autogenerated end defaultto do - if @parent.managed? + if @resource.managed? :present else nil @@ -495,13 +495,13 @@ class Property < Puppet::Parameter # to get checked, which means that those other properties do not have # @is values set. This seems to be the source of quite a few bugs, # although they're mostly logging bugs, not functional ones. - if prov = @parent.provider and prov.respond_to?(:exists?) + if prov = @resource.provider and prov.respond_to?(:exists?) result = prov.exists? - elsif @parent.respond_to?(:exists?) - result = @parent.exists? + elsif @resource.respond_to?(:exists?) + result = @resource.exists? else raise Puppet::DevError, "No ability to determine if %s exists" % - @parent.class.name + @resource.class.name end if result return :present @@ -514,7 +514,7 @@ class Property < Puppet::Parameter # say it should exist. #defaultto :present defaultto do - if @parent.managed? + if @resource.managed? :present else nil diff --git a/lib/puppet/type/resources.rb b/lib/puppet/type/resources.rb index 5778460a5..b314c9441 100644 --- a/lib/puppet/type/resources.rb +++ b/lib/puppet/type/resources.rb @@ -31,10 +31,10 @@ Puppet::Type.newtype(:resources) do validate do |value| if [:true, true, "true"].include?(value) - unless @parent.resource_type.respond_to?(:list) - raise ArgumentError, "Purging resources of type %s is not supported, since they cannot be listed" % @parent[:name] + unless @resource.resource_type.respond_to?(:list) + raise ArgumentError, "Purging resources of type %s is not supported, since they cannot be listed" % @resource[:name] end - unless @parent.resource_type.validproperty?(:ensure) + unless @resource.resource_type.validproperty?(:ensure) raise ArgumentError, "Purging is only supported on types that accept 'ensure'" end end @@ -63,7 +63,7 @@ Puppet::Type.newtype(:resources) do end defaultto { - if @parent[:name] == "user" + if @resource[:name] == "user" 500 else nil diff --git a/lib/puppet/type/schedule.rb b/lib/puppet/type/schedule.rb index 3c3ce59a8..08bada3a7 100755 --- a/lib/puppet/type/schedule.rb +++ b/lib/puppet/type/schedule.rb @@ -249,7 +249,7 @@ module Puppet return false if value == :never value = self.value - case @parent[:periodmatch] + case @resource[:periodmatch] when :number method = @@methods[value] if method.is_a?(Proc) @@ -266,7 +266,7 @@ module Puppet # than the unit of time, we match. We divide the scale # by the repeat, so that we'll repeat that often within # the scale. - return (now.to_i - previous.to_i) >= (scale / @parent[:repeat]) + return (now.to_i - previous.to_i) >= (scale / @resource[:repeat]) end end end @@ -285,12 +285,12 @@ module Puppet # This implicitly assumes that 'periodmatch' is distance -- that # is, if there's no value, we assume it's a valid value. - return unless @parent[:periodmatch] + return unless @resource[:periodmatch] - if value != 1 and @parent[:periodmatch] != :distance + if value != 1 and @resource[:periodmatch] != :distance raise Puppet::Error, "Repeat must be 1 unless periodmatch is 'distance', not '%s'" % - @parent[:periodmatch] + @resource[:periodmatch] end end diff --git a/lib/puppet/type/service.rb b/lib/puppet/type/service.rb index 1f04c0246..73d4d70ce 100644 --- a/lib/puppet/type/service.rb +++ b/lib/puppet/type/service.rb @@ -37,7 +37,7 @@ module Puppet newvalue(:true, :event => :service_enabled) do unless provider.respond_to?(:enable) raise Puppet::Error, "Service %s does not support enabling" % - @parent.name + @resource.name end provider.enable end @@ -45,7 +45,7 @@ module Puppet newvalue(:false, :event => :service_disabled) do unless provider.respond_to?(:disable) raise Puppet::Error, "Service %s does not support enabling" % - @parent.name + @resource.name end provider.disable end @@ -53,7 +53,7 @@ module Puppet def retrieve unless provider.respond_to?(:enabled?) raise Puppet::Error, "Service %s does not support enabling" % - @parent.name + @resource.name end return provider.enabled? end @@ -67,15 +67,15 @@ module Puppet munge do |should| @runlevel = nil if should =~ /^\d+$/ - arity = @parent.method(:enable) + arity = @resource.method(:enable) if @runlevel and arity != 1 raise Puppet::Error, "Services on %s do not accept runlevel specs" % - @parent.type + @resource.type elsif arity != 0 raise Puppet::Error, "Services on %s must specify runlevels" % - @parent.type + @resource.type end @runlevel = should return :true @@ -133,7 +133,7 @@ module Puppet # self # end - if property = @parent.property(:enable) + if property = @resource.property(:enable) property.retrieve unless property.insync? property.sync @@ -152,8 +152,8 @@ module Puppet warning." munge do |value| - @parent.warning "'running' is deprecated; please use 'ensure'" - @parent[:ensure] = value + @resource.warning "'running' is deprecated; please use 'ensure'" + @resource[:ensure] = value end end @@ -188,7 +188,7 @@ module Puppet munge do |value| warning "'type' is deprecated; use 'provider' instead" - @parent[:provider] = value + @resource[:provider] = value end end @@ -211,11 +211,11 @@ module Puppet end if FileTest.exists?(path) unless FileTest.directory?(path) - @parent.debug "Search path %s is not a directory" % + @resource.debug "Search path %s is not a directory" % [path] end else - @parent.debug("Search path %s does not exist" % [path]) + @resource.debug("Search path %s does not exist" % [path]) end paths.delete(path) end @@ -236,7 +236,7 @@ module Puppet The pattern can be a simple string or any legal Ruby pattern." defaultto { - @parent[:binary] || @parent[:name] + @resource[:binary] || @resource[:name] } end newparam(:restart) do diff --git a/lib/puppet/type/sshkey.rb b/lib/puppet/type/sshkey.rb index 6abbf2de8..b047ff1cd 100755 --- a/lib/puppet/type/sshkey.rb +++ b/lib/puppet/type/sshkey.rb @@ -62,8 +62,8 @@ module Puppet desc "The file in which to store the mount table. Only used by those providers that write to disk (i.e., not NetInfo)." - defaultto { if @parent.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile) - @parent.class.defaultprovider.default_target + defaultto { if @resource.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile) + @resource.class.defaultprovider.default_target else nil end diff --git a/lib/puppet/type/tidy.rb b/lib/puppet/type/tidy.rb index 2750f3113..8b27948bb 100755 --- a/lib/puppet/type/tidy.rb +++ b/lib/puppet/type/tidy.rb @@ -30,10 +30,10 @@ module Puppet def change_to_s(currentvalue, newvalue) start = "Tidying" if @out.include?(:age) - start += ", older than %s seconds" % @parent.should(:age) + start += ", older than %s seconds" % @resource.should(:age) end if @out.include?(:size) - start += ", larger than %s bytes" % @parent.should(:size) + start += ", larger than %s bytes" % @resource.should(:size) end start @@ -49,7 +49,7 @@ module Puppet else @out = [] TATTRS.each do |param| - if property = @parent.property(param) + if property = @resource.property(param) self.debug "No is value for %s", [param] if is[property].nil? unless property.insync?(is[property]) @out << param @@ -67,16 +67,16 @@ module Puppet def retrieve stat = nil - unless stat = @parent.stat + unless stat = @resource.stat return { self => :absent} end - if stat.ftype == "directory" and ! @parent[:rmdirs] + if stat.ftype == "directory" and ! @resource[:rmdirs] return {self => :notidy} end allprops = TATTRS.inject({}) { |prophash, param| - if property = @parent.property(param) + if property = @resource.property(param) prophash[property] = property.assess(stat) end prophash @@ -85,26 +85,26 @@ module Puppet end def sync - file = @parent[:path] + file = @resource[:path] case File.lstat(file).ftype when "directory": - if @parent[:rmdirs] - subs = Dir.entries(@parent[:path]).reject { |d| + if @resource[:rmdirs] + subs = Dir.entries(@resource[:path]).reject { |d| d == "." or d == ".." }.length if subs > 0 self.info "%s has %s children; not tidying" % - [@parent[:path], subs] - self.info Dir.entries(@parent[:path]).inspect + [@resource[:path], subs] + self.info Dir.entries(@resource[:path]).inspect else - Dir.rmdir(@parent[:path]) + Dir.rmdir(@resource[:path]) end else self.debug "Not tidying directories" return nil end when "file": - @parent.handlebackup(file) + @resource.handlebackup(file) File.unlink(file) when "link": File.unlink(file) @@ -137,7 +137,7 @@ module Puppet if stat.ftype == "directory" type = :mtime else - type = @parent[:type] || :atime + type = @resource[:type] || :atime end #return Integer(Time.now - stat.send(type)) diff --git a/lib/puppet/type/user.rb b/lib/puppet/type/user.rb index b426102aa..417bf7cf5 100755 --- a/lib/puppet/type/user.rb +++ b/lib/puppet/type/user.rb @@ -36,7 +36,7 @@ module Puppet # If they're talking about the thing at all, they generally want to # say it should exist. defaultto do - if @parent.managed? + if @resource.managed? :present else nil @@ -183,7 +183,7 @@ module Puppet return nil end - if @parent[:membership] == :inclusive + if @resource[:membership] == :inclusive return @should.sort.join(",") else members = @should diff --git a/lib/puppet/type/yumrepo.rb b/lib/puppet/type/yumrepo.rb index cad411544..a344d2c3b 100644 --- a/lib/puppet/type/yumrepo.rb +++ b/lib/puppet/type/yumrepo.rb @@ -21,16 +21,16 @@ module Puppet else result = set(self.should) if should == :absent - parent.section[inikey] = nil + resource.section[inikey] = nil else - parent.section[inikey] = should + resource.section[inikey] = should end end return result end def retrieve - return parent.section[inikey] + return resource.section[inikey] end def inikey @@ -210,7 +210,7 @@ module Puppet class << changes[-1] def go result = super - self.property.parent.store + self.property.resource.store return result end end diff --git a/lib/puppet/type/zone.rb b/lib/puppet/type/zone.rb index 48f4a90bb..c38b212c0 100644 --- a/lib/puppet/type/zone.rb +++ b/lib/puppet/type/zone.rb @@ -139,7 +139,7 @@ Puppet::Type.newtype(:zone) do properties.each do |prop| if method = prop[dir] warned = false - while @parent.processing? + while @resource.processing? unless warned info "Waiting for zone to finish processing" warned = true @@ -326,7 +326,7 @@ end munge do |value| if value =~ /%s/ - value % @parent[:name] + value % @resource[:name] else value end diff --git a/test/ral/manager/type.rb b/test/ral/manager/type.rb index 355b81c4d..58af51fea 100755 --- a/test/ral/manager/type.rb +++ b/test/ral/manager/type.rb @@ -444,7 +444,7 @@ end # Now create an instance obj = type.create(:name => :myobj) - inst = property.new(:parent => obj) + inst = property.new(:resource => obj) # And make sure it's correctly setting @is ret = nil @@ -460,7 +460,7 @@ end property = type.newproperty(:setretrieve, :retrieve => :yayness) end - inst = property.new(:parent => obj) + inst = property.new(:resource => obj) # And make sure it's correctly setting @is ret = nil diff --git a/test/ral/providers/parsedfile.rb b/test/ral/providers/parsedfile.rb index 015d0a8b7..3e83f6ce8 100755 --- a/test/ral/providers/parsedfile.rb +++ b/test/ral/providers/parsedfile.rb @@ -29,7 +29,7 @@ class TestParsedFile < Test::Unit::TestCase # The target should always be a property, not a parameter. newproperty(:target) do - defaultto { @parent.class.defaultprovider.default_target } + defaultto { @resource.class.defaultprovider.default_target } end end diff --git a/test/ral/types/parameter.rb b/test/ral/types/parameter.rb index b34548546..865add14a 100755 --- a/test/ral/types/parameter.rb +++ b/test/ral/types/parameter.rb @@ -20,7 +20,7 @@ class TestParameter < Test::Unit::TestCase def newinst(param) assert_nothing_raised { - return param.new(:parent => "yay") + return param.new(:resource => "yay") } end diff --git a/test/ral/types/property.rb b/test/ral/types/property.rb index 11c31179f..a55a9b443 100755 --- a/test/ral/types/property.rb +++ b/test/ral/types/property.rb @@ -7,16 +7,16 @@ require 'puppettest' class TestProperty < Test::Unit::TestCase include PuppetTest - def newinst(property, parent = nil) + def newinst(property, resource = nil) inst = nil - unless parent - parent = "fakeparent" - parent.meta_def(:pathbuilder) do [self.to_s] end - parent.meta_def(:provider) do nil end - parent.meta_def(:fakeproperty) do '' end + unless resource + resource = "fakeresource" + resource.meta_def(:pathbuilder) do [self.to_s] end + resource.meta_def(:provider) do nil end + resource.meta_def(:fakeproperty) do '' end end assert_nothing_raised { - newinst = property.new(:parent => parent) + newinst = property.new(:resource => resource) def newinst.retrieve(); return @fakeprovidervalue; end; return newinst } @@ -222,7 +222,7 @@ class TestProperty < Test::Unit::TestCase inst = newinst(property, klassinst) # Now make sure we can set the values, they get validated as normal, - # and they set the values on the parent rathe than trying to call + # and they set the values on the resource rather than trying to call # a method {:value => :matched_value, "27" => :matched_number}.each do |value, event| assert_nothing_raised do @@ -255,7 +255,7 @@ class TestProperty < Test::Unit::TestCase inst = nil assert_nothing_raised do - inst = propertyklass.new(:parent => obj) + inst = propertyklass.new(:resource => obj) end assert_nothing_raised do @@ -278,7 +278,7 @@ class TestProperty < Test::Unit::TestCase myproperty.newvalue :mkfailure do raise "It's all broken" end - property = myproperty.new(:parent => p) + property = myproperty.new(:resource => p) assert_raise(Puppet::Error) do property.set(:mkfailure) |