Hello What you're proposing looks very closed to the proposed patch (mainly for the same reasons). My only concerns are: - What informations do you plan to add to the transaction reports? - What the output of 'puppetd --changes' will look like?
As far as those two points are ok with us, we are fine with any patch. Do you have some bit of code for those 2 features? Thanks Aurelien -------- Message d'origine-------- De: puppet-dev@googlegroups.com de la part de Luke Kanies Date: ven. 10/07/2009 18:22 À: puppet-dev@googlegroups.com Objet : [Puppet-dev] Re: [PATCH/puppet 1/1] Feature #2400 : add display changes and add them in YAML to the report I like the basic idea here, and as you discerned, I'm working on something similar. There are a couple of straightforward issues (e.g., I can't seem to find the code that actually adds the changes to the transaction, and the output would be better in an easily-machine readable form like yaml or json), but the biggest problem is that we want this information in the reports, but it has to be done in a way that keeps references to all of the resources from leaking into the reports. Change objects have references to parameters, which have references to resources and catalogs and all that, so adding them directly to reports and then serializing those reports will result in your reports being, um, gigantic. My plan instead has always been to have the changes create Events (which they already do) and have those events contain all of the important information from changes but as strings instead of references (which they don't). Then you just have the transactions collect all of the events, and serializing those events to send to the server or print on the console is very easy because the plain data should print well as yaml, json, etc. What do you think? On Jul 10, 2009, at 12:10 AM, Stéphan Gorget wrote: > > Signed-off-by: Stéphan Gorget <gor...@ocre.cea.fr> > --- > lib/puppet/defaults.rb | 4 ++- > lib/puppet/resource/catalog.rb | 2 +- > lib/puppet/transaction.rb | 7 ++++++ > lib/puppet/transaction/report.rb | 39 +++++++++++++++++++++++++++++ > ++++++++- > 4 files changed, 49 insertions(+), 3 deletions(-) > > diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb > index b2de823..88162ae 100644 > --- a/lib/puppet/defaults.rb > +++ b/lib/puppet/defaults.rb > @@ -628,7 +628,9 @@ module Puppet > being evaluated. This allows you to interactively see > exactly > what is being done."], > :summarize => [false, > - "Whether to print a transaction summary." > + "Whether to print a transaction summary."], > + :changes => [false, > + "Whether to print the transaction changes." > ] > ) > > diff --git a/lib/puppet/resource/catalog.rb b/lib/puppet/resource/ > catalog.rb > index 42e92f4..4cd3ba1 100644 > --- a/lib/puppet/resource/catalog.rb > +++ b/lib/puppet/resource/catalog.rb > @@ -151,7 +151,7 @@ class Puppet::Resource::Catalog < > Puppet::SimpleGraph > > yield transaction if block_given? > > - transaction.send_report if host_config and (Puppet[:report] > or Puppet[:summarize]) > + transaction.send_report if host_config and (Puppet[:report] > or Puppet[:summarize] or Puppet[:changes]) > > return transaction > ensure > diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb > index f09ca80..06c3c73 100644 > --- a/lib/puppet/transaction.rb > +++ b/lib/puppet/transaction.rb > @@ -512,6 +512,13 @@ class Transaction > report.graph() > end > > + report.changes = report.sumup(@events) > + if Puppet[:changes] > + unless report.changes.empty? > + puts report.displaychanges > + end > + end > + > if Puppet[:summarize] > puts report.summary > end > diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/ > transaction/report.rb > index e5b8650..77b8aec 100644 > --- a/lib/puppet/transaction/report.rb > +++ b/lib/puppet/transaction/report.rb > @@ -10,7 +10,7 @@ class Puppet::Transaction::Report > > indirects :report, :terminus_class => :processor > > - attr_accessor :logs, :metrics, :time, :host > + attr_accessor :logs, :metrics, :time, :host, :changes > > # This is necessary since Marshall doesn't know how to > # dump hash with default proc (see below @records) > @@ -58,6 +58,29 @@ class Puppet::Transaction::Report > @records[metric] << object > end > > + # Provide a summary of the changes > + def displaychanges > + ret = "" > + > + # display the different changes for each type > + changes.keys.sort.each { |t| > + ret += "%s:\n" % t > + changes[t].keys.sort.each { |e| > + # Count the number of occurences for each value in > the changes[t][e] > + count = changes[t][e].inject(Hash.new(0)) {|h,i| > h[i] += 1; h } > + ret += count.to_a.collect { |c, count| > + if count > 1 > + " %15s %s (%s)" % [c + ":", e, count] > + else > + " %15s %s" % [c + ":", e] > + end > + }.join("\n") > + ret += "\n" > + } > + } > + return ret > + end > + > # Provide a summary of this report. > def summary > ret = "" > @@ -83,5 +106,19 @@ class Puppet::Transaction::Report > end > return ret > end > + > + # Copy events in a structure that can be return with the report > + def sumup(events) > + report= {} > + events.each { |e| > + type = e.source.class.name.to_s.capitalize > + title = e.source.title.to_s > + change = e.name.to_s > + report[type] = {} if !report[type].is_a?(Hash) > + report[type][title] = [] if !report[type][title].is_a? > (Array) > + report[type][title].push(change) > + } > + report > + end > end > > -- > 1.6.2.2 > > > > -- I think that's how Chicago got started. A bunch of people in New York said, 'Gee, I'm enjoying the crime and the poverty, but it just isn't cold enough. Let's go west.' --Richard Jeni --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to puppet-dev@googlegroups.com To unsubscribe from this group, send email to puppet-dev+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en -~----------~----~----~----~------~----~------~--~---
<<inline: winmail.dat>>