summaryrefslogtreecommitdiffstats
path: root/lib/puppet/application
diff options
context:
space:
mode:
authorDominic Cleal <dcleal@redhat.com>2011-02-19 21:21:13 +0000
committerDominic Cleal <dcleal@redhat.com>2011-02-19 21:21:13 +0000
commitc87ec2598700c4e5236452a016f0497ec848cb90 (patch)
tree47a2435ef019bfcac2ec2aa388935173bc5c6b52 /lib/puppet/application
parent3eace859f20d9ac7366382826028af44c3ab62d6 (diff)
parentea348761df0b5297dbac50c7f1c48d22746524fa (diff)
downloadpuppet-c87ec2598700c4e5236452a016f0497ec848cb90.tar.gz
puppet-c87ec2598700c4e5236452a016f0497ec848cb90.tar.xz
puppet-c87ec2598700c4e5236452a016f0497ec848cb90.zip
Merge branch 'master' into tickets/master/4258-dev
Diffstat (limited to 'lib/puppet/application')
-rw-r--r--lib/puppet/application/agent.rb7
-rw-r--r--lib/puppet/application/apply.rb8
-rw-r--r--lib/puppet/application/doc.rb5
-rw-r--r--lib/puppet/application/inspect.rb123
-rw-r--r--lib/puppet/application/kick.rb6
-rw-r--r--lib/puppet/application/master.rb4
-rw-r--r--lib/puppet/application/queue.rb8
-rw-r--r--lib/puppet/application/resource.rb6
8 files changed, 143 insertions, 24 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/doc.rb b/lib/puppet/application/doc.rb
index 1f6c63286..aaefd6e75 100644
--- a/lib/puppet/application/doc.rb
+++ b/lib/puppet/application/doc.rb
@@ -8,7 +8,7 @@ class Puppet::Application::Doc < Puppet::Application
attr_accessor :unknown_args, :manifest
def preinit
- {:references => [], :mode => :text, :format => :to_rest }.each do |name,value|
+ {:references => [], :mode => :text, :format => :to_markdown }.each do |name,value|
options[name] = value
end
@unknown_args = []
@@ -113,9 +113,6 @@ class Puppet::Application::Doc < Puppet::Application
text += Puppet::Util::Reference.footer unless with_contents # We've only got one reference
- # Replace the trac links, since they're invalid everywhere else
- text.gsub!(/`\w+\s+([^`]+)`:trac:/) { |m| $1 }
-
if options[:mode] == :pdf
Puppet::Util::Reference.pdf(text)
else
diff --git a/lib/puppet/application/inspect.rb b/lib/puppet/application/inspect.rb
new file mode 100644
index 000000000..19324e285
--- /dev/null
+++ b/lib/puppet/application/inspect.rb
@@ -0,0 +1,123 @@
+require 'puppet'
+require 'puppet/application'
+require 'puppet/file_bucket/dipper'
+
+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
+
+ @report.configuration_version = catalog.version
+
+ inspect_starttime = Time.now
+ @report.add_times("config_retrieval", inspect_starttime - retrieval_starttime)
+
+ if Puppet[:archive_files]
+ dipper = Puppet::FileBucket::Dipper.new(:Server => Puppet[:archive_file_server])
+ end
+
+ catalog.to_ral.resources.each do |ral_resource|
+ audited_attributes = ral_resource[:audit]
+ next unless audited_attributes
+
+ status = Puppet::Resource::Status.new(ral_resource)
+
+ begin
+ audited_resource = ral_resource.to_resource
+ rescue StandardError => detail
+ puts detail.backtrace if Puppet[:trace]
+ ral_resource.err "Could not inspect #{ral_resource}; skipping: #{detail}"
+ audited_attributes.each do |name|
+ event = ral_resource.event(
+ :property => name,
+ :status => "failure",
+ :audited => true,
+ :message => "failed to inspect #{name}"
+ )
+ status.add_event(event)
+ end
+ else
+ audited_attributes.each do |name|
+ next if audited_resource[name].nil?
+ # Skip :absent properties of :absent resources. Really, it would be nicer if the RAL returned nil for those, but it doesn't. ~JW
+ if name == :ensure or audited_resource[:ensure] != :absent or audited_resource[name] != :absent
+ event = ral_resource.event(
+ :previous_value => audited_resource[name],
+ :property => name,
+ :status => "audit",
+ :audited => true,
+ :message => "inspected value is #{audited_resource[name].inspect}"
+ )
+ status.add_event(event)
+ end
+ end
+ end
+ if Puppet[:archive_files] and ral_resource.type == :file and audited_attributes.include?(:content)
+ path = ral_resource[:path]
+ if File.readable?(path)
+ begin
+ dipper.backup(path)
+ rescue StandardError => detail
+ Puppet.warning detail
+ end
+ end
+ end
+ @report.add_resource_status(status)
+ end
+
+ finishtime = Time.now
+ @report.add_times("inspect", finishtime - inspect_starttime)
+ @report.finalize_report
+
+ 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]