summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRick Bradley <rick@rickbradley.com>2007-10-13 17:52:06 -0500
committerRick Bradley <rick@rickbradley.com>2007-10-13 17:52:06 -0500
commit8c935deed405299c304ccbe370c9240fda63cafb (patch)
treeba75be429bf71195cf7c4e6fc379a9e94d61912c /lib
parente90191af9300fda00cd29d609ac80daff00332cc (diff)
parent694f98b4d9e7172cec58d407bc5aeae7861e1a06 (diff)
downloadpuppet-8c935deed405299c304ccbe370c9240fda63cafb.tar.gz
puppet-8c935deed405299c304ccbe370c9240fda63cafb.tar.xz
puppet-8c935deed405299c304ccbe370c9240fda63cafb.zip
Merge branch 'master' of git://reductivelabs.com/puppet into routing
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/indirector.rb4
-rw-r--r--lib/puppet/indirector/code/configuration.rb20
-rw-r--r--lib/puppet/indirector/code/report.rb49
-rw-r--r--lib/puppet/indirector/indirection.rb6
-rwxr-xr-xlib/puppet/network/handler/report.rb70
-rw-r--r--lib/puppet/node/configuration.rb6
-rwxr-xr-xlib/puppet/reports.rb51
-rw-r--r--lib/puppet/reports/log.rb4
-rw-r--r--lib/puppet/reports/rrdgraph.rb4
-rw-r--r--lib/puppet/reports/store.rb6
-rw-r--r--lib/puppet/reports/tagmail.rb2
-rw-r--r--lib/puppet/transaction/report.rb5
-rw-r--r--lib/puppet/transportable.rb2
13 files changed, 146 insertions, 83 deletions
diff --git a/lib/puppet/indirector.rb b/lib/puppet/indirector.rb
index a2eb41763..6009a7ba7 100644
--- a/lib/puppet/indirector.rb
+++ b/lib/puppet/indirector.rb
@@ -59,6 +59,10 @@ module Puppet::Indirector
def search(*args)
indirection.search(*args)
end
+
+ def version(*args)
+ indirection.version(*args)
+ end
end
module InstanceMethods
diff --git a/lib/puppet/indirector/code/configuration.rb b/lib/puppet/indirector/code/configuration.rb
index 949926a3c..50728757c 100644
--- a/lib/puppet/indirector/code/configuration.rb
+++ b/lib/puppet/indirector/code/configuration.rb
@@ -47,15 +47,19 @@ class Puppet::Indirector::Code::Configuration < Puppet::Indirector::Code
$0 =~ /puppetmasterd/
end
- # Return the configuration version.
- def version(client = nil, clientip = nil)
- if client and node = Puppet::Node.search(client)
- update_node_check(node)
- return interpreter.configuration_version(node)
+ # Return the configuration version. Here we're returning the
+ # latest of the node, fact, or parse date. These are the
+ # three things that go into compiling a client configuration,
+ # so changes in any of them result in changes.
+ # LAK:FIXME Note that this only works when all three sources
+ # use timestamps; once one of them moves to using real versions,
+ # the comparison stops working.
+ def version(key)
+ if node = Puppet::Node.search(key)
+ return [Puppet::Node.version(key).to_f, Puppet::Node::Facts.version(key).to_f, interpreter.configuration_version(node).to_f].sort[-1]
else
- # Just return something that will always result in a recompile, because
- # this is local.
- return (Time.now + 1000).to_i
+ # This is the standard for "got nothing for ya".
+ 0
end
end
diff --git a/lib/puppet/indirector/code/report.rb b/lib/puppet/indirector/code/report.rb
new file mode 100644
index 000000000..a3c3a6df5
--- /dev/null
+++ b/lib/puppet/indirector/code/report.rb
@@ -0,0 +1,49 @@
+require 'puppet/indirector/code'
+require 'puppet/reports'
+
+class Puppet::Indirector::Code::Report < Puppet::Indirector::Code
+ desc "Puppet's report processor. Processes the report with each of
+ the report types listed in the 'reports' setting."
+
+ def initialize
+ Puppet.settings.use(:reporting, :metrics)
+ end
+
+ def save(report)
+ process(report)
+ end
+
+ private
+
+ # Process the report with each of the configured report types.
+ # LAK:NOTE This isn't necessarily the best design, but it's backward
+ # compatible and that's good enough for now.
+ def process(report)
+ return if Puppet[:reports] == "none"
+
+ reports().each do |name|
+ if mod = Puppet::Reports.report(name)
+ # We have to use a dup because we're including a module in the
+ # report.
+ newrep = report.dup
+ begin
+ newrep.extend(mod)
+ newrep.process
+ rescue => detail
+ if Puppet[:trace]
+ puts detail.backtrace
+ end
+ Puppet.err "Report %s failed: %s" %
+ [name, detail]
+ end
+ else
+ Puppet.warning "No report named '%s'" % name
+ end
+ end
+ end
+
+ # Handle the parsing of the reports attribute.
+ def reports
+ Puppet[:reports].gsub(/(^\s+)|(\s+$)/, '').split(/\s*,\s*/)
+ end
+end
diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb
index 5f7baa3da..efa8819bb 100644
--- a/lib/puppet/indirector/indirection.rb
+++ b/lib/puppet/indirector/indirection.rb
@@ -92,6 +92,7 @@ class Puppet::Indirector::Indirection
def find(key, *args)
if cache? and cache.has_most_recent?(key, terminus.version(key))
+ Puppet.info "Using cached %s %s" % [self.name, key]
return cache.find(key, *args)
end
if result = terminus.find(key, *args)
@@ -117,10 +118,15 @@ class Puppet::Indirector::Indirection
instance.version ||= Time.now.utc
dest = cache? ? cache : terminus
return if dest.has_most_recent?(instance.name, instance.version)
+ Puppet.info "Caching %s %s" % [self.name, instance.name] if cache?
cache.save(instance, *args) if cache?
terminus.save(instance, *args)
end
+ def version(*args)
+ terminus.version(*args)
+ end
+
private
# Create a new terminus instance.
diff --git a/lib/puppet/network/handler/report.rb b/lib/puppet/network/handler/report.rb
index e202d4e2a..12abc9b15 100755
--- a/lib/puppet/network/handler/report.rb
+++ b/lib/puppet/network/handler/report.rb
@@ -1,78 +1,24 @@
require 'puppet/util/instance_loader'
+require 'puppet/reports'
# A simple server for triggering a new run on a Puppet client.
class Puppet::Network::Handler
class Report < Handler
desc "Accepts a Puppet transaction report and processes it."
- extend Puppet::Util::ClassGen
- extend Puppet::Util::InstanceLoader
-
- module ReportBase
- include Puppet::Util::Docs
- attr_writer :useyaml
-
- def useyaml?
- if defined? @useyaml
- @useyaml
- else
- false
- end
- end
- end
-
@interface = XMLRPC::Service::Interface.new("puppetreports") { |iface|
iface.add_method("string report(array)")
}
- # Set up autoloading and retrieving of reports.
- instance_load :report, 'puppet/reports'
-
- class << self
- attr_reader :hooks
- end
-
# Add a new report type.
def self.newreport(name, options = {}, &block)
- name = symbolize(name)
-
- mod = genmodule(name, :extend => ReportBase, :hash => instance_hash(:report), :block => block)
-
- if options[:useyaml]
- mod.useyaml = true
- end
-
- mod.send(:define_method, :report_name) do
- name
- end
- end
-
- # Collect the docs for all of our reports.
- def self.reportdocs
- docs = ""
-
- # Use this method so they all get loaded
- instance_loader(:report).loadall
- loaded_instances(:report).sort { |a,b| a.to_s <=> b.to_s }.each do |name|
- mod = self.report(name)
- docs += "%s\n%s\n" % [name, "-" * name.to_s.length]
-
- docs += Puppet::Util::Docs.scrub(mod.doc) + "\n\n"
- end
-
- docs
- end
-
- # List each of the reports.
- def self.reports
- instance_loader(:report).loadall
- loaded_instances(:report)
+ Puppet.warning "The interface for registering report types has changed; use Puppet::Reports.register_report for report type %s" % name
+ Puppet::Reports.register_report(name, options, &block)
end
def initialize(*args)
super
- Puppet.settings.use(:reporting)
- Puppet.settings.use(:metrics)
+ Puppet.settings.use(:reporting, :metrics)
end
# Accept a report from a client.
@@ -111,17 +57,13 @@ class Puppet::Network::Handler
client = report.host
reports().each do |name|
- if mod = self.class.report(name)
+ if mod = Puppet::Reports.report(name)
# We have to use a dup because we're including a module in the
# report.
newrep = report.dup
begin
newrep.extend(mod)
- if mod.useyaml?
- newrep.process(yaml)
- else
- newrep.process
- end
+ newrep.process
rescue => detail
if Puppet[:trace]
puts detail.backtrace
diff --git a/lib/puppet/node/configuration.rb b/lib/puppet/node/configuration.rb
index da8dc3a9a..9adf9aea3 100644
--- a/lib/puppet/node/configuration.rb
+++ b/lib/puppet/node/configuration.rb
@@ -388,8 +388,12 @@ class Puppet::Node::Configuration < Puppet::PGraph
# dumped by default, nor does yaml-dumping # the edge-labels work at this point (I don't
# know why).
# Neither of these matters right now, but I suppose it could at some point.
+ # We also have to have the vertex_dict dumped after the resource table, because yaml can't
+ # seem to handle the output of yaml-dumping the vertex_dict.
def to_yaml_properties
- instance_variables.reject { |v| %w{@edgelist_class @edge_labels}.include?(v) }
+ props = instance_variables.reject { |v| %w{@edgelist_class @edge_labels @vertex_dict}.include?(v) }
+ props << "@vertex_dict"
+ props
end
private
diff --git a/lib/puppet/reports.rb b/lib/puppet/reports.rb
new file mode 100755
index 000000000..df992d46c
--- /dev/null
+++ b/lib/puppet/reports.rb
@@ -0,0 +1,51 @@
+require 'puppet/util/instance_loader'
+
+# A simple mechanism for loading and returning reports.
+class Puppet::Reports
+ extend Puppet::Util::ClassGen
+ extend Puppet::Util::InstanceLoader
+
+ # Set up autoloading and retrieving of reports.
+ instance_load :report, 'puppet/reports'
+
+ class << self
+ attr_reader :hooks
+ end
+
+ # Add a new report type.
+ def self.register_report(name, options = {}, &block)
+ name = symbolize(name)
+
+ mod = genmodule(name, :extend => Puppet::Util::Docs, :hash => instance_hash(:report), :block => block)
+
+ if options[:useyaml]
+ mod.useyaml = true
+ end
+
+ mod.send(:define_method, :report_name) do
+ name
+ end
+ end
+
+ # Collect the docs for all of our reports.
+ def self.reportdocs
+ docs = ""
+
+ # Use this method so they all get loaded
+ instance_loader(:report).loadall
+ loaded_instances(:report).sort { |a,b| a.to_s <=> b.to_s }.each do |name|
+ mod = self.report(name)
+ docs += "%s\n%s\n" % [name, "-" * name.to_s.length]
+
+ docs += Puppet::Util::Docs.scrub(mod.doc) + "\n\n"
+ end
+
+ docs
+ end
+
+ # List each of the reports.
+ def self.reports
+ instance_loader(:report).loadall
+ loaded_instances(:report)
+ end
+end
diff --git a/lib/puppet/reports/log.rb b/lib/puppet/reports/log.rb
index 8f7b95f8b..8dfeedb07 100644
--- a/lib/puppet/reports/log.rb
+++ b/lib/puppet/reports/log.rb
@@ -1,6 +1,6 @@
-require 'puppet'
+require 'puppet/reports'
-Puppet::Network::Handler.report.newreport(:log) do
+Puppet::Reports.register_report(:log) do
desc "Send all received logs to the local log destinations. Usually
the log destination is syslog."
diff --git a/lib/puppet/reports/rrdgraph.rb b/lib/puppet/reports/rrdgraph.rb
index 9ab1f4b17..2611f0369 100644
--- a/lib/puppet/reports/rrdgraph.rb
+++ b/lib/puppet/reports/rrdgraph.rb
@@ -1,6 +1,4 @@
-require 'puppet'
-
-Puppet::Network::Handler.report.newreport(:rrdgraph) do
+Puppet::Reports.register_report(:rrdgraph) do
desc "Graph all available data about hosts using the RRD library. You
must have the Ruby RRDtool library installed to use this report, which
you can get from `the RubyRRDTool RubyForge page`_. This package requires
diff --git a/lib/puppet/reports/store.rb b/lib/puppet/reports/store.rb
index 0c3e86f37..dfc992820 100644
--- a/lib/puppet/reports/store.rb
+++ b/lib/puppet/reports/store.rb
@@ -1,6 +1,6 @@
require 'puppet'
-Puppet::Network::Handler.report.newreport(:store, :useyaml => true) do
+Puppet::Reports.register_report(:store) do
Puppet.settings.use(:reporting)
desc "Store the yaml report on disk. Each host sends its report as a YAML dump
@@ -24,7 +24,7 @@ Puppet::Network::Handler.report.newreport(:store, :useyaml => true) do
config.use("reportclient-#{client}")
end
- def process(yaml)
+ def process
# We don't want any tracking back in the fs. Unlikely, but there
# you go.
client = self.host.gsub("..",".")
@@ -46,7 +46,7 @@ Puppet::Network::Handler.report.newreport(:store, :useyaml => true) do
begin
File.open(file, "w", 0640) do |f|
- f.print yaml
+ f.print to_yaml
end
rescue => detail
if Puppet[:trace]
diff --git a/lib/puppet/reports/tagmail.rb b/lib/puppet/reports/tagmail.rb
index fd9126a1a..a2c973f8f 100644
--- a/lib/puppet/reports/tagmail.rb
+++ b/lib/puppet/reports/tagmail.rb
@@ -3,7 +3,7 @@ require 'pp'
require 'net/smtp'
-Puppet::Network::Handler.report.newreport(:tagmail) do
+Puppet::Reports.register_report(:tagmail) do
desc "This report sends specific log messages to specific email addresses
based on the tags in the log messages. See the
`UsingTags tag documentation`:trac: for more information
diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb
index 19dd1b629..f73c6a9fb 100644
--- a/lib/puppet/transaction/report.rb
+++ b/lib/puppet/transaction/report.rb
@@ -1,10 +1,15 @@
require 'puppet'
+require 'puppet/indirector'
# A class for reporting what happens on each client. Reports consist of
# two types of data: Logs and Metrics. Logs are the output that each
# change produces, and Metrics are all of the numerical data involved
# in the transaction.
class Puppet::Transaction::Report
+ extend Puppet::Indirector
+
+ indirects :report, :terminus_class => :code
+
attr_accessor :logs, :metrics, :time, :host
def <<(msg)
diff --git a/lib/puppet/transportable.rb b/lib/puppet/transportable.rb
index 2a600b50e..281ad00d3 100644
--- a/lib/puppet/transportable.rb
+++ b/lib/puppet/transportable.rb
@@ -126,7 +126,7 @@ module Puppet
# Return the type fully capitalized correctly.
def type_capitalized
- type.split("::").collect { |s| s.capitalize }.join("::")
+ type.to_s.split("::").collect { |s| s.capitalize }.join("::")
end
end