diff options
Diffstat (limited to 'lib/puppet/application')
-rw-r--r-- | lib/puppet/application/agent.rb | 7 | ||||
-rw-r--r-- | lib/puppet/application/apply.rb | 8 | ||||
-rw-r--r-- | lib/puppet/application/inspect.rb | 80 | ||||
-rw-r--r-- | lib/puppet/application/kick.rb | 6 | ||||
-rw-r--r-- | lib/puppet/application/master.rb | 4 | ||||
-rw-r--r-- | lib/puppet/application/queue.rb | 8 | ||||
-rw-r--r-- | lib/puppet/application/resource.rb | 6 |
7 files changed, 99 insertions, 20 deletions
diff --git a/lib/puppet/application/agent.rb b/lib/puppet/application/agent.rb index c5ad72068..96f33296f 100644 --- a/lib/puppet/application/agent.rb +++ b/lib/puppet/application/agent.rb @@ -228,9 +228,9 @@ class Puppet::Application::Agent < Puppet::Application # access to the local files and we don't need a ca. Puppet::SSL::Host.ca_location = options[:fingerprint] ? :none : :remote - Puppet::Transaction::Report.terminus_class = :rest + Puppet::Transaction::Report.indirection.terminus_class = :rest # we want the last report to be persisted locally - Puppet::Transaction::Report.cache_class = :yaml + Puppet::Transaction::Report.indirection.cache_class = :yaml # Override the default; puppetd needs this, usually. # You can still override this on the command-line with, e.g., :compiler. @@ -239,8 +239,7 @@ class Puppet::Application::Agent < Puppet::Application # Override the default. Puppet[:facts_terminus] = :facter - Puppet::Resource::Catalog.cache_class = :yaml - + Puppet::Resource::Catalog.indirection.cache_class = :yaml # We need tomake the client either way, we just don't start it # if --no-client is set. diff --git a/lib/puppet/application/apply.rb b/lib/puppet/application/apply.rb index 8ec3fab6b..e5b4bb5b7 100644 --- a/lib/puppet/application/apply.rb +++ b/lib/puppet/application/apply.rb @@ -85,12 +85,12 @@ class Puppet::Application::Apply < Puppet::Application end # Collect our facts. - unless facts = Puppet::Node::Facts.find(Puppet[:certname]) + unless facts = Puppet::Node::Facts.indirection.find(Puppet[:certname]) raise "Could not find facts for #{Puppet[:certname]}" end # Find our Node - unless node = Puppet::Node.find(Puppet[:certname]) + unless node = Puppet::Node.indirection.find(Puppet[:certname]) raise "Could not find node #{Puppet[:certname]}" end @@ -112,7 +112,7 @@ class Puppet::Application::Apply < Puppet::Application begin # Compile our catalog starttime = Time.now - catalog = Puppet::Resource::Catalog.find(node.name, :use_node => node) + catalog = Puppet::Resource::Catalog.indirection.find(node.name, :use_node => node) # Translate it to a RAL catalog catalog = catalog.to_ral @@ -149,7 +149,7 @@ class Puppet::Application::Apply < Puppet::Application end # we want the last report to be persisted locally - Puppet::Transaction::Report.cache_class = :yaml + Puppet::Transaction::Report.indirection.cache_class = :yaml if options[:debug] Puppet::Util::Log.level = :debug diff --git a/lib/puppet/application/inspect.rb b/lib/puppet/application/inspect.rb new file mode 100644 index 000000000..c76f9e4da --- /dev/null +++ b/lib/puppet/application/inspect.rb @@ -0,0 +1,80 @@ +require 'puppet/application' + +class Puppet::Application::Inspect < Puppet::Application + + should_parse_config + run_mode :agent + + option("--debug","-d") + option("--verbose","-v") + + option("--logdest LOGDEST", "-l") do |arg| + begin + Puppet::Util::Log.newdestination(arg) + options[:logset] = true + rescue => detail + $stderr.puts detail.to_s + end + end + + def setup + exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs? + + raise "Inspect requires reporting to be enabled. Set report=true in puppet.conf to enable reporting." unless Puppet[:report] + + @report = Puppet::Transaction::Report.new("inspect") + + Puppet::Util::Log.newdestination(@report) + Puppet::Util::Log.newdestination(:console) unless options[:logset] + + trap(:INT) do + $stderr.puts "Exiting" + exit(1) + end + + if options[:debug] + Puppet::Util::Log.level = :debug + elsif options[:verbose] + Puppet::Util::Log.level = :info + end + + Puppet::Transaction::Report.indirection.terminus_class = :rest + Puppet::Resource::Catalog.indirection.terminus_class = :yaml + end + + def run_command + retrieval_starttime = Time.now + + unless catalog = Puppet::Resource::Catalog.indirection.find(Puppet[:certname]) + raise "Could not find catalog for #{Puppet[:certname]}" + end + + retrieval_time = Time.now - retrieval_starttime + @report.add_times("config_retrieval", retrieval_time) + + starttime = Time.now + + catalog.to_ral.resources.each do |ral_resource| + audited_attributes = ral_resource[:audit] + next unless audited_attributes + + audited_resource = ral_resource.to_resource + + status = Puppet::Resource::Status.new(ral_resource) + audited_attributes.each do |name| + event = ral_resource.event(:previous_value => audited_resource[name], :property => name, :status => "audit", :message => "inspected value is #{audited_resource[name].inspect}") + status.add_event(event) + end + @report.add_resource_status(status) + end + + @report.add_metric(:time, {"config_retrieval" => retrieval_time, "inspect" => Time.now - starttime}) + + begin + Puppet::Transaction::Report.indirection.save(@report) + rescue => detail + puts detail.backtrace if Puppet[:trace] + Puppet.err "Could not send report: #{detail}" + end + end +end diff --git a/lib/puppet/application/kick.rb b/lib/puppet/application/kick.rb index 37aeb1ef2..12dad653a 100644 --- a/lib/puppet/application/kick.rb +++ b/lib/puppet/application/kick.rb @@ -120,7 +120,7 @@ class Puppet::Application::Kick < Puppet::Application :background => ! options[:foreground], :ignoreschedules => options[:ignoreschedules] } - run = Puppet::Run.new( run_options ).save( url ) + run = Puppet::Run.indirection.save(Puppet::Run.new( run_options ), url) puts "Getting status" result = run.status puts "status is #{result}" @@ -175,12 +175,12 @@ class Puppet::Application::Kick < Puppet::Application if Puppet[:node_terminus] == "ldap" and (options[:all] or @classes) if options[:all] - @hosts = Puppet::Node.search("whatever", :fqdn => options[:fqdn]).collect { |node| node.name } + @hosts = Puppet::Node.indirection.search("whatever", :fqdn => options[:fqdn]).collect { |node| node.name } puts "all: #{@hosts.join(", ")}" else @hosts = [] @classes.each do |klass| - list = Puppet::Node.search("whatever", :fqdn => options[:fqdn], :class => klass).collect { |node| node.name } + list = Puppet::Node.indirection.search("whatever", :fqdn => options[:fqdn], :class => klass).collect { |node| node.name } puts "#{klass}: #{list.join(", ")}" @hosts += list diff --git a/lib/puppet/application/master.rb b/lib/puppet/application/master.rb index fde474907..879b66c67 100644 --- a/lib/puppet/application/master.rb +++ b/lib/puppet/application/master.rb @@ -51,7 +51,7 @@ class Puppet::Application::Master < Puppet::Application Puppet::Util::Log.newdestination :console raise ArgumentError, "Cannot render compiled catalogs without pson support" unless Puppet.features.pson? begin - unless catalog = Puppet::Resource::Catalog.find(options[:node]) + unless catalog = Puppet::Resource::Catalog.indirection.find(options[:node]) raise "Could not compile catalog for #{options[:node]}" end @@ -139,7 +139,7 @@ class Puppet::Application::Master < Puppet::Application Puppet.settings.use :main, :master, :ssl # Cache our nodes in yaml. Currently not configurable. - Puppet::Node.cache_class = :yaml + Puppet::Node.indirection.cache_class = :yaml # Configure all of the SSL stuff. if Puppet::SSL::CertificateAuthority.ca? diff --git a/lib/puppet/application/queue.rb b/lib/puppet/application/queue.rb index 239f6b2ad..b9e8ca4ca 100644 --- a/lib/puppet/application/queue.rb +++ b/lib/puppet/application/queue.rb @@ -41,12 +41,12 @@ class Puppet::Application::Queue < Puppet::Application require 'puppet/indirector/catalog/queue' # provides Puppet::Indirector::Queue.subscribe Puppet.notice "Starting puppetqd #{Puppet.version}" Puppet::Resource::Catalog::Queue.subscribe do |catalog| - # Once you have a Puppet::Resource::Catalog instance, calling save on it should suffice + # Once you have a Puppet::Resource::Catalog instance, passing it to save should suffice # to put it through to the database via its active_record indirector (which is determined # by the terminus_class = :active_record setting above) Puppet::Util.benchmark(:notice, "Processing queued catalog for #{catalog.name}") do begin - catalog.save + Puppet::Resource::Catalog.indirection.save(catalog) rescue => detail puts detail.backtrace if Puppet[:trace] Puppet.err "Could not save queued catalog for #{catalog.name}: #{detail}" @@ -79,7 +79,7 @@ class Puppet::Application::Queue < Puppet::Application exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs? require 'puppet/resource/catalog' - Puppet::Resource::Catalog.terminus_class = :active_record + Puppet::Resource::Catalog.indirection.terminus_class = :active_record daemon.daemonize if Puppet[:daemonize] @@ -87,6 +87,6 @@ class Puppet::Application::Queue < Puppet::Application # class set up, because if storeconfigs is enabled, # we'll get a loop of continually caching the catalog # for storage again. - Puppet::Resource::Catalog.cache_class = nil + Puppet::Resource::Catalog.indirection.cache_class = nil end end diff --git a/lib/puppet/application/resource.rb b/lib/puppet/application/resource.rb index f55caa58a..c7c1c28be 100644 --- a/lib/puppet/application/resource.rb +++ b/lib/puppet/application/resource.rb @@ -76,12 +76,12 @@ class Puppet::Application::Resource < Puppet::Application text = if name if params.empty? - [ Puppet::Resource.find( key ) ] + [ Puppet::Resource.indirection.find( key ) ] else - [ Puppet::Resource.new( type, name, :parameters => params ).save( key ) ] + [ Puppet::Resource.indirection.save(Puppet::Resource.new( type, name, :parameters => params ), key) ] end else - Puppet::Resource.search( key, {} ) + Puppet::Resource.indirection.search( key, {} ) end.map(&format).join("\n") if options[:edit] |