2
# this method is responsible for collecting state changes
3
# we always descend into the children before we evaluate our current
5
# this returns any changes resulting from testing, thus 'collect'
2
# This method is responsible for collecting property changes we always
3
# descend into the children before we evaluate our current properties.
4
# This returns any changes resulting from testing, thus 'collect' rather
7
if self.provider.is_a?(Puppet::Provider)
8
unless provider.class.suitable?
9
raise Puppet::Error, "Provider %s is not functional on this platform" % provider.class.name
8
12
#Puppet.err "Evaluating %s" % self.path.join(":")
9
13
unless defined? @evalcount
10
14
self.err "No evalcount defined on '%s' of type '%s'" %
20
if p = self.provider and p.respond_to?(:prefetch)
18
# this only operates on states, not states + children
24
# this only operates on properties, not properties + children
19
25
# it's important that we call retrieve() on the type instance,
20
# not directly on the state, because it allows the type to override
26
# not directly on the property, because it allows the type to override
21
27
# the method, like pfile does
24
# states() is a private method, returning an ordered list
25
unless self.class.depthfirst?
26
changes += statechanges()
29
changes << @children.collect { |child|
31
child.cache(:checked, Time.now)
35
if self.class.depthfirst?
36
changes += statechanges()
28
currentvalues = self.retrieve
30
changes = propertychanges(currentvalues).flatten
41
32
# now record how many changes we've resulted in
42
33
if changes.length > 0
43
34
self.debug "%s change(s)" %
46
self.cache(:checked, Time.now)
38
# If we're in noop mode, we don't want to store the checked time,
39
# because it will result in the resource not getting scheduled if
40
# someone were to apply the catalog in non-noop mode.
41
# We're going to go ahead and record that we checked if there were
42
# no changes, since it's unlikely it will affect the scheduling.
44
if ! noop or (noop && changes.length == 0)
45
self.cache(:checked, Time.now)
47
47
return changes.flatten
50
# By default, try flushing the provider.
50
# Flush the provider, if it supports it. This is called by the
52
53
if self.provider and self.provider.respond_to?(:flush)
53
54
self.provider.flush
57
58
# if all contained objects are in sync, then we're in sync
58
59
# FIXME I don't think this is used on the type instances any more,
59
60
# it's really only used for testing
63
if state = @states[:ensure]
64
if state.insync? and state.should == :absent
64
if property = @parameters[:ensure]
65
unless is.include? property
66
raise Puppet::DevError,
67
"The is value is not in the is array for '%s'" %
70
ensureis = is[property]
71
if property.insync?(ensureis) and property.should == :absent
71
state.debug("Not in sync: %s vs %s" %
72
[state.is.inspect, state.should.inspect])
76
properties.each { |property|
77
unless is.include? property
78
raise Puppet::DevError,
79
"The is value is not in the is array for '%s'" %
84
unless property.insync?(propis)
85
property.debug("Not in sync: %s vs %s" %
86
[propis.inspect, property.should.inspect])
75
# state.debug("In sync")
89
# property.debug("In sync")
79
93
#self.debug("%s sync status is %s" % [self,insync])
83
# retrieve the current value of all contained states
97
# retrieve the current value of all contained properties
99
return currentpropvalues
102
# get a hash of the current properties.
103
def currentpropvalues(override_value = nil)
85
104
# it's important to use the method here, as it follows the order
86
105
# in which they're defined in the object
87
states().each { |state|
92
# Retrieve the changes associated with all of the states.
106
return properties().inject({}) { | prophash, property|
107
prophash[property] = override_value.nil? ?
114
# Are we running in noop mode?
127
# Retrieve the changes associated with all of the properties.
128
def propertychanges(currentvalues)
94
129
# If we are changing the existence of the object, then none of
95
# the other states matter.
130
# the other properties matter.
97
if @states.include?(:ensure) and ! @states[:ensure].insync?
98
#self.info "ensuring %s from %s" %
99
# [@states[:ensure].should, @states[:ensure].is]
100
changes = [Puppet::StateChange.new(@states[:ensure])]
101
# Else, if the 'ensure' state is correctly absent, then do
132
ensureparam = @parameters[:ensure]
134
# This allows resource types to have 'ensure' be a parameter, which allows them to
135
# just pass the parameter on to other generated resources.
136
ensureparam = nil unless ensureparam.is_a?(Puppet::Property)
137
if ensureparam && !currentvalues.include?(ensureparam)
138
raise Puppet::DevError, "Parameter ensure defined but missing from current values"
141
if ensureparam and ! ensureparam.insync?(currentvalues[ensureparam])
142
changes << Puppet::Transaction::Change.new(ensureparam, currentvalues[ensureparam])
143
# Else, if the 'ensure' property is correctly absent, then do
103
elsif @states.include?(:ensure) and @states[:ensure].is == :absent
104
#self.info "Object is correctly absent"
145
elsif ensureparam and currentvalues[ensureparam] == :absent
107
#if @states.include?(:ensure)
108
# self.info "ensure: Is: %s, Should: %s" %
109
# [@states[:ensure].is, @states[:ensure].should]
111
# self.info "no ensure state"
113
changes = states().find_all { |state|
116
Puppet::StateChange.new(state)
148
changes = properties().find_all { |property|
149
currentvalues[property] ||= :absent
150
! property.insync?(currentvalues[property])
151
}.collect { |property|
152
Puppet::Transaction::Change.new(property, currentvalues[property])
120
156
if Puppet[:debug] and changes.length > 0
121
self.debug("Changing " + changes.collect { |ch|
157
self.debug("Changing " + changes.collect { |ch| ch.property.name }.join(","))
131
# $Id: evaluation.rb 1856 2006-11-11 07:40:16Z luke $