(Markus and I have been pairing and chatting on this, and I'm taking
this to email and, thus, public.)
I've just pushed an update to my 'feature/event_manager/
resource_harness' branch (which is based on my event_manager branch),
with a mostly-functional resource harness class. For those following
along at home, this class will handle all of the per-resource
transactional behaviour (retrieve, compare, sync), simplifying the
transaction class and simplifying creation of a resource 'status'
class, for reporting.
Here's the current state of the harness class; please comment:
require 'puppet/resource/status'
class Puppet::Transaction::ResourceHarness
attr_reader :transaction, :resource
def apply_changes(status, changes)
changes.each do |change|
status << change.apply
end
status.changed = true
end
def changes_to_perform(status, current)
if param = resource.parameter(:ensure)
insync = param.insync?(current[:ensure])
return [Puppet::Transaction::Change.new(param,
current[:ensure])] unless insync
return [] if param.should == :absent
end
resource.properties.reject { |p| p.name == :ensure }.find_all
{ |param| ! param.insync?(current[param.name]) }.collect do |param|
Puppet::Transaction::Change.new(param, current[param.name])
end
end
def evaluate
status = Puppet::Resource::Status.new(resource)
if !skip? and changes = changes_to_perform(status,
resource.retrieve)
status.out_of_sync = true
apply_changes(status, changes)
end
return status
rescue => detail
resource.fail "Could not create resource status: #{detail}"
unless status
resource.err "Could not evaluate: #{detail}"
status.failed = true
return status
end
def initialize(transaction, resource)
@transaction = transaction
@resource = resource
end
end
--
I'm worried about Bart. Today, he's sucking people's blood,
tommorrow he might be smoking. -Marge Simpson
---------------------------------------------------------------------
Luke Kanies -|- http://reductivelabs.com -|- +1(615)594-8199
--
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-dev?hl=en.