summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/metatype/attributes.rb38
-rw-r--r--lib/puppet/metatype/evaluation.rb80
-rw-r--r--lib/puppet/metatype/providers.rb5
-rwxr-xr-xlib/puppet/network/handler/fileserver.rb29
-rw-r--r--lib/puppet/propertychange.rb18
-rwxr-xr-xlib/puppet/provider/parsedfile.rb6
-rw-r--r--lib/puppet/provider/zone/solaris.rb2
-rw-r--r--lib/puppet/transaction.rb2
-rwxr-xr-xlib/puppet/type/cron.rb62
-rwxr-xr-xlib/puppet/type/exec.rb6
-rwxr-xr-xlib/puppet/type/group.rb31
-rwxr-xr-xlib/puppet/type/host.rb45
-rwxr-xr-xlib/puppet/type/mount.rb17
-rw-r--r--lib/puppet/type/notify.rb2
-rw-r--r--lib/puppet/type/package.rb50
-rwxr-xr-xlib/puppet/type/parsedtype.rb16
-rw-r--r--lib/puppet/type/pfile.rb31
-rwxr-xr-xlib/puppet/type/pfile/checksum.rb104
-rwxr-xr-xlib/puppet/type/pfile/content.rb32
-rwxr-xr-xlib/puppet/type/pfile/ensure.rb22
-rwxr-xr-xlib/puppet/type/pfile/group.rb35
-rwxr-xr-xlib/puppet/type/pfile/mode.rb47
-rwxr-xr-xlib/puppet/type/pfile/owner.rb40
-rwxr-xr-xlib/puppet/type/pfile/source.rb32
-rw-r--r--lib/puppet/type/pfile/target.rb14
-rwxr-xr-xlib/puppet/type/pfile/type.rb9
-rw-r--r--lib/puppet/type/property.rb63
-rw-r--r--lib/puppet/type/resources.rb4
-rw-r--r--lib/puppet/type/service.rb9
-rwxr-xr-xlib/puppet/type/sshkey.rb7
-rwxr-xr-xlib/puppet/type/tidy.rb40
-rwxr-xr-xlib/puppet/type/user.rb66
-rw-r--r--lib/puppet/type/yumrepo.rb14
-rw-r--r--lib/puppet/type/zone.rb68
34 files changed, 519 insertions, 527 deletions
diff --git a/lib/puppet/metatype/attributes.rb b/lib/puppet/metatype/attributes.rb
index 131aafac6..50ee53c2b 100644
--- a/lib/puppet/metatype/attributes.rb
+++ b/lib/puppet/metatype/attributes.rb
@@ -307,9 +307,7 @@ class Puppet::Type
# method on the class.
if options[:retrieve]
define_method(:retrieve) do
- instance_variable_set(
- "@is", provider.send(options[:retrieve])
- )
+ provider.send(options[:retrieve])
end
end
@@ -458,22 +456,16 @@ class Puppet::Type
obj = @parameters[:ensure] and obj.should == :absent
end
- # Allow an outside party to specify the 'is' value for a property. The
- # arguments are an array because you can't use parens with 'is=' calls.
- # Most classes won't use this.
- def is=(ary)
- param, value = ary
- param = attr_alias(param)
- if self.class.validproperty?(param)
- unless prop = @parameters[param]
- prop = self.newattr(param)
- end
- prop.is = value
- else
- self[param] = value
+ # Create a new property if it is valid but doesn't exist
+ # Returns: true if a new parameter was added, false otherwise
+ def add_property_parameter(prop_name)
+ if self.class.validproperty?(prop_name) && !@parameters[prop_name]
+ self.newattr(prop_name)
+ return true
end
+ return false
end
-
+
# abstract accessing parameters and properties, and normalize
# access to always be symbols, not strings
# This returns a value, not an object. It returns the 'is'
@@ -492,7 +484,7 @@ class Puppet::Type
if obj = @parameters[name]
if obj.is_a?(Puppet::Type::Property)
- return obj.is
+ fail "[] called on a property"
else
return obj.value
end
@@ -554,16 +546,6 @@ class Puppet::Type
}
end
- # retrieve the 'is' value for a specified property
- def is(name)
- name = attr_alias(name)
- if prop = @parameters[name] and prop.is_a?(Puppet::Type::Property)
- return prop.is
- else
- return nil
- end
- end
-
# retrieve the 'should' value for a specified property
def should(name)
name = attr_alias(name)
diff --git a/lib/puppet/metatype/evaluation.rb b/lib/puppet/metatype/evaluation.rb
index 58f316e2c..09495d6d1 100644
--- a/lib/puppet/metatype/evaluation.rb
+++ b/lib/puppet/metatype/evaluation.rb
@@ -20,9 +20,9 @@ class Puppet::Type
# it's important that we call retrieve() on the type instance,
# not directly on the property, because it allows the type to override
# the method, like pfile does
- self.retrieve
+ currentvalues = self.retrieve
- changes = propertychanges().flatten
+ changes = propertychanges(currentvalues).flatten
# now record how many changes we've resulted in
if changes.length > 0
@@ -44,19 +44,32 @@ class Puppet::Type
# if all contained objects are in sync, then we're in sync
# FIXME I don't think this is used on the type instances any more,
# it's really only used for testing
- def insync?
+ def insync?(is)
insync = true
-
+
if property = @parameters[:ensure]
- if property.insync? and property.should == :absent
+ unless is.include? property
+ raise Puppet::DevError,
+ "The is value is not in the is array for '%s'" %
+ [property.name]
+ end
+ ensureis = is[property]
+ if property.insync?(ensureis) and property.should == :absent
return true
end
end
properties.each { |property|
- unless property.insync?
+ unless is.include? property
+ raise Puppet::DevError,
+ "The is value is not in the is array for '%s'" %
+ [property.name]
+ end
+
+ propis = is[property]
+ unless property.insync?(propis)
property.debug("Not in sync: %s vs %s" %
- [property.is.inspect, property.should.inspect])
+ [propis.inspect, property.should.inspect])
insync = false
#else
# property.debug("In sync")
@@ -66,28 +79,40 @@ class Puppet::Type
#self.debug("%s sync status is %s" % [self,insync])
return insync
end
-
+
# retrieve the current value of all contained properties
def retrieve
+ return currentpropvalues
+ end
+
+ # get a hash of the current properties.
+ def currentpropvalues(override_value = nil)
# it's important to use the method here, as it follows the order
# in which they're defined in the object
- properties().each { |property|
- property.retrieve
- }
+ return properties().inject({}) { | prophash, property|
+ prophash[property] = override_value.nil? ?
+ property.retrieve :
+ override_value
+ prophash
+ }
end
-
+
# Retrieve the changes associated with all of the properties.
- def propertychanges
+ def propertychanges(currentvalues)
# If we are changing the existence of the object, then none of
# the other properties matter.
changes = []
- if @parameters.include?(:ensure) and ! @parameters[:ensure].insync?
+ ensureparam = @parameters[:ensure]
+ if @parameters.include?(:ensure) && !currentvalues.include?(ensureparam)
+ raise Puppet::DevError, "Parameter ensure defined but missing from current values"
+ end
+ if @parameters.include?(:ensure) and ! ensureparam.insync?(currentvalues[ensureparam])
# self.info "ensuring %s from %s" %
# [@parameters[:ensure].should, @parameters[:ensure].is]
- changes = [Puppet::PropertyChange.new(@parameters[:ensure])]
+ changes << Puppet::PropertyChange.new(ensureparam, currentvalues[ensureparam])
# Else, if the 'ensure' property is correctly absent, then do
# nothing
- elsif @parameters.include?(:ensure) and @parameters[:ensure].is == :absent
+ elsif @parameters.include?(:ensure) and currentvalues[ensureparam] == :absent
# self.info "Object is correctly absent"
return []
else
@@ -98,9 +123,13 @@ class Puppet::Type
# self.info "no ensure property"
# end
changes = properties().find_all { |property|
- ! property.insync?
+ unless currentvalues.include?(property)
+ raise Puppet::DevError, "Property %s does not have a current value",
+ [property.name]
+ end
+ ! property.insync?(currentvalues[property])
}.collect { |property|
- Puppet::PropertyChange.new(property)
+ Puppet::PropertyChange.new(property, currentvalues[property])
}
end
@@ -113,6 +142,21 @@ class Puppet::Type
changes
end
+
+ private
+ # FIXARB: This can go away
+ def checknewinsync(currentvalues)
+ currentvalues.each { |prop, val|
+ if prop.respond_to? :new_insync? and prop.new_insync?(val) != prop.insync?
+ puts "#{prop.name} new_insync? != insync?"
+ self.devfail "#{prop.name} new_insync? != insync?"
+ end
+ }
+
+ properties().each { |prop|
+ puts "#{prop.name} is missing from current values" if (!currentvalues.include?(prop))
+ }
+ end
end
# $Id$
diff --git a/lib/puppet/metatype/providers.rb b/lib/puppet/metatype/providers.rb
index ed9c68ab6..a130fc186 100644
--- a/lib/puppet/metatype/providers.rb
+++ b/lib/puppet/metatype/providers.rb
@@ -61,15 +61,12 @@ class Puppet::Type
# we've set up our naming stuff correctly everywhere.
# Mark found objects as present
- obj.is = [:ensure, :present]
hash.each { |param, value|
if property = obj.property(param)
- property.is = value
elsif val = obj[param]
obj[param] = val
else
# There is a value on disk, but it should go away
- obj.is = [param, value]
obj[param] = :absent
end
}
@@ -82,7 +79,7 @@ class Puppet::Type
# because it sets the should value, not the is value.
hash.delete(namevar)
hash.each { |param, value|
- obj.is = [param, value]
+ obj[param] = value unless obj.add_property_parameter(param)
}
end
diff --git a/lib/puppet/network/handler/fileserver.rb b/lib/puppet/network/handler/fileserver.rb
index 4331d27fd..5ba507b16 100755
--- a/lib/puppet/network/handler/fileserver.rb
+++ b/lib/puppet/network/handler/fileserver.rb
@@ -42,20 +42,23 @@ class Puppet::Network::Handler
end
obj = nil
- unless obj = mount.check(path, links)
+ unless obj = mount.getfileobject(path, links)
return ""
end
+ currentvalues = mount.check(obj)
+
desc = []
CHECKPARAMS.each { |check|
if property = obj.property(check)
- unless property.is
+ if currentvalues[property]
+ desc << currentvalues[property]
+ else
mount.debug "Manually retrieving info for %s" % check
- property.retrieve
+ desc << property.retrieve
end
- desc << property.is
else
- if check == "checksum" and obj.property(:type).is == "file"
+ if check == "checksum" and currentvalues[obj.property(:type)] == "file"
mount.notice "File %s does not have data for %s" %
[obj.name, check]
end
@@ -424,16 +427,18 @@ class Puppet::Network::Handler
Puppet::Util.logmethods(self, true)
- # Run 'retrieve' on a file. This gets the actual parameters, so
- # we can pass them to the client.
- def check(dir, links)
+ def getfileobject(dir, links)
unless FileTest.exists?(dir)
self.notice "File source %s does not exist" % dir
return nil
end
- obj = fileobj(dir, links)
-
+ return fileobj(dir, links)
+ end
+
+ # Run 'retrieve' on a file. This gets the actual parameters, so
+ # we can pass them to the client.
+ def check(obj)
# FIXME we should really have a timeout here -- we don't
# want to actually check on every connection, maybe no more
# than every 60 seconds or something. It'd be nice if we
@@ -444,9 +449,7 @@ class Puppet::Network::Handler
# any state changes or anything. We don't even need to sync
# the checksum, because we're always going to hit the disk
# directly.
- obj.retrieve
-
- return obj
+ return obj.retrieve
end
# Create a map for a specific client.
diff --git a/lib/puppet/propertychange.rb b/lib/puppet/propertychange.rb
index bbd18a22d..53d8ceec4 100644
--- a/lib/puppet/propertychange.rb
+++ b/lib/puppet/propertychange.rb
@@ -14,19 +14,19 @@ module Puppet
# Switch the goals of the property, thus running the change in reverse.
def backward
@property.should = @is
- @property.retrieve
+ @is = @property.retrieve
unless defined? @transaction
raise Puppet::Error,
"PropertyChange '%s' tried to be executed outside of transaction" %
self
end
- unless @property.insync?
+ unless @property.insync?(@is)
@property.info "Backing %s" % self
return self.go
else
@property.debug "rollback is already in sync: %s vs. %s" %
- [@property.is.inspect, @property.should.inspect]
+ [@is, @property.should.inspect]
return nil
end
end
@@ -52,14 +52,14 @@ module Puppet
)
end
- def initialize(property)
+ def initialize(property, currentvalue)
unless property.is_a?(Puppet::Type::Property)
raise Puppet::DevError, "Got a %s instead of a property" %
property.class
end
@property = property
@path = [property.path,"change"].flatten
- @is = property.is
+ @is = currentvalue
@should = property.should
@@ -92,7 +92,7 @@ module Puppet
end
return events.collect { |name|
- @report = @property.log(@property.change_to_s)
+ @report = @property.log(@property.change_to_s(@is, @should))
event(name)
}
end
@@ -114,14 +114,14 @@ module Puppet
end
def skip?
- if @property.insync?
+ if @property.insync?(@is)
@property.info "Already in sync"
return true
end
if @property.noop
@property.log "is %s, should be %s (noop)" %
- [property.is_to_s, property.should_to_s]
+ [property.is_to_s(@is), property.should_to_s(@should)]
#@property.debug "%s is noop" % @property
return true
end
@@ -134,7 +134,7 @@ module Puppet
def to_s
return "change %s.%s(%s)" %
- [@transaction.object_id, self.object_id, @property.change_to_s]
+ [@transaction.object_id, self.object_id, @property.change_to_s(@is, @should)]
#return "change %s.%s" % [@transaction.object_id, self.object_id]
end
end
diff --git a/lib/puppet/provider/parsedfile.rb b/lib/puppet/provider/parsedfile.rb
index 8d1936ceb..334768d6b 100755
--- a/lib/puppet/provider/parsedfile.rb
+++ b/lib/puppet/provider/parsedfile.rb
@@ -273,9 +273,9 @@ class Puppet::Provider::ParsedFile < Puppet::Provider
# This is only the case for properties, and targets should always
# be properties.
- if model.respond_to?(:is)
- targets << model.is(:target)
- end
+ #if model.respond_to?(:is)
+ # targets << model.is(:target)
+ #end
end
targets.uniq.reject { |t| t.nil? }
diff --git a/lib/puppet/provider/zone/solaris.rb b/lib/puppet/provider/zone/solaris.rb
index 572f137b0..e22192c22 100644
--- a/lib/puppet/provider/zone/solaris.rb
+++ b/lib/puppet/provider/zone/solaris.rb
@@ -114,6 +114,8 @@ set zonepath=%s
return hash
end
+ # FIXARB: Not sure what this one is doing. It is not setting @is for the
+ # if case.
def retrieve
if hash = statushash()
setstatus(hash)
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb
index 75332c145..a276d138c 100644
--- a/lib/puppet/transaction.rb
+++ b/lib/puppet/transaction.rb
@@ -107,7 +107,7 @@ class Transaction
puts detail.backtrace
end
change.property.err "change from %s to %s failed: %s" %
- [change.property.is_to_s, change.property.should_to_s, detail]
+ [change.property.is_to_s(change.is), change.property.should_to_s(change.should), detail]
@failures[resource] += 1
next
# FIXME this should support using onerror to determine
diff --git a/lib/puppet/type/cron.rb b/lib/puppet/type/cron.rb
index ebf0fbe8a..3c72224e0 100755
--- a/lib/puppet/type/cron.rb
+++ b/lib/puppet/type/cron.rb
@@ -39,9 +39,9 @@ Puppet::Type.newtype(:cron) do
# We have to override the parent method, because we consume the entire
# "should" array
- def insync?
+ def insync?(is)
if defined? @should and @should
- self.is_to_s == self.should_to_s
+ self.is_to_s(is) == self.should_to_s
else
true
end
@@ -93,36 +93,28 @@ Puppet::Type.newtype(:cron) do
return false
end
- def should_to_s
- if @should
- if self.name == :command or @should[0].is_a? Symbol
- @should[0]
+ def should_to_s(newvalue = @should)
+ if newvalue
+ if self.name == :command or newvalue[0].is_a? Symbol
+ newvalue[0]
else
- @should.join(",")
+ newvalue.join(",")
end
else
nil
end
end
- def is=(val)
- if val.is_a?(Array)
- @is = val
- else
- @is = [val]
- end
- end
-
- def is_to_s
- if @is
- unless @is.is_a?(Array)
- return @is
+ def is_to_s(currentvalue = @is)
+ if currentvalue
+ unless currentvalue.is_a?(Array)
+ return currentvalue
end
- if self.name == :command or @is[0].is_a? Symbol
- @is[0]
+ if self.name == :command or currentvalue[0].is_a? Symbol
+ currentvalue[0]
else
- @is.join(",")
+ currentvalue.join(",")
end
else
nil
@@ -206,12 +198,13 @@ Puppet::Type.newtype(:cron) do
All cron parameters support ``absent`` as a value; this will
remove any existing values for that field."
- def is
- if @is
- @is[0]
- else
- nil
- end
+ def retrieve
+ return_value = super
+ if return_value && return_value.is_a?(Array)
+ return_value = return_value[0]
+ end
+
+ return return_value
end
def should
@@ -286,6 +279,7 @@ Puppet::Type.newtype(:cron) do
can be no guarantees that other, earlier settings will not also
affect a given cron job.
+
Also, Puppet cannot automatically determine whether an existing,
unmanaged environment setting is associated with a given cron
job. If you already have cron jobs with environment settings,
@@ -302,11 +296,11 @@ Puppet::Type.newtype(:cron) do
end
end
- def insync?
- if @is.is_a? Array
- return @is.sort == @should.sort
+ def insync?(is)
+ if is.is_a? Array
+ return is.sort == @should.sort
else
- return @is == @should
+ return is == @should
end
end
@@ -370,7 +364,7 @@ Puppet::Type.newtype(:cron) do
ret = obj.should
if ret.nil?
- ret = obj.is
+ ret = obj.retrieve
end
if ret == :absent
@@ -394,4 +388,6 @@ Puppet::Type.newtype(:cron) do
end
end
+
# $Id$
+
diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb
index 5a045f630..9097f6179 100755
--- a/lib/puppet/type/exec.rb
+++ b/lib/puppet/type/exec.rb
@@ -79,7 +79,7 @@ module Puppet
executed command returns something else. Defaults to 0."
# Make output a bit prettier
- def change_to_s
+ def change_to_s(currentvalue, newvalue)
return "executed successfully"
end
@@ -88,9 +88,9 @@ module Puppet
# Default to somethinng
if @parent.check
- self.is = :notrun
+ return :notrun
else
- self.is = self.should
+ return self.should
end
end
diff --git a/lib/puppet/type/group.rb b/lib/puppet/type/group.rb
index 27d4b90d6..c0cfd900c 100755
--- a/lib/puppet/type/group.rb
+++ b/lib/puppet/type/group.rb
@@ -47,15 +47,16 @@ module Puppet
end
end
- def change_to_s
+ # FIXARB: Check this... I think it may be the same as in Ensure class.
+ def change_to_s(currentvalue, newvalue)
begin
- if @is == :absent
+ if currentvalue == :absent
return "created"
- elsif self.should == :absent
+ elsif newvalue == :absent
return "removed"
else
return "%s changed '%s' to '%s'" %
- [self.name, self.is_to_s, self.should_to_s]
+ [self.name, self.is_to_s(currentvalue), self.should_to_s(newvalue)]
end
rescue Puppet::Error, Puppet::DevError
raise
@@ -67,22 +68,12 @@ module Puppet
end
def retrieve
- if provider.exists?
- @is = :present
- else
- @is = :absent
- end
+ return provider.exists? ? :present : :absent
end
# The default 'sync' method only selects among a list of registered
# values.
def sync
- if self.insync?
- self.info "already in sync"
- return nil
- #else
- #self.info "%s vs %s" % [self.is.inspect, self.should.inspect]
- end
unless self.class.values
self.devfail "No values defined for %s" %
self.class.name
@@ -101,7 +92,7 @@ module Puppet
GID is picked according to local system standards."
def retrieve
- @is = provider.gid
+ return provider.gid
end
def sync
@@ -167,13 +158,9 @@ module Puppet
def retrieve
if self.provider and @provider.exists?
- super
+ return super
else
- properties().each { |property|
- property.is = :absent
- }
-
- return
+ return currentpropvalues(:absent)
end
end
end
diff --git a/lib/puppet/type/host.rb b/lib/puppet/type/host.rb
index 8a449da4b..0d3013dbd 100755
--- a/lib/puppet/type/host.rb
+++ b/lib/puppet/type/host.rb
@@ -15,47 +15,28 @@ module Puppet
make those aliases available in your Puppet scripts and also on
disk."
- def insync?
- @is == @should
+ def insync?(is)
+ is == @should
end
- # Make sure our "is" value is always an array.
- def is
- current = super
- current = [current] unless current.is_a? Array
- current
+ def is_to_s(currentvalue = @is)
+ currentvalue = [currentvalue] unless currentvalue.is_a? Array
+ currentvalue.join(" ")
end
- def is_to_s
- self.is.join(" ")
- end
-
- # We have to override the feeding mechanism; it might be nil or
- # white-space separated
- def is=(value)
- # If it's just whitespace, ignore it
- case value
- when /^\s+$/
- @is = nil
- when String
- @is = value.split(/\s+/)
- else
- @is = value
- end
- end
-
def retrieve
- super
- case @is
+ is = super
+ case is
when String
- @is = @is.split(/\s*,\s*/)
+ is = is.split(/\s*,\s*/)
when Symbol:
- @is = [@is]
+ is = [is]
when Array
# nothing
else
- raise Puppet::DevError, "Invalid @is type %s" % @is.class
+ raise Puppet::DevError, "Invalid @is type %s" % is.class
end
+ return is
end
# We actually want to return the whole array here, not just the first
@@ -72,8 +53,8 @@ module Puppet
end
end
- def should_to_s
- @should.join(" ")
+ def should_to_s(newvalue = @should)
+ newvalue.join(" ")
end
validate do |value|
diff --git a/lib/puppet/type/mount.rb b/lib/puppet/type/mount.rb
index 6e882687d..ea25d5b5b 100755
--- a/lib/puppet/type/mount.rb
+++ b/lib/puppet/type/mount.rb
@@ -43,7 +43,8 @@ module Puppet
newvalue(:mounted, :event => :mount_mounted) do
# Create the mount point if it does not already exist.
- if self.is == :absent or self.is.nil?
+ current_value = self.retrieve
+ if current_value.nil? or current_value == :absent
provider.create
end
@@ -52,20 +53,22 @@ module Puppet
end
def retrieve
- if provider.mounted?
- @is = :mounted
- else
- @is = super()
- end
+ return provider.mounted? ? :mounted : super()
end
def syncothers
# We have to flush any changes to disk.
+ currentvalues = @parent.retrieve
oos = @parent.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",
+ [prop.name]
+ end
if prop.name == :ensure
false
else
- ! prop.insync?
+ ! prop.insync?(currentvalues[prop])
end
end.each { |prop| prop.sync }.length
if oos > 0
diff --git a/lib/puppet/type/notify.rb b/lib/puppet/type/notify.rb
index 8877e3398..599197f76 100644
--- a/lib/puppet/type/notify.rb
+++ b/lib/puppet/type/notify.rb
@@ -22,7 +22,7 @@ module Puppet
return
end
- def insync?
+ def insync?(is)
false
end
diff --git a/lib/puppet/type/package.rb b/lib/puppet/type/package.rb
index 642d1bc99..244a79072 100644
--- a/lib/puppet/type/package.rb
+++ b/lib/puppet/type/package.rb
@@ -79,7 +79,7 @@ module Puppet
# Because yum always exits with a 0 exit code, there's a retrieve
# in the "install" method. So, check the current state now,
# to compare against later.
- current = self.is
+ current = self.retrieve
begin
provider.update
rescue => detail
@@ -106,7 +106,7 @@ module Puppet
self.fail "Could not update: %s" % detail
end
- if self.is == :absent
+ if self.retrieve == :absent
:package_installed
else
:package_changed
@@ -118,7 +118,7 @@ module Puppet
# Override the parent method, because we've got all kinds of
# funky definitions of 'in sync'.
- def insync?
+ def insync?(is)
@should ||= []
@latest = nil unless defined? @latest
@@ -128,12 +128,12 @@ module Puppet
@should.each { |should|
case should
when :present
- unless @is == :absent
+ unless is == :absent
return true
end
when :latest
# Short-circuit packages that are not present
- if @is == :absent
+ if is == :absent
return false
end
@@ -156,7 +156,7 @@ module Puppet
end
end
- case @is
+ case is
when @latest:
return true
when :present:
@@ -164,14 +164,14 @@ module Puppet
# that can't query versions.
return true
else
- self.debug "@is is %s, latest %s is %s" %
- [@is.inspect, @parent.name, @latest.inspect]
+ self.debug "is is %s, latest %s is %s" %
+ [is.inspect, @parent.name, @latest.inspect]
end
when :absent
- if @is == :absent
+ if is == :absent
return true
end
- when @is
+ when is
return true
end
}
@@ -181,15 +181,15 @@ module Puppet
# This retrieves the current state. LAK: I think this method is unused.
def retrieve
- @is = @parent.retrieve
+ return @parent.retrieve
end
# Provide a bit more information when logging upgrades.
- def should_to_s
+ def should_to_s(newvalue = @should)
if @latest
@latest.to_s
else
- super
+ super(newvalue)
end
end
end
@@ -379,7 +379,7 @@ module Puppet
self.each do |pkg|
next unless packages[:provider] == pkgtype
unless packages.include? pkg
- pkg.is = [:ensure, :absent]
+ pkg.provider.send(:ensure, :absent)
end
end
end
@@ -428,7 +428,7 @@ module Puppet
# about it and set it appropriately.
if hash = @provider.query
if hash == :listed # Mmmm, hackalicious
- return
+ return {}
end
hash.each { |param, value|
unless self.class.validattr?(param)
@@ -437,11 +437,19 @@ module Puppet
}
setparams(hash)
+
+ return properties().inject({}) { |prop_hash, property|
+ prop_hash[property] = hash[property.name] if hash.has_key?(property.name)
+ prop_hash
+ }
else
# Else just mark all of the properties absent.
- self.class.validproperties.each { |name|
- self.is = [name, :absent]
- }
+ # FIXARB: Not sure why this is using validproperties instead of
+ # properties()?
+ return self.class.validproperties.inject({}) { |h, name|
+ h[@parameters[name]] = :absent
+ h
+ }
end
end
@@ -449,9 +457,11 @@ module Puppet
# are properties.
def setparams(hash)
# Everything on packages is a parameter except :ensure
- hash.each { |param, value|
+ hash.each { |param, value|
+ next if param == :ensure
if self.class.attrtype(param) == :property
- self.is = [param, value]
+ add_property_parameter(param)
+ self.provider.send("%s=" % param, value)
else
self[param] = value
end
diff --git a/lib/puppet/type/parsedtype.rb b/lib/puppet/type/parsedtype.rb
index 40a90d5ae..488922efd 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
- @parent.retrieve
+ return @parent.retrieve
end
# All this does is return an event; all of the work gets done
@@ -197,20 +197,22 @@ module Puppet
end
end
- properties().each do |property|
+ currentvalues = properties().inject({}) do |prophash, property|
if h.has_key? property.name
property.is = h[property.name]
+ prophash[property] = h[property.name]
else
property.is = :absent
+ prophash[property] = :absent
end
+ prophash
end
- return h
+ # FIXARB: This used to return h, find what broke ;)
+ return currentvalues
else
- properties().each do |property|
- property.is = :absent
- end
- return nil
+ # FIXARB: This used to return nil, find what broke ;)
+ return currentpropvalues(:absent)
end
end
end
diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb
index 39a298ed9..bfa10dda2 100644
--- a/lib/puppet/type/pfile.rb
+++ b/lib/puppet/type/pfile.rb
@@ -823,22 +823,21 @@ module Puppet
def retrieve
unless stat = self.stat(true)
self.debug "File does not exist"
- properties().each { |property|
- property.is = :absent
- }
-
# If the file doesn't exist but we have a source, then call
# retrieve on that property
+
+ propertyvalues = properties().inject({}) { |hash, property|
+ hash[property] = :absent
+ hash
+ }
+
if @parameters.include?(:source)
- @parameters[:source].retrieve
+ propertyvalues[:source] = @parameters[:source].retrieve
end
-
- return
+ return propertyvalues
end
- properties().each { |property|
- property.retrieve
- }
+ return currentpropvalues()
end
# This recurses against the remote source and makes sure the local
@@ -929,8 +928,8 @@ module Puppet
else
# If they didn't pass in a sum, then tell checksum to
# figure it out.
- @parameters[:checksum].retrieve
- @parameters[:checksum].checksum = @parameters[:checksum].is
+ currentvalue = @parameters[:checksum].retrieve
+ @parameters[:checksum].checksum = currentvalue
end
end
end
@@ -1118,7 +1117,7 @@ module Puppet
# Override the parent method, because we don't want to generate changes
# when the file is missing and there is no 'ensure' state.
- def propertychanges
+ def propertychanges(currentvalues)
unless self.stat
found = false
([:ensure] + CREATORS).each do |prop|
@@ -1143,8 +1142,8 @@ module Puppet
# Make sure we get a new stat objct
self.stat(true)
- thing.retrieve
- unless thing.insync?
+ currentvalue = thing.retrieve
+ unless thing.insync?(currentvalue)
thing.sync
end
end
@@ -1159,7 +1158,7 @@ module Puppet
# We put all of the properties in separate files, because there are so many
# of them. The order these are loaded is important, because it determines
- # the order they are in the property list.
+ # the order they are in the property lit.
require 'puppet/type/pfile/checksum'
require 'puppet/type/pfile/content' # can create the file
require 'puppet/type/pfile/source' # can create the file
diff --git a/lib/puppet/type/pfile/checksum.rb b/lib/puppet/type/pfile/checksum.rb
index 09dc016c1..ec4c8a34f 100755
--- a/lib/puppet/type/pfile/checksum.rb
+++ b/lib/puppet/type/pfile/checksum.rb
@@ -83,9 +83,8 @@ module Puppet
# Because source and content and whomever else need to set the checksum
# and do the updating, we provide a simple mechanism for doing so.
def checksum=(value)
- @is = value
munge(@should)
- self.updatesum
+ self.updatesum(value)
end
def checktype
@@ -93,21 +92,21 @@ module Puppet
end
# Checksums need to invert how changes are printed.
- def change_to_s
+ def change_to_s(currentvalue, newvalue)
begin
- if @is == :absent
+ if currentvalue == :absent
return "defined '%s' as '%s'" %
[self.name, self.currentsum]
- elsif self.should == :absent
+ elsif newvalue == :absent
return "undefined %s from '%s'" %
- [self.name, self.is_to_s]
+ [self.name, self.is_to_s(currentvalue)]
else
if defined? @cached and @cached
return "%s changed '%s' to '%s'" %
- [self.name, @cached, self.is_to_s]
+ [self.name, @cached, self.is_to_s(currentvalue)]
else
return "%s changed '%s' to '%s'" %
- [self.name, self.currentsum, self.is_to_s]
+ [self.name, self.currentsum, self.is_to_s(currentvalue)]
end
end
rescue Puppet::Error, Puppet::DevError
@@ -209,80 +208,78 @@ module Puppet
# the stored state to reflect the current state, and then kick
# off an event to mark any changes.
def handlesum
- if @is.nil?
+ currentvalue = self.retrieve
+ if currentvalue.nil?
raise Puppet::Error, "Checksum state for %s is somehow nil" %
@parent.title
end
- if @is == :absent
- self.retrieve
-
- if self.insync?
- self.debug "Checksum is already in sync"
- return nil
- end
- #@parent.debug "%s(%s): after refresh, is '%s'" %
+ 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]
# If we still can't retrieve a checksum, it means that
# the file still doesn't exist
- if @is == :absent
- # if they're copying, then we won't worry about the file
- # not existing yet
- unless @parent.property(:source)
- self.warning(
- "File %s does not exist -- cannot checksum" %
- @parent[:path]
- )
- end
- return nil
+ if currentvalue == :absent
+ # if they're copying, then we won't worry about the file
+ # not existing yet
+ unless @parent.property(:source)
+ self.warning("File %s does not exist -- cannot checksum" %
+ @parent[:path]
+ )
end
+ return nil
end
-
+
# If the sums are different, then return an event.
- if self.updatesum
+ if self.updatesum(currentvalue)
return :file_changed
else
return nil
end
end
- def insync?
- @should = [checktype]
+ def insync?(currentvalue)
+ @should = [checktype()]
if cache(checktype())
- return @is == currentsum()
+ return currentvalue == currentsum()
else
# If there's no cached sum, then we don't want to generate
# an event.
return true
end
end
-
+
# Even though they can specify multiple checksums, the insync?
# mechanism can really only test against one, so we'll just retrieve
# the first specified sum type.
+ # FIXARB: THere is a cache but it seems inconsistent when it
+ # uses the cache vs, when it uses @is. This will
+ # need more attention.
def retrieve(usecache = false)
# When the 'source' is retrieving, it passes "true" here so
# that we aren't reading the file twice in quick succession, yo.
- if usecache and @is
- return @is
+ currentvalue = currentsum()
+ if usecache and currentvalue
+ return currentvalue
end
stat = nil
unless stat = @parent.stat
- self.is = :absent
- return
+ return :absent
end
if stat.ftype == "link" and @parent[:links] != :follow
self.debug "Not checksumming symlink"
- #@parent.delete(:checksum)
- self.is = self.currentsum
- return
+ # @parent.delete(:checksum)
+ return currentvalue
end
# Just use the first allowed check type
- @is = getsum(checktype())
+ currentvalue = getsum(checktype())
# If there is no sum defined, then store the current value
# into the cache, so that we're not marked as being
@@ -290,17 +287,18 @@ module Puppet
# time we get a sum.
unless cache(checktype())
# FIXME we should support an updatechecksums-like mechanism
- self.updatesum
+ self.updatesum(currentvalue)
end
-
- #@parent.debug "checksum state is %s" % self.is
+
+ # @parent.debug "checksum state is %s" % self.is
+ return currentvalue
end
# Store the new sum to the state db.
- def updatesum
+ def updatesum(newvalue)
result = false
- if @is.is_a?(Symbol)
+ if newvalue.is_a?(Symbol)
raise Puppet::Error, "%s has invalid checksum" % @parent.title
end
@@ -313,25 +311,23 @@ module Puppet
# )
# end
- if @is == sum
+ if newvalue == sum
return false
end
- #if cache(self.should) == @is
- # raise Puppet::Error, "Got told to update same sum twice"
- #end
self.debug "Replacing %s checksum %s with %s" %
- [@parent.title, sum, @is]
- #@parent.debug "@is: %s; @should: %s" % [@is,@should]
+ [@parent.title, sum, newvalue]
+ # @parent.debug "currentvalue: %s; @should: %s" %
+ # [newvalue,@should]
result = true
else
- @parent.debug "Creating checksum %s" % @is
+ @parent.debug "Creating checksum %s" % newvalue
result = false
end
# Cache the sum so the log message can be right if possible.
@cached = sum
- cache(checktype(), @is)
+ cache(checktype(), newvalue)
return result
end
end
diff --git a/lib/puppet/type/pfile/content.rb b/lib/puppet/type/pfile/content.rb
index e3e390179..9b8be0d68 100755
--- a/lib/puppet/type/pfile/content.rb
+++ b/lib/puppet/type/pfile/content.rb
@@ -20,13 +20,13 @@ module Puppet
This attribute is especially useful when used with
`PuppetTemplating templating`:trac:."
- def change_to_s
- should = "{md5}" + Digest::MD5.hexdigest(self.should)
- if @is == :absent
- return "created file with contents %s" % should
+ def change_to_s(currentvalue, newvalue)
+ newvalue = "{md5}" + Digest::MD5.hexdigest(newvalue)
+ if currentvalue == :absent
+ return "created file with contents %s" % newvalue
else
- is = "{md5}" + Digest::MD5.hexdigest(@is)
- return "changed file contents from %s to %s" % [is, should]
+ currentvalue = "{md5}" + Digest::MD5.hexdigest(currentvalue)
+ return "changed file contents from %s to %s" % [currentvalue, newvalue]
end
end
@@ -35,25 +35,23 @@ module Puppet
def retrieve
stat = nil
unless stat = @parent.stat
- @is = :absent
- return
+ return :absent
end
if stat.ftype == "link" and @parent[:links] == :ignore
- self.is = self.should
- return
+ 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)
- return
+ return nil
end
begin
- @is = File.read(@parent[:path])
+ currentvalue = File.read(@parent[:path])
+ return currentvalue
rescue => detail
- @is = nil
raise Puppet::Error, "Could not read %s: %s" %
[@parent.title, detail]
end
@@ -62,13 +60,11 @@ module Puppet
# Just write our content out to disk.
def sync
+ return_event = @parent.stat ? :file_changed : :file_created
+
@parent.write { |f| f.print self.should }
- if @is == :absent
- return :file_created
- else
- return :file_changed
- end
+ return return_event
end
end
end
diff --git a/lib/puppet/type/pfile/ensure.rb b/lib/puppet/type/pfile/ensure.rb
index 658c3535e..afd2baae3 100755
--- a/lib/puppet/type/pfile/ensure.rb
+++ b/lib/puppet/type/pfile/ensure.rb
@@ -108,11 +108,13 @@ module Puppet
return :link
end
- def change_to_s
- if property = (@parent.property(:content) || @parent.property(:source)) and ! property.insync?
- return property.change_to_s
+ def change_to_s(currentvalue, newvalue)
+ if property = (@parent.property(:content) || @parent.property(:source)) and ! property.insync?(currentvalue)
+ currentvalue = property.retrieve
+
+ return property.change_to_s(property.retrieve, property.should)
else
- super
+ super(currentvalue, newvalue)
end
end
@@ -133,26 +135,26 @@ module Puppet
# We have to treat :present specially, because it works with any
# type of file.
- def insync?
+ def insync?(currentvalue)
if self.should == :present
- if @is.nil? or @is == :absent
+ if currentvalue.nil? or currentvalue == :absent
return false
else
return true
end
else
- return super
+ return super(currentvalue)
end
end
def retrieve
if stat = @parent.stat(false)
- @is = stat.ftype.intern
+ return stat.ftype.intern
else
if self.should == :false
- @is = :false
+ return :false
else
- @is = :absent
+ return :absent
end
end
end
diff --git a/lib/puppet/type/pfile/group.rb b/lib/puppet/type/pfile/group.rb
index fb032a1ee..6606f3322 100755
--- a/lib/puppet/type/pfile/group.rb
+++ b/lib/puppet/type/pfile/group.rb
@@ -26,20 +26,19 @@ module Puppet
end
# We want to print names, not numbers
- def is_to_s
- if @is.is_a? Integer
- id2name(@is) || @is
+ def is_to_s(currentvalue)
+ if currentvalue.is_a? Integer
+ id2name(currentvalue) || currentvalue
else
- return @is.to_s
+ return currentvalue.to_s
end
end
- def should_to_s
- should = self.should
- if should.is_a? Integer
- id2name(should) || should
+ def should_to_s(newvalue = @should)
+ if newvalue.is_a? Integer
+ id2name(newvalue) || newalue
else
- return should.to_s
+ return newvalue.to_s
end
end
@@ -60,8 +59,7 @@ module Puppet
stat = @parent.stat(false)
unless stat
- self.is = :absent
- return
+ return :absent
end
# Set our method appropriately, depending on links.
@@ -70,7 +68,8 @@ module Puppet
else
@method = :chown
end
- self.is = stat.gid
+
+ return stat.gid
end
# Determine if the group is valid, and if so, return the GID
@@ -90,19 +89,15 @@ 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
- if @is == :absent
- @parent.stat(true)
- self.retrieve
+ unless @parent.stat(false)
+ stat = @parent.stat(true)
+ currentvalue = self.retrieve
- if @is == :absent
+ unless stat
self.debug "File '%s' does not exist; cannot chgrp" %
@parent[:path]
return nil
end
-
- if self.insync?
- return nil
- end
end
gid = nil
diff --git a/lib/puppet/type/pfile/mode.rb b/lib/puppet/type/pfile/mode.rb
index e29e74235..ceb4c0d56 100755
--- a/lib/puppet/type/pfile/mode.rb
+++ b/lib/puppet/type/pfile/mode.rb
@@ -10,27 +10,27 @@ module Puppet
# Our modes are octal, so make sure they print correctly. Other
# valid values are symbols, basically
- def is_to_s
- case @is
+ def is_to_s(currentvalue)
+ case currentvalue
when Integer
- return "%o" % @is
+ return "%o" % currentvalue
when Symbol
- return @is
+ return currentvalue
else
- raise Puppet::DevError, "Invalid 'is' value for mode: %s" %
- @is.inspect
+ raise Puppet::DevError, "Invalid current value for mode: %s" %
+ currentvalue.inspect
end
end
- def should_to_s
- case self.should
+ def should_to_s(newvalue = @should)
+ case newvalue
when Integer
- return "%o" % self.should
+ return "%o" % newvalue
when Symbol
- return self.should
+ return newvalue
else
raise Puppet::DevError, "Invalid 'should' value for mode: %s" %
- self.should.inspect
+ newvalue.inspect
end
end
@@ -77,12 +77,12 @@ module Puppet
return value
end
- def insync?
+ def insync?(currentvalue)
if stat = @parent.stat and stat.ftype == "link" and @parent[:links] != :follow
self.debug "Not managing symlink mode"
return true
else
- return super
+ return super(currentvalue)
end
end
@@ -91,30 +91,23 @@ module Puppet
# off mode management entirely.
if stat = @parent.stat(false)
- self.is = stat.mode & 007777
unless defined? @fixed
if defined? @should and @should
@should = @should.collect { |s| self.dirmask(s) }
end
end
+ return stat.mode & 007777
else
- self.is = :absent
+ return :absent
end
-
- #self.debug "chmod state is %o" % self.is
end
def sync
- if @is == :absent
- @parent.stat(true)
- self.retrieve
- if @is == :absent
- self.debug "File does not exist; cannot set mode"
- return nil
- end
+ unless @parent.stat(false)
+ stat = @parent.stat(true)
- if self.insync?
- # we're already in sync
+ unless stat
+ self.debug "File does not exist; cannot set mode"
return nil
end
end
@@ -127,7 +120,7 @@ module Puppet
end
begin
- File.chmod(mode,@parent[:path])
+ File.chmod(mode, @parent[:path])
rescue => detail
error = Puppet::Error.new("failed to chmod %s: %s" %
[@parent[:path], detail.message])
diff --git a/lib/puppet/type/pfile/owner.rb b/lib/puppet/type/pfile/owner.rb
index 07a2b880b..d88e9d04c 100755
--- a/lib/puppet/type/pfile/owner.rb
+++ b/lib/puppet/type/pfile/owner.rb
@@ -64,21 +64,21 @@ module Puppet
end
# We want to print names, not numbers
- def is_to_s
- id2name(@is) || @is
+ def is_to_s(currentvalue)
+ id2name(currentvalue) || currentvalue
end
- def should_to_s
- case self.should
+ def should_to_s(newvalue = @should)
+ case newvalue
when Symbol
- self.should.to_s
+ newvalue.to_s
when Integer
- id2name(self.should) || self.should
+ id2name(newvalue) || newvalue
when String
- self.should
+ newvalue
else
raise Puppet::DevError, "Invalid uid type %s(%s)" %
- [self.should.class, self.should]
+ [newvalue.class, newvalue]
end
end
@@ -98,8 +98,7 @@ module Puppet
end
unless stat = @parent.stat(false)
- @is = :absent
- return
+ return :absent
end
# Set our method appropriately, depending on links.
@@ -109,15 +108,17 @@ module Puppet
@method = :chown
end
- self.is = stat.uid
-
+ currentvalue = stat.uid
+
# On OS X, files that are owned by -2 get returned as really
# large UIDs instead of negative ones. This isn't a Ruby bug,
# it's an OS X bug, since it shows up in perl, too.
- if @is > 120000
- self.warning "current state is silly: %s" % @is
- @is = :silly
+ if currentvalue > 120000
+ self.warning "current state is silly: %s" % is
+ currentvalue = :silly
end
+
+ return currentvalue
end
def sync
@@ -146,16 +147,11 @@ module Puppet
return nil
end
- if @is == :absent
- @parent.stat(true)
- self.retrieve
- if @is == :absent
+ unless @parent.stat(false)
+ unless @parent.stat(true)
self.debug "File does not exist; cannot set owner"
return nil
end
- if self.insync?
- return nil
- end
#self.debug "%s: after refresh, is '%s'" % [self.class.name,@is]
end
diff --git a/lib/puppet/type/pfile/source.rb b/lib/puppet/type/pfile/source.rb
index d007ea301..84e3eb032 100755
--- a/lib/puppet/type/pfile/source.rb
+++ b/lib/puppet/type/pfile/source.rb
@@ -60,9 +60,9 @@ module Puppet
source.sub(/\/$/, '')
end
- def change_to_s
- should = "{md5}" + @stats[:checksum]
- if @parent.is(:ensure) == :absent
+ def change_to_s(currentvalue, newvalue)
+ # newvalue = "{md5}" + @stats[:checksum]
+ if @parent.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]]
@@ -116,17 +116,17 @@ module Puppet
# Have we successfully described the remote source?
def described?
- ! @stats.nil? and ! @stats[:type].nil? and @is != :notdescribed
+ ! @stats.nil? and ! @stats[:type].nil? #and @is != :notdescribed
end
# Use the info we get from describe() to check if we're in sync.
- def insync?
+ def insync?(currentvalue)
unless described?
info "No specified sources exist"
return true
end
- if @is == :nocopy
+ if currentvalue == :nocopy
return true
end
@@ -136,11 +136,15 @@ module Puppet
return true
end
- if @parent.is(:ensure) != :absent and ! @parent.replace?
+ #FIXARB: Inefficient? Needed to call retrieve on parent's ensure and checksum
+ parentensure = @parent.property(:ensure).retrieve
+ if parentensure != :absent and ! @parent.replace?
return true
end
# Now, we just check to see if the checksums are the same
- return @parent.is(:checksum) == @stats[:checksum]
+ parentchecksum = @parent.property(:checksum).retrieve
+ a = (!parentchecksum.nil? and (parentchecksum == @stats[:checksum]))
+ return (!parentchecksum.nil? and (parentchecksum == @stats[:checksum]))
end
def pinparams
@@ -169,8 +173,7 @@ module Puppet
end
if @stats.nil? or @stats[:type].nil?
- @is = :notdescribed
- return nil
+ return nil # :notdescribed
end
case @stats[:type]
@@ -182,8 +185,7 @@ module Puppet
self.info @stats.inspect
self.err "Cannot use files of type %s as sources" %
@stats[:type]
- @is = :nocopy
- return
+ return :nocopy
end
# Take each of the stats and set them as states on the local file
@@ -196,11 +198,11 @@ module Puppet
# be inherited from the source?
unless @parent.argument?(stat)
@parent[stat] = value
- @parent.property(stat).retrieve
+ @parent.property(stat).retrieve # FIXARB: This is calling retrieve on all propertis of File. What are we gonna do with the return values?
end
}
- @is = @stats[:checksum]
+ return @stats[:checksum]
end
def should
@@ -223,7 +225,7 @@ module Puppet
def sync
unless @stats[:type] == "file"
#if @stats[:type] == "directory"
- #[@parent.name, @is.inspect, @should.inspect]
+ #[@parent.name, @should.inspect]
#end
raise Puppet::DevError, "Got told to copy non-file %s" %
@parent[:path]
diff --git a/lib/puppet/type/pfile/target.rb b/lib/puppet/type/pfile/target.rb
index c3c9031ec..8913eb86f 100644
--- a/lib/puppet/type/pfile/target.rb
+++ b/lib/puppet/type/pfile/target.rb
@@ -15,7 +15,8 @@ module Puppet
end
# Only call mklink if ensure() didn't call us in the first place.
- if @parent.property(:ensure).insync?
+ currentensure = @parent.property(:ensure).retrieve
+ if @parent.property(:ensure).insync?(currentensure)
mklink()
end
end
@@ -48,23 +49,24 @@ module Puppet
end
end
- def insync?
+ def insync?(currentvalue)
if [:nochange, :notlink].include?(self.should) or @parent.recurse?
return true
else
- return super
+ return super(currentvalue)
end
end
+
def retrieve
if stat = @parent.stat
if stat.ftype == "link"
- @is = File.readlink(@parent[:path])
+ return File.readlink(@parent[:path])
else
- @is = :notlink
+ return :notlink
end
else
- @is = :absent
+ return :absent
end
end
end
diff --git a/lib/puppet/type/pfile/type.rb b/lib/puppet/type/pfile/type.rb
index 5f720ac9c..4c2783c71 100755
--- a/lib/puppet/type/pfile/type.rb
+++ b/lib/puppet/type/pfile/type.rb
@@ -8,14 +8,13 @@ module Puppet
#end
def retrieve
+ currentvalue = :absent
if stat = @parent.stat(false)
- @is = stat.ftype
- else
- @is = :absent
+ currentvalue = stat.ftype
end
-
# so this state is never marked out of sync
- @should = [@is]
+ @should = [currentvalue]
+ return currentvalue
end
diff --git a/lib/puppet/type/property.rb b/lib/puppet/type/property.rb
index 5c4babf38..065da6452 100644
--- a/lib/puppet/type/property.rb
+++ b/lib/puppet/type/property.rb
@@ -1,4 +1,4 @@
-# The virtual base class for properties, which are the self-contained building
+ # The virtual base class for properties, which are the self-contained building
# blocks for actually doing work on the system.
require 'puppet'
@@ -8,7 +8,6 @@ require 'puppet/parameter'
module Puppet
class Property < Puppet::Parameter
- attr_accessor :is
# Because 'should' uses an array, we have a special method for handling
# it. We also want to keep copies of the original values, so that
@@ -143,7 +142,7 @@ class Property < Puppet::Parameter
def call_valuemethod(name, value)
event = nil
if method = self.class.value_option(name, :method) and self.respond_to?(method)
- self.debug "setting %s (currently %s)" % [value, self.is]
+ self.debug "setting %s (currently %s)" % [value, self.retrieve]
begin
event = self.send(method)
@@ -169,17 +168,17 @@ class Property < Puppet::Parameter
end
# How should a property change be printed as a string?
- def change_to_s
+ def change_to_s(currentvalue, newvalue)
begin
- if @is == :absent
+ if currentvalue == :absent
return "defined '%s' as '%s'" %
- [self.name, self.should_to_s]
- elsif self.should == :absent or self.should == [:absent]
+ [self.name, self.should_to_s(newvalue)]
+ elsif newvalue == :absent or newvalue == [:absent]
return "undefined %s from '%s'" %
- [self.name, self.is_to_s]
+ [self.name, self.is_to_s(currentvalue)]
else
return "%s changed '%s' to '%s'" %
- [self.name, self.is_to_s, self.should_to_s]
+ [self.name, self.is_to_s(currentvalue), self.should_to_s(newvalue)]
end
rescue Puppet::Error, Puppet::DevError
raise
@@ -219,17 +218,11 @@ class Property < Puppet::Parameter
# initialize our property
def initialize(hash = {})
- @is = nil
super
end
def inspect
str = "Property('%s', " % self.name
- if self.is
- str += "@is = '%s', " % [self.is]
- else
- str += "@is = nil, "
- end
if defined? @should and @should
str += "@should = '%s')" % @should.join(", ")
@@ -244,7 +237,7 @@ class Property < Puppet::Parameter
# since we cannot fix it. Otherwise, we expect our should value
# to be an array, and if @is matches any of those values, then
# we consider it to be in-sync.
- def insync?
+ def insync?(is)
#debug "%s value is '%s', should be '%s'" %
# [self,self.is.inspect,self.should.inspect]
unless defined? @should and @should
@@ -262,7 +255,7 @@ class Property < Puppet::Parameter
# Look for a matching value
@should.each { |val|
- if @is == val or @is == val.to_s
+ if is == val or is == val.to_s
return true
end
}
@@ -275,8 +268,8 @@ class Property < Puppet::Parameter
# we need to set up a mechanism for pretty printing of the values
# default to just the values, but this way individual properties can
# override these methods
- def is_to_s
- @is
+ def is_to_s(currentvalue)
+ currentvalue
end
# Send a log message.
@@ -317,7 +310,10 @@ class Property < Puppet::Parameter
# provider. In other words, if the property name is 'gid', we'll call
# 'provider.gid' to retrieve the current value.
def retrieve
- @is = provider.send(self.class.name)
+ is = provider.send(self.class.name)
+# puts "IS is: " + is.to_s
+# puts "and its an array!!!" if is.is_a? Array
+ return is
end
# Set our value, using the provider, an associated block, or both.
@@ -383,9 +379,10 @@ class Property < Puppet::Parameter
end
end
- def should_to_s
- if defined? @should
- @should.join(" ")
+ def should_to_s(newvalue)
+ newvalue = [newvalue] unless newvalue.is_a? Array
+ if defined? newvalue
+ newvalue.join(" ")
else
return nil
end
@@ -394,10 +391,10 @@ class Property < Puppet::Parameter
# The default 'sync' method only selects among a list of registered
# values.
def sync
- if self.insync?
- self.info "already in sync"
- return nil
- end
+# if self.insync?
+# self.info "already in sync"
+# return nil
+# end
unless self.class.values
self.devfail "No values defined for %s" %
self.class.name
@@ -474,15 +471,15 @@ class Property < Puppet::Parameter
end
end
- def change_to_s
+ def change_to_s(currentvalue, newvalue)
begin
- if @is == :absent or @is.nil?
+ if currentvalue == :absent or currentvalue.nil?
return "created"
- elsif self.should == :absent
+ elsif newvalue == :absent
return "removed"
else
return "%s changed '%s' to '%s'" %
- [self.name, self.is_to_s, self.should_to_s]
+ [self.name, self.is_to_s(currentvalue), self.should_to_s(newvalue)]
end
rescue Puppet::Error, Puppet::DevError
raise
@@ -507,9 +504,9 @@ class Property < Puppet::Parameter
@parent.class.name
end
if result
- @is = :present
+ return :present
else
- @is = :absent
+ return :absent
end
end
diff --git a/lib/puppet/type/resources.rb b/lib/puppet/type/resources.rb
index a3f6574d8..5778460a5 100644
--- a/lib/puppet/type/resources.rb
+++ b/lib/puppet/type/resources.rb
@@ -129,13 +129,13 @@ Puppet::Type.newtype(:resources) do
return true unless self[:unless_system_user]
resource[:check] = :uid
- resource.retrieve
+ current_values = resource.retrieve
if system_users().include?(resource[:name])
return false
end
- if resource.is(:uid) <= self[:unless_system_user]
+ if current_values[resource.property(:uid)] <= self[:unless_system_user]
return false
else
return true
diff --git a/lib/puppet/type/service.rb b/lib/puppet/type/service.rb
index 0fdd04928..1f04c0246 100644
--- a/lib/puppet/type/service.rb
+++ b/lib/puppet/type/service.rb
@@ -55,7 +55,7 @@ module Puppet
raise Puppet::Error, "Service %s does not support enabling" %
@parent.name
end
- @is = provider.enabled?
+ return provider.enabled?
end
validate do |value|
@@ -116,7 +116,7 @@ module Puppet
aliasvalue(:true, :running)
def retrieve
- self.is = provider.status
+ return provider.status
end
def sync
@@ -313,8 +313,9 @@ module Puppet
# to events.
def refresh
# Only restart if we're supposed to be running
- if ens = @parameters[:ensure] and ens.should == :running and ens.is == :running
- provider.restart
+
+ if ens = @parameters[:ensure] and ens.should == :running and ens.retrieve == :running
+ provider.restart
end
end
end
diff --git a/lib/puppet/type/sshkey.rb b/lib/puppet/type/sshkey.rb
index f6622c510..6abbf2de8 100755
--- a/lib/puppet/type/sshkey.rb
+++ b/lib/puppet/type/sshkey.rb
@@ -28,11 +28,10 @@ module Puppet
make those aliases available in your Puppet scripts."
attr_accessor :meta
-
- def insync?
- @is == @should
- end
+ def insync?(is)
+ is == @should
+ end
# We actually want to return the whole array here, not just the first
# value.
def should
diff --git a/lib/puppet/type/tidy.rb b/lib/puppet/type/tidy.rb
index 2827c1be3..2750f3113 100755
--- a/lib/puppet/type/tidy.rb
+++ b/lib/puppet/type/tidy.rb
@@ -27,7 +27,7 @@ module Puppet
defaultto :anything # just so we always get this property
- def change_to_s
+ def change_to_s(currentvalue, newvalue)
start = "Tidying"
if @out.include?(:age)
start += ", older than %s seconds" % @parent.should(:age)
@@ -39,9 +39,9 @@ module Puppet
start
end
- def insync?
- if @is.is_a?(Symbol)
- if [:absent, :notidy].include?(@is)
+ def insync?(is)
+ if is.is_a?(Symbol)
+ if [:absent, :notidy].include?(is)
return true
else
return false
@@ -50,11 +50,13 @@ module Puppet
@out = []
TATTRS.each do |param|
if property = @parent.property(param)
- unless property.insync?
+ self.debug "No is value for %s", [param] if is[property].nil?
+ unless property.insync?(is[property])
@out << param
end
end
end
+
if @out.length > 0
return false
else
@@ -62,24 +64,24 @@ module Puppet
end
end
end
-
+
def retrieve
stat = nil
unless stat = @parent.stat
- @is = :absent
- return
+ return { self => :absent}
end
if stat.ftype == "directory" and ! @parent[:rmdirs]
- @is = :notidy
- return
+ return {self => :notidy}
end
- TATTRS.each { |param|
+ allprops = TATTRS.inject({}) { |prophash, param|
if property = @parent.property(param)
- property.is = property.assess(stat)
+ prophash[property] = property.assess(stat)
end
+ prophash
}
+ return { self => allprops }
end
def sync
@@ -150,8 +152,8 @@ module Puppet
end
end
- def insync?
- if (Time.now.to_i - @is) > self.should
+ def insync?(is)
+ if (Time.now.to_i - is) > self.should
return false
end
@@ -204,8 +206,8 @@ module Puppet
end
end
- def insync?
- if @is > self.should
+ def insync?(is)
+ if is > self.should
return false
end
@@ -277,7 +279,11 @@ module Puppet
def retrieve
# Our ensure property knows how to retrieve everything for us.
- obj = @parameters[:ensure] and obj.retrieve
+ if obj = @parameters[:ensure]
+ return obj.retrieve
+ else
+ return {}
+ end
end
# Hack things a bit so we only ever check the ensure property.
diff --git a/lib/puppet/type/user.rb b/lib/puppet/type/user.rb
index c85c0368e..4bbb5b233 100755
--- a/lib/puppet/type/user.rb
+++ b/lib/puppet/type/user.rb
@@ -43,15 +43,16 @@ module Puppet
end
end
- def change_to_s
+ # FIXARB: Check this... I think it is exactly the same as the Ensure classes.
+ def change_to_s(currentvalue, newvalue)
begin
- if @is == :absent
+ if currentvalue == :absent
return "created"
- elsif self.should == :absent
+ elsif newvalue == :absent
return "removed"
else
return "%s changed '%s' to '%s'" %
- [self.name, self.is_to_s, self.should_to_s]
+ [self.name, self.is_to_s(currentvalue), self.should_to_s(newvalue)]
end
rescue Puppet::Error, Puppet::DevError
raise
@@ -64,21 +65,21 @@ module Puppet
def retrieve
if provider.exists?
- @is = :present
+ return :present
else
- @is = :absent
+ return :absent
end
end
# The default 'sync' method only selects among a list of registered
# values.
def sync
- if self.insync?
- self.info "already in sync"
- return nil
+# if self.insync?
+# self.info "already in sync"
+# return nil
#else
#self.info "%s vs %s" % [self.is.inspect, self.should.inspect]
- end
+# end
unless self.class.values
self.devfail "No values defined for %s" %
self.class.name
@@ -185,20 +186,19 @@ module Puppet
group should not be listed. Multiple groups should be
specified as an array."
- def should_to_s
+ # FIXARB: Whoa... That should method requires is?
+ def should_to_s(newvalue = @should)
self.should
end
- def is_to_s
- @is.join(",")
+ def is_to_s(currentvalue)
+ currentvalue.join(",")
end
# We need to override this because the groups need to
# be joined with commas
def should
- unless defined? @is
- retrieve
- end
+ current_value = retrieve
unless defined? @should and @should
return nil
@@ -208,31 +208,31 @@ module Puppet
return @should.sort.join(",")
else
members = @should
- if @is.is_a?(Array)
- members += @is
+ if current_value.is_a?(Array)
+ members += current_value
end
return members.uniq.sort.join(",")
end
end
def retrieve
- if tmp = provider.groups
- @is = tmp.split(",")
+ if tmp = provider.groups and tmp != :absent
+ return tmp.split(",")
else
- @is = :absent
+ return :absent
end
end
- def insync?
+ def insync?(is)
unless defined? @should and @should
return true
end
- unless defined? @is and @is
+ unless defined? is and is
return true
end
- tmp = @is
- if @is.is_a? Array
- tmp = @is.sort.join(",")
+ tmp = is
+ if is.is_a? Array
+ tmp = is.sort.join(",")
end
return tmp == self.should
@@ -361,17 +361,21 @@ module Puppet
def retrieve
absent = false
- properties().each { |property|
+ properties().inject({}) { |prophash, property|
+ current_value = :absent
+
if absent
- property.is = :absent
+ prophash[property] = :absent
else
- property.retrieve
+ current_value = property.retrieve
+ prophash[property] = current_value
end
- if property.name == :ensure and property.is == :absent
+ if property.name == :ensure and current_value == :absent
absent = true
- next
+# next
end
+ prophash
}
end
end
diff --git a/lib/puppet/type/yumrepo.rb b/lib/puppet/type/yumrepo.rb
index 94ba3ef6c..cad411544 100644
--- a/lib/puppet/type/yumrepo.rb
+++ b/lib/puppet/type/yumrepo.rb
@@ -7,16 +7,16 @@ require 'puppet/type/parsedtype'
module Puppet
# A property for one entry in a .ini-style file
class IniProperty < Puppet::Property
- def insync?
+ def insync?(is)
# A should property of :absent is the same as nil
if is.nil? && (should.nil? || should == :absent)
return true
end
- return super
+ return super(is)
end
def sync
- if insync?
+ if insync?(retrieve)
result = nil
else
result = set(self.should)
@@ -30,7 +30,7 @@ module Puppet
end
def retrieve
- @is = parent.section[inikey]
+ return parent.section[inikey]
end
def inikey
@@ -88,12 +88,12 @@ module Puppet
inifile.each_section do |s|
next if s.name == "main"
obj = create(:name => s.name, :check => check)
- obj.retrieve
+ current_values = obj.retrieve
obj.eachproperty do |property|
- if property.is.nil?
+ if current_values[property].nil?
obj.delete(property.name)
else
- property.should = property.is
+ property.should = current_values[property]
end
end
obj.delete(:check)
diff --git a/lib/puppet/type/zone.rb b/lib/puppet/type/zone.rb
index 35d2a3d87..48f4a90bb 100644
--- a/lib/puppet/type/zone.rb
+++ b/lib/puppet/type/zone.rb
@@ -15,23 +15,25 @@ Puppet::Type.newtype(:zone) do
class ZoneMultiConfigProperty < ZoneConfigProperty
def configtext
list = @should
+
+ current_value = self.retrieve
- unless @is.is_a? Symbol
- if @is.is_a? Array
- list += @is
+ unless current_value.is_a? Symbol
+ if current_value.is_a? Array
+ list += current_vlue
else
- if @is
- list << @is
+ if current_value
+ list << current_value
end
end
end
- # Some hackery so we can test whether @is is an array or a symbol
- if @is.is_a? Array
- tmpis = @is
+ # Some hackery so we can test whether current_value is an array or a symbol
+ if current_value.is_a? Array
+ tmpis = current_value
else
- if @is
- tmpis = [@is]
+ if current_value
+ tmpis = [current_value]
else
tmpis = []
end
@@ -56,11 +58,11 @@ Puppet::Type.newtype(:zone) do
end
# We want all specified directories to be included.
- def insync?
- if @is.is_a? Array and @should.is_a? Array
- @is.sort == @should.sort
+ def insync?(current_value)
+ if current_value.is_a? Array and @should.is_a? Array
+ current_value.sort == @should.sort
else
- @is == @should
+ current_value == @should
end
end
end
@@ -124,11 +126,6 @@ Puppet::Type.newtype(:zone) do
list[1..-1]
end
- def is=(value)
- value = value.intern if value.is_a? String
- @is = value
- end
-
def sync
method = nil
if up?
@@ -139,8 +136,6 @@ Puppet::Type.newtype(:zone) do
# We need to get the state we're currently in and just call
# everything between it and us.
- states = self.class.valueslice(self.is, self.should)
-
properties.each do |prop|
if method = prop[dir]
warned = false
@@ -163,7 +158,8 @@ Puppet::Type.newtype(:zone) do
# Are we moving up the property tree?
def up?
- self.class.valueindex(self.is) < self.class.valueindex(self.should)
+ current_value = self.retrieve
+ self.class.valueindex(current_value) < self.class.valueindex(self.should)
end
end
@@ -386,56 +382,58 @@ set zonepath=%s
def retrieve
if hash = provider.statushash()
- setstatus(hash)
+ prophash = setstatus(hash)
# Now retrieve the configuration itself and set appropriately.
- config2status(provider.getconfig())
+ return config2status(provider.getconfig(), prophash)
else
- properties().each do |pr|
- pr.is = :absent
- end
+ return currentpropvalues(:absent)
end
end
# Take the results of a listing and set everything appropriately.
def setstatus(hash)
+ prophash = {}
hash.each do |param, value|
next if param == :name
case self.class.attrtype(param)
- when :pr:
- self.is = [param, value]
+ when :property:
+ prophash[self.property(param)] = value
else
self[param] = value
end
end
+ return prophash
end
private
# Turn the results of getconfig into status information.
- def config2status(config)
+ def config2status(config, prophash)
config.each do |name, value|
case name
when :autoboot:
- self.is = [:autoboot, value.intern]
+ prophash[self.property(:autoboot)] = value.intern
when :zonepath:
# Nothing; this is set in the zoneadm list command
when :pool:
- self.is = [:pool, value]
+ prophash[self.property(:pool)] = value
when :shares:
- self.is = [:shares, value]
+ prophash[self.property(:shares)] = value
when "inherit-pkg-dir":
dirs = value.collect do |hash|
hash[:dir]
end
- self.is = [:inherit, dirs]
+ prophash[self.property(:inherit)] = dirs
when "net":
vals = value.collect do |hash|
"%s:%s" % [hash[:physical], hash[:address]]
end
- self.is = [:ip, vals]
+ prophash[self.proeprty(:ip)] = vals
end
end
+
+ return prophash
end
end