summaryrefslogtreecommitdiffstats
path: root/lib/puppet/application
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
commit3180b9d9b2c844dade1d361326600f7001ec66dd (patch)
tree98fe7c5ac7eb942aac9c39f019a17b0b3f5a57f4 /lib/puppet/application
parent543225970225de5697734bfaf0a6eee996802c04 (diff)
downloadpuppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.gz
puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.xz
puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.zip
Code smell: Two space indentation
Replaced 106806 occurances of ^( +)(.*$) with The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people who learned ruby in the 1900s) uses two-space indentation. 3 Examples: The code: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") becomes: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") The code: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object becomes: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object The code: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end becomes: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end
Diffstat (limited to 'lib/puppet/application')
-rw-r--r--lib/puppet/application/agent.rb434
-rw-r--r--lib/puppet/application/apply.rb258
-rw-r--r--lib/puppet/application/cert.rb142
-rw-r--r--lib/puppet/application/describe.rb334
-rw-r--r--lib/puppet/application/doc.rb364
-rw-r--r--lib/puppet/application/filebucket.rb142
-rw-r--r--lib/puppet/application/kick.rb358
-rw-r--r--lib/puppet/application/master.rb272
-rw-r--r--lib/puppet/application/queue.rb138
-rw-r--r--lib/puppet/application/resource.rb198
10 files changed, 1320 insertions, 1320 deletions
diff --git a/lib/puppet/application/agent.rb b/lib/puppet/application/agent.rb
index 2d7ac1b6a..b90bdd484 100644
--- a/lib/puppet/application/agent.rb
+++ b/lib/puppet/application/agent.rb
@@ -2,268 +2,268 @@ require 'puppet/application'
class Puppet::Application::Agent < Puppet::Application
- should_parse_config
- run_mode :agent
-
- attr_accessor :explicit_waitforcert, :args, :agent, :daemon, :host
-
- def preinit
- # Do an initial trap, so that cancels don't get a stack trace.
- trap(:INT) do
- $stderr.puts "Cancelling startup"
- exit(0)
- end
-
- {
- :waitforcert => 120, # Default to checking for certs every 5 minutes
- :detailed_exitcodes => false,
- :verbose => false,
- :debug => false,
- :centrallogs => false,
- :setdest => false,
- :enable => false,
- :disable => false,
- :client => true,
- :fqdn => nil,
- :serve => [],
- :digest => :MD5,
- :fingerprint => false,
- }.each do |opt,val|
- options[opt] = val
- end
-
- @explicit_waitforcert = false
- @args = {}
- require 'puppet/daemon'
- @daemon = Puppet::Daemon.new
- @daemon.argv = ARGV.dup
- end
+ should_parse_config
+ run_mode :agent
- option("--centrallogging")
- option("--disable")
- option("--enable")
- option("--debug","-d")
- option("--fqdn FQDN","-f")
- option("--test","-t")
- option("--verbose","-v")
-
- option("--fingerprint")
- option("--digest DIGEST")
-
- option("--serve HANDLER", "-s") do |arg|
- if Puppet::Network::Handler.handler(arg)
- options[:serve] << arg.to_sym
- else
- raise "Could not find handler for #{arg}"
- end
- end
+ attr_accessor :explicit_waitforcert, :args, :agent, :daemon, :host
- option("--no-client") do |arg|
- options[:client] = false
+ def preinit
+ # Do an initial trap, so that cancels don't get a stack trace.
+ trap(:INT) do
+ $stderr.puts "Cancelling startup"
+ exit(0)
end
- option("--onetime", "-o") do |arg|
- Puppet[:onetime] = true
- options[:waitforcert] = 0 unless @explicit_waitforcert
+ {
+ :waitforcert => 120, # Default to checking for certs every 5 minutes
+ :detailed_exitcodes => false,
+ :verbose => false,
+ :debug => false,
+ :centrallogs => false,
+ :setdest => false,
+ :enable => false,
+ :disable => false,
+ :client => true,
+ :fqdn => nil,
+ :serve => [],
+ :digest => :MD5,
+ :fingerprint => false,
+ }.each do |opt,val|
+ options[opt] = val
end
- option("--detailed-exitcodes") do |arg|
- options[:detailed_exitcodes] = true
+ @explicit_waitforcert = false
+ @args = {}
+ require 'puppet/daemon'
+ @daemon = Puppet::Daemon.new
+ @daemon.argv = ARGV.dup
+ end
+
+ option("--centrallogging")
+ option("--disable")
+ option("--enable")
+ option("--debug","-d")
+ option("--fqdn FQDN","-f")
+ option("--test","-t")
+ option("--verbose","-v")
+
+ option("--fingerprint")
+ option("--digest DIGEST")
+
+ option("--serve HANDLER", "-s") do |arg|
+ if Puppet::Network::Handler.handler(arg)
+ options[:serve] << arg.to_sym
+ else
+ raise "Could not find handler for #{arg}"
end
-
- option("--logdest DEST", "-l DEST") do |arg|
- begin
- Puppet::Util::Log.newdestination(arg)
- options[:setdest] = true
- rescue => detail
- puts detail.backtrace if Puppet[:debug]
- $stderr.puts detail.to_s
- end
+ end
+
+ option("--no-client") do |arg|
+ options[:client] = false
+ end
+
+ option("--onetime", "-o") do |arg|
+ Puppet[:onetime] = true
+ options[:waitforcert] = 0 unless @explicit_waitforcert
+ end
+
+ option("--detailed-exitcodes") do |arg|
+ options[:detailed_exitcodes] = true
+ end
+
+ option("--logdest DEST", "-l DEST") do |arg|
+ begin
+ Puppet::Util::Log.newdestination(arg)
+ options[:setdest] = true
+ rescue => detail
+ puts detail.backtrace if Puppet[:debug]
+ $stderr.puts detail.to_s
end
-
- option("--waitforcert WAITFORCERT", "-w") do |arg|
- options[:waitforcert] = arg.to_i
- @explicit_waitforcert = true
+ end
+
+ option("--waitforcert WAITFORCERT", "-w") do |arg|
+ options[:waitforcert] = arg.to_i
+ @explicit_waitforcert = true
+ end
+
+ option("--port PORT","-p") do |arg|
+ @args[:Port] = arg
+ end
+
+ def run_command
+ return fingerprint if options[:fingerprint]
+ return onetime if Puppet[:onetime]
+ main
+ end
+
+ def fingerprint
+ unless cert = host.certificate || host.certificate_request
+ $stderr.puts "Fingerprint asked but no certificate nor certificate request have yet been issued"
+ exit(1)
+ return
end
-
- option("--port PORT","-p") do |arg|
- @args[:Port] = arg
+ unless fingerprint = cert.fingerprint(options[:digest])
+ raise ArgumentError, "Could not get fingerprint for digest '#{options[:digest]}'"
end
-
- def run_command
- return fingerprint if options[:fingerprint]
- return onetime if Puppet[:onetime]
- main
+ Puppet.notice fingerprint
+ end
+
+ def onetime
+ unless options[:client]
+ $stderr.puts "onetime is specified but there is no client"
+ exit(43)
+ return
end
- def fingerprint
- unless cert = host.certificate || host.certificate_request
- $stderr.puts "Fingerprint asked but no certificate nor certificate request have yet been issued"
- exit(1)
- return
- end
- unless fingerprint = cert.fingerprint(options[:digest])
- raise ArgumentError, "Could not get fingerprint for digest '#{options[:digest]}'"
- end
- Puppet.notice fingerprint
- end
+ @daemon.set_signal_traps
- def onetime
- unless options[:client]
- $stderr.puts "onetime is specified but there is no client"
- exit(43)
- return
- end
-
- @daemon.set_signal_traps
-
- begin
- report = @agent.run
- rescue => detail
- puts detail.backtrace if Puppet[:trace]
- Puppet.err detail.to_s
- end
-
- if not report
- exit(1)
- elsif not Puppet[:noop] and options[:detailed_exitcodes] then
- exit(report.exit_status)
- else
- exit(0)
- end
+ begin
+ report = @agent.run
+ rescue => detail
+ puts detail.backtrace if Puppet[:trace]
+ Puppet.err detail.to_s
end
- def main
- Puppet.notice "Starting Puppet client version #{Puppet.version}"
-
- @daemon.start
+ if not report
+ exit(1)
+ elsif not Puppet[:noop] and options[:detailed_exitcodes] then
+ exit(report.exit_status)
+ else
+ exit(0)
end
-
- # Enable all of the most common test options.
- def setup_test
- Puppet.settings.handlearg("--ignorecache")
- Puppet.settings.handlearg("--no-usecacheonfailure")
- Puppet.settings.handlearg("--no-splay")
- Puppet.settings.handlearg("--show_diff")
- Puppet.settings.handlearg("--no-daemonize")
- options[:verbose] = true
- Puppet[:onetime] = true
- options[:detailed_exitcodes] = true
- options[:waitforcert] = 0 unless @explicit_waitforcert
+ end
+
+ def main
+ Puppet.notice "Starting Puppet client version #{Puppet.version}"
+
+ @daemon.start
+ end
+
+ # Enable all of the most common test options.
+ def setup_test
+ Puppet.settings.handlearg("--ignorecache")
+ Puppet.settings.handlearg("--no-usecacheonfailure")
+ Puppet.settings.handlearg("--no-splay")
+ Puppet.settings.handlearg("--show_diff")
+ Puppet.settings.handlearg("--no-daemonize")
+ options[:verbose] = true
+ Puppet[:onetime] = true
+ options[:detailed_exitcodes] = true
+ options[:waitforcert] = 0 unless @explicit_waitforcert
+ end
+
+ # Handle the logging settings.
+ def setup_logs
+ if options[:debug] or options[:verbose]
+ Puppet::Util::Log.newdestination(:console)
+ if options[:debug]
+ Puppet::Util::Log.level = :debug
+ else
+ Puppet::Util::Log.level = :info
+ end
end
- # Handle the logging settings.
- def setup_logs
- if options[:debug] or options[:verbose]
- Puppet::Util::Log.newdestination(:console)
- if options[:debug]
- Puppet::Util::Log.level = :debug
- else
- Puppet::Util::Log.level = :info
- end
- end
-
- Puppet::Util::Log.newdestination(:syslog) unless options[:setdest]
+ Puppet::Util::Log.newdestination(:syslog) unless options[:setdest]
+ end
+
+ def enable_disable_client(agent)
+ if options[:enable]
+ agent.enable
+ elsif options[:disable]
+ agent.disable
end
+ exit(0)
+ end
- def enable_disable_client(agent)
- if options[:enable]
- agent.enable
- elsif options[:disable]
- agent.disable
- end
- exit(0)
+ def setup_listen
+ unless FileTest.exists?(Puppet[:authconfig])
+ Puppet.err "Will not start without authorization file #{Puppet[:authconfig]}"
+ exit(14)
end
- def setup_listen
- unless FileTest.exists?(Puppet[:authconfig])
- Puppet.err "Will not start without authorization file #{Puppet[:authconfig]}"
- exit(14)
- end
+ handlers = nil
- handlers = nil
+ if options[:serve].empty?
+ handlers = [:Runner]
+ else
+ handlers = options[:serve]
+ end
- if options[:serve].empty?
- handlers = [:Runner]
- else
- handlers = options[:serve]
- end
+ require 'puppet/network/server'
+ # No REST handlers yet.
+ server = Puppet::Network::Server.new(:xmlrpc_handlers => handlers, :port => Puppet[:puppetport])
- require 'puppet/network/server'
- # No REST handlers yet.
- server = Puppet::Network::Server.new(:xmlrpc_handlers => handlers, :port => Puppet[:puppetport])
+ @daemon.server = server
+ end
- @daemon.server = server
- end
+ def setup
+ setup_test if options[:test]
- def setup
- setup_test if options[:test]
+ setup_logs
- setup_logs
+ exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
- exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
+ # If noop is set, then also enable diffs
+ Puppet[:show_diff] = true if Puppet[:noop]
- # If noop is set, then also enable diffs
- Puppet[:show_diff] = true if Puppet[:noop]
-
- args[:Server] = Puppet[:server]
- if options[:fqdn]
- args[:FQDN] = options[:fqdn]
- Puppet[:certname] = options[:fqdn]
- end
+ args[:Server] = Puppet[:server]
+ if options[:fqdn]
+ args[:FQDN] = options[:fqdn]
+ Puppet[:certname] = options[:fqdn]
+ end
- if options[:centrallogs]
- logdest = args[:Server]
+ if options[:centrallogs]
+ logdest = args[:Server]
- logdest += ":" + args[:Port] if args.include?(:Port)
- Puppet::Util::Log.newdestination(logdest)
- end
+ logdest += ":" + args[:Port] if args.include?(:Port)
+ Puppet::Util::Log.newdestination(logdest)
+ end
- Puppet.settings.use :main, :agent, :ssl
+ Puppet.settings.use :main, :agent, :ssl
- # We need to specify a ca location for all of the SSL-related i
- # indirected classes to work; in fingerprint mode we just need
- # access to the local files and we don't need a ca.
- Puppet::SSL::Host.ca_location = options[:fingerprint] ? :none : :remote
+ # We need to specify a ca location for all of the SSL-related i
+ # indirected classes to work; in fingerprint mode we just need
+ # 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.terminus_class = :rest
- # Override the default; puppetd needs this, usually.
- # You can still override this on the command-line with, e.g., :compiler.
- Puppet[:catalog_terminus] = :rest
+ # Override the default; puppetd needs this, usually.
+ # You can still override this on the command-line with, e.g., :compiler.
+ Puppet[:catalog_terminus] = :rest
- # Override the default.
- Puppet[:facts_terminus] = :facter
+ # Override the default.
+ Puppet[:facts_terminus] = :facter
- Puppet::Resource::Catalog.cache_class = :yaml
+ Puppet::Resource::Catalog.cache_class = :yaml
- # We need tomake the client either way, we just don't start it
- # if --no-client is set.
- require 'puppet/agent'
- require 'puppet/configurer'
- @agent = Puppet::Agent.new(Puppet::Configurer)
+ # We need tomake the client either way, we just don't start it
+ # if --no-client is set.
+ require 'puppet/agent'
+ require 'puppet/configurer'
+ @agent = Puppet::Agent.new(Puppet::Configurer)
- enable_disable_client(@agent) if options[:enable] or options[:disable]
+ enable_disable_client(@agent) if options[:enable] or options[:disable]
- @daemon.agent = agent if options[:client]
+ @daemon.agent = agent if options[:client]
- # It'd be nice to daemonize later, but we have to daemonize before the
- # waitforcert happens.
- @daemon.daemonize if Puppet[:daemonize]
+ # It'd be nice to daemonize later, but we have to daemonize before the
+ # waitforcert happens.
+ @daemon.daemonize if Puppet[:daemonize]
- @host = Puppet::SSL::Host.new
- cert = @host.wait_for_cert(options[:waitforcert]) unless options[:fingerprint]
+ @host = Puppet::SSL::Host.new
+ cert = @host.wait_for_cert(options[:waitforcert]) unless options[:fingerprint]
- @objects = []
+ @objects = []
- # This has to go after the certs are dealt with.
- if Puppet[:listen]
- unless Puppet[:onetime]
- setup_listen
- else
- Puppet.notice "Ignoring --listen on onetime run"
- end
- end
+ # This has to go after the certs are dealt with.
+ if Puppet[:listen]
+ unless Puppet[:onetime]
+ setup_listen
+ else
+ Puppet.notice "Ignoring --listen on onetime run"
+ end
end
+ end
end
diff --git a/lib/puppet/application/apply.rb b/lib/puppet/application/apply.rb
index cd4c75d75..bb4186dbd 100644
--- a/lib/puppet/application/apply.rb
+++ b/lib/puppet/application/apply.rb
@@ -2,164 +2,164 @@ require 'puppet/application'
class Puppet::Application::Apply < Puppet::Application
- should_parse_config
-
- option("--debug","-d")
- option("--execute EXECUTE","-e") do |arg|
- options[:code] = arg
+ should_parse_config
+
+ option("--debug","-d")
+ option("--execute EXECUTE","-e") do |arg|
+ options[:code] = arg
+ end
+ option("--loadclasses","-L")
+ option("--verbose","-v")
+ option("--use-nodes")
+ option("--detailed-exitcodes")
+
+ option("--apply catalog", "-a catalog") do |arg|
+ options[:catalog] = arg
+ end
+
+ option("--logdest LOGDEST", "-l") do |arg|
+ begin
+ Puppet::Util::Log.newdestination(arg)
+ options[:logset] = true
+ rescue => detail
+ $stderr.puts detail.to_s
end
- option("--loadclasses","-L")
- option("--verbose","-v")
- option("--use-nodes")
- option("--detailed-exitcodes")
-
- option("--apply catalog", "-a catalog") do |arg|
- options[:catalog] = arg
+ end
+
+ def run_command
+ if options[:catalog]
+ apply
+ elsif Puppet[:parseonly]
+ parseonly
+ else
+ main
end
+ end
- option("--logdest LOGDEST", "-l") do |arg|
- begin
- Puppet::Util::Log.newdestination(arg)
- options[:logset] = true
- rescue => detail
- $stderr.puts detail.to_s
- end
+ def apply
+ if options[:catalog] == "-"
+ text = $stdin.read
+ else
+ text = File.read(options[:catalog])
end
- def run_command
- if options[:catalog]
- apply
- elsif Puppet[:parseonly]
- parseonly
- else
- main
- end
+ begin
+ catalog = Puppet::Resource::Catalog.convert_from(Puppet::Resource::Catalog.default_format,text)
+ catalog = Puppet::Resource::Catalog.pson_create(catalog) unless catalog.is_a?(Puppet::Resource::Catalog)
+ rescue => detail
+ raise Puppet::Error, "Could not deserialize catalog from pson: #{detail}"
end
- def apply
- if options[:catalog] == "-"
- text = $stdin.read
- else
- text = File.read(options[:catalog])
- end
+ catalog = catalog.to_ral
- begin
- catalog = Puppet::Resource::Catalog.convert_from(Puppet::Resource::Catalog.default_format,text)
- catalog = Puppet::Resource::Catalog.pson_create(catalog) unless catalog.is_a?(Puppet::Resource::Catalog)
- rescue => detail
- raise Puppet::Error, "Could not deserialize catalog from pson: #{detail}"
- end
+ require 'puppet/configurer'
+ configurer = Puppet::Configurer.new
+ configurer.run :catalog => catalog
+ end
- catalog = catalog.to_ral
-
- require 'puppet/configurer'
- configurer = Puppet::Configurer.new
- configurer.run :catalog => catalog
+ def parseonly
+ # Set our code or file to use.
+ if options[:code] or command_line.args.length == 0
+ Puppet[:code] = options[:code] || STDIN.read
+ else
+ Puppet[:manifest] = command_line.args.shift
end
-
- def parseonly
- # Set our code or file to use.
- if options[:code] or command_line.args.length == 0
- Puppet[:code] = options[:code] || STDIN.read
- else
- Puppet[:manifest] = command_line.args.shift
- end
- begin
- Puppet::Node::Environment.new(Puppet[:environment]).known_resource_types
- rescue => detail
- Puppet.err detail
- exit 1
- end
- exit 0
+ begin
+ Puppet::Node::Environment.new(Puppet[:environment]).known_resource_types
+ rescue => detail
+ Puppet.err detail
+ exit 1
+ end
+ exit 0
+ end
+
+ def main
+ # Set our code or file to use.
+ if options[:code] or command_line.args.length == 0
+ Puppet[:code] = options[:code] || STDIN.read
+ else
+ Puppet[:manifest] = command_line.args.shift
end
- def main
- # Set our code or file to use.
- if options[:code] or command_line.args.length == 0
- Puppet[:code] = options[:code] || STDIN.read
- else
- Puppet[:manifest] = command_line.args.shift
- end
+ # Collect our facts.
+ unless facts = Puppet::Node::Facts.find(Puppet[:certname])
+ raise "Could not find facts for #{Puppet[:certname]}"
+ end
- # Collect our facts.
- unless facts = Puppet::Node::Facts.find(Puppet[:certname])
- raise "Could not find facts for #{Puppet[:certname]}"
- end
+ # Find our Node
+ unless node = Puppet::Node.find(Puppet[:certname])
+ raise "Could not find node #{Puppet[:certname]}"
+ end
- # Find our Node
- unless node = Puppet::Node.find(Puppet[:certname])
- raise "Could not find node #{Puppet[:certname]}"
- end
+ # Merge in the facts.
+ node.merge(facts.values)
- # Merge in the facts.
- node.merge(facts.values)
-
- # Allow users to load the classes that puppet agent creates.
- if options[:loadclasses]
- file = Puppet[:classfile]
- if FileTest.exists?(file)
- unless FileTest.readable?(file)
- $stderr.puts "#{file} is not readable"
- exit(63)
- end
- node.classes = File.read(file).split(/[\s\n]+/)
- end
+ # Allow users to load the classes that puppet agent creates.
+ if options[:loadclasses]
+ file = Puppet[:classfile]
+ if FileTest.exists?(file)
+ unless FileTest.readable?(file)
+ $stderr.puts "#{file} is not readable"
+ exit(63)
end
+ node.classes = File.read(file).split(/[\s\n]+/)
+ end
+ end
- begin
- # Compile our catalog
- starttime = Time.now
- catalog = Puppet::Resource::Catalog.find(node.name, :use_node => node)
+ begin
+ # Compile our catalog
+ starttime = Time.now
+ catalog = Puppet::Resource::Catalog.find(node.name, :use_node => node)
- # Translate it to a RAL catalog
- catalog = catalog.to_ral
+ # Translate it to a RAL catalog
+ catalog = catalog.to_ral
- catalog.finalize
+ catalog.finalize
- catalog.retrieval_duration = Time.now - starttime
+ catalog.retrieval_duration = Time.now - starttime
- require 'puppet/configurer'
- configurer = Puppet::Configurer.new
- configurer.execute_prerun_command
+ require 'puppet/configurer'
+ configurer = Puppet::Configurer.new
+ configurer.execute_prerun_command
- # And apply it
- transaction = catalog.apply
+ # And apply it
+ transaction = catalog.apply
- configurer.execute_postrun_command
+ configurer.execute_postrun_command
- status = 0
- if not Puppet[:noop] and options[:detailed_exitcodes]
- transaction.generate_report
- exit(transaction.report.exit_status)
- else
- exit(0)
- end
- rescue => detail
- puts detail.backtrace if Puppet[:trace]
- $stderr.puts detail.message
- exit(1)
- end
+ status = 0
+ if not Puppet[:noop] and options[:detailed_exitcodes]
+ transaction.generate_report
+ exit(transaction.report.exit_status)
+ else
+ exit(0)
+ end
+ rescue => detail
+ puts detail.backtrace if Puppet[:trace]
+ $stderr.puts detail.message
+ exit(1)
end
+ end
- def setup
- exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
+ def setup
+ exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
- # If noop is set, then also enable diffs
- Puppet[:show_diff] = true if Puppet[:noop]
+ # If noop is set, then also enable diffs
+ Puppet[:show_diff] = true if Puppet[:noop]
- Puppet::Util::Log.newdestination(:console) unless options[:logset]
- client = nil
- server = nil
+ Puppet::Util::Log.newdestination(:console) unless options[:logset]
+ client = nil
+ server = nil
- trap(:INT) do
- $stderr.puts "Exiting"
- exit(1)
- end
+ 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
+ if options[:debug]
+ Puppet::Util::Log.level = :debug
+ elsif options[:verbose]
+ Puppet::Util::Log.level = :info
end
+ end
end
diff --git a/lib/puppet/application/cert.rb b/lib/puppet/application/cert.rb
index af9042993..467b0c859 100644
--- a/lib/puppet/application/cert.rb
+++ b/lib/puppet/application/cert.rb
@@ -2,84 +2,84 @@ require 'puppet/application'
class Puppet::Application::Cert < Puppet::Application
- should_parse_config
- run_mode :master
-
- attr_accessor :cert_mode, :all, :ca, :digest, :signed
-
- def find_mode(opt)
- require 'puppet/ssl/certificate_authority'
- modes = Puppet::SSL::CertificateAuthority::Interface::INTERFACE_METHODS
- tmp = opt.sub("--", '').to_sym
- @cert_mode = modes.include?(tmp) ? tmp : nil
- end
-
- option("--clean", "-c") do
- @cert_mode = :destroy
+ should_parse_config
+ run_mode :master
+
+ attr_accessor :cert_mode, :all, :ca, :digest, :signed
+
+ def find_mode(opt)
+ require 'puppet/ssl/certificate_authority'
+ modes = Puppet::SSL::CertificateAuthority::Interface::INTERFACE_METHODS
+ tmp = opt.sub("--", '').to_sym
+ @cert_mode = modes.include?(tmp) ? tmp : nil
+ end
+
+ option("--clean", "-c") do
+ @cert_mode = :destroy
+ end
+
+ option("--all", "-a") do
+ @all = true
+ end
+
+ option("--digest DIGEST") do |arg|
+ @digest = arg
+ end
+
+ option("--signed", "-s") do
+ @signed = true
+ end
+
+ option("--debug", "-d") do |arg|
+ Puppet::Util::Log.level = :debug
+ end
+
+ require 'puppet/ssl/certificate_authority/interface'
+ Puppet::SSL::CertificateAuthority::Interface::INTERFACE_METHODS.reject {|m| m == :destroy }.each do |method|
+ option("--#{method}", "-#{method.to_s[0,1]}") do
+ find_mode("--#{method}")
end
-
- option("--all", "-a") do
- @all = true
+ end
+
+ option("--verbose", "-v") do
+ Puppet::Util::Log.level = :info
+ end
+
+ def main
+ if @all
+ hosts = :all
+ elsif @signed
+ hosts = :signed
+ else
+ hosts = command_line.args.collect { |h| h.downcase }
end
-
- option("--digest DIGEST") do |arg|
- @digest = arg
+ begin
+ @ca.apply(:revoke, :to => hosts) if @cert_mode == :destroy
+ @ca.apply(@cert_mode, :to => hosts, :digest => @digest)
+ rescue => detail
+ puts detail.backtrace if Puppet[:trace]
+ puts detail.to_s
+ exit(24)
end
+ end
- option("--signed", "-s") do
- @signed = true
- end
+ def setup
+ exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
- option("--debug", "-d") do |arg|
- Puppet::Util::Log.level = :debug
- end
+ Puppet::Util::Log.newdestination :console
- require 'puppet/ssl/certificate_authority/interface'
- Puppet::SSL::CertificateAuthority::Interface::INTERFACE_METHODS.reject {|m| m == :destroy }.each do |method|
- option("--#{method}", "-#{method.to_s[0,1]}") do
- find_mode("--#{method}")
- end
+ if [:generate, :destroy].include? @cert_mode
+ Puppet::SSL::Host.ca_location = :local
+ else
+ Puppet::SSL::Host.ca_location = :only
end
- option("--verbose", "-v") do
- Puppet::Util::Log.level = :info
- end
-
- def main
- if @all
- hosts = :all
- elsif @signed
- hosts = :signed
- else
- hosts = command_line.args.collect { |h| h.downcase }
- end
- begin
- @ca.apply(:revoke, :to => hosts) if @cert_mode == :destroy
- @ca.apply(@cert_mode, :to => hosts, :digest => @digest)
- rescue => detail
- puts detail.backtrace if Puppet[:trace]
- puts detail.to_s
- exit(24)
- end
- end
-
- def setup
- exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
-
- Puppet::Util::Log.newdestination :console
-
- if [:generate, :destroy].include? @cert_mode
- Puppet::SSL::Host.ca_location = :local
- else
- Puppet::SSL::Host.ca_location = :only
- end
-
- begin
- @ca = Puppet::SSL::CertificateAuthority.new
- rescue => detail
- puts detail.backtrace if Puppet[:trace]
- puts detail.to_s
- exit(23)
- end
+ begin
+ @ca = Puppet::SSL::CertificateAuthority.new
+ rescue => detail
+ puts detail.backtrace if Puppet[:trace]
+ puts detail.to_s
+ exit(23)
end
+ end
end
diff --git a/lib/puppet/application/describe.rb b/lib/puppet/application/describe.rb
index 64246d1ea..5abe3ea14 100644
--- a/lib/puppet/application/describe.rb
+++ b/lib/puppet/application/describe.rb
@@ -2,202 +2,202 @@ require 'puppet/application'
class Formatter
- def initialize(width)
- @width = width
+ def initialize(width)
+ @width = width
+ end
+
+ def wrap(txt, opts)
+ return "" unless txt && !txt.empty?
+ work = (opts[:scrub] ? scrub(txt) : txt)
+ indent = (opts[:indent] ? opts[:indent] : 0)
+ textLen = @width - indent
+ patt = Regexp.new("^(.{0,#{textLen}})[ \n]")
+ prefix = " " * indent
+
+ res = []
+
+ while work.length > textLen
+ if work =~ patt
+ res << $1
+ work.slice!(0, $MATCH.length)
+ else
+ res << work.slice!(0, textLen)
+ end
end
-
- def wrap(txt, opts)
- return "" unless txt && !txt.empty?
- work = (opts[:scrub] ? scrub(txt) : txt)
- indent = (opts[:indent] ? opts[:indent] : 0)
- textLen = @width - indent
- patt = Regexp.new("^(.{0,#{textLen}})[ \n]")
- prefix = " " * indent
-
- res = []
-
- while work.length > textLen
- if work =~ patt
- res << $1
- work.slice!(0, $MATCH.length)
- else
- res << work.slice!(0, textLen)
- end
- end
- res << work if work.length.nonzero?
- prefix + res.join("\n#{prefix}")
- end
-
- def header(txt, sep = "-")
- "\n#{txt}\n" + sep * txt.size
- end
-
- private
-
- def scrub(text)
- # For text with no carriage returns, there's nothing to do.
- return text if text !~ /\n/
- indent = nil
-
- # If we can match an indentation, then just remove that same level of
- # indent from every line.
- if text =~ /^(\s+)/
- indent = $1
- return text.gsub(/^#{indent}/,'')
- else
- return text
- end
+ res << work if work.length.nonzero?
+ prefix + res.join("\n#{prefix}")
+ end
+
+ def header(txt, sep = "-")
+ "\n#{txt}\n" + sep * txt.size
+ end
+
+ private
+
+ def scrub(text)
+ # For text with no carriage returns, there's nothing to do.
+ return text if text !~ /\n/
+ indent = nil
+
+ # If we can match an indentation, then just remove that same level of
+ # indent from every line.
+ if text =~ /^(\s+)/
+ indent = $1
+ return text.gsub(/^#{indent}/,'')
+ else
+ return text
end
+ end
end
class TypeDoc
- def initialize
- @format = Formatter.new(76)
- @types = {}
- Puppet::Type.loadall
- Puppet::Type.eachtype { |type|
- next if type.name == :component
- @types[type.name] = type
- }
+ def initialize
+ @format = Formatter.new(76)
+ @types = {}
+ Puppet::Type.loadall
+ Puppet::Type.eachtype { |type|
+ next if type.name == :component
+ @types[type.name] = type
+ }
+ end
+
+ def list_types
+ puts "These are the types known to puppet:\n"
+ @types.keys.sort { |a, b|
+ a.to_s <=> b.to_s
+ }.each do |name|
+ type = @types[name]
+ s = type.doc.gsub(/\s+/, " ")
+ n = s.index(".")
+ if n.nil?
+ s = ".. no documentation .."
+ elsif n > 45
+ s = s[0, 45] + " ..."
+ else
+ s = s[0, n]
+ end
+ printf "%-15s - %s\n", name, s
end
+ end
- def list_types
- puts "These are the types known to puppet:\n"
- @types.keys.sort { |a, b|
- a.to_s <=> b.to_s
- }.each do |name|
- type = @types[name]
- s = type.doc.gsub(/\s+/, " ")
- n = s.index(".")
- if n.nil?
- s = ".. no documentation .."
- elsif n > 45
- s = s[0, 45] + " ..."
- else
- s = s[0, n]
- end
- printf "%-15s - %s\n", name, s
- end
+ def format_type(name, opts)
+ name = name.to_sym
+ unless @types.has_key?(name)
+ puts "Unknown type #{name}"
+ return
end
-
- def format_type(name, opts)
- name = name.to_sym
- unless @types.has_key?(name)
- puts "Unknown type #{name}"
- return
- end
- type = @types[name]
- puts @format.header(name.to_s, "=")
- puts @format.wrap(type.doc, :indent => 0, :scrub => true) + "\n\n"
-
- puts @format.header("Parameters")
- if opts[:parameters]
- format_attrs(type, [:property, :param])
- else
- list_attrs(type, [:property, :param])
- end
-
- if opts[:meta]
- puts @format.header("Meta Parameters")
- if opts[:parameters]
- format_attrs(type, [:meta])
- else
- list_attrs(type, [:meta])
- end
- end
-
- if type.providers.size > 0
- puts @format.header("Providers")
- if opts[:providers]
- format_providers(type)
- else
- list_providers(type)
- end
- end
+ type = @types[name]
+ puts @format.header(name.to_s, "=")
+ puts @format.wrap(type.doc, :indent => 0, :scrub => true) + "\n\n"
+
+ puts @format.header("Parameters")
+ if opts[:parameters]
+ format_attrs(type, [:property, :param])
+ else
+ list_attrs(type, [:property, :param])
end
- # List details about attributes
- def format_attrs(type, attrs)
- docs = {}
- type.allattrs.each do |name|
- kind = type.attrtype(name)
- docs[name] = type.attrclass(name).doc if attrs.include?(kind) && name != :provider
- end
-
- docs.sort { |a,b|
- a[0].to_s <=> b[0].to_s
- }.each { |name, doc|
- print "\n- **#{name}**"
- if type.namevar == name and name != :name
- puts " (*namevar*)"
- else
- puts ""
- end
- puts @format.wrap(doc, :indent => 4, :scrub => true)
- }
+ if opts[:meta]
+ puts @format.header("Meta Parameters")
+ if opts[:parameters]
+ format_attrs(type, [:meta])
+ else
+ list_attrs(type, [:meta])
+ end
end
- # List the names of attributes
- def list_attrs(type, attrs)
- params = []
- type.allattrs.each do |name|
- kind = type.attrtype(name)
- params << name.to_s if attrs.include?(kind) && name != :provider
- end
- puts @format.wrap(params.sort.join(", "), :indent => 4)
+ if type.providers.size > 0
+ puts @format.header("Providers")
+ if opts[:providers]
+ format_providers(type)
+ else
+ list_providers(type)
+ end
end
-
- def format_providers(type)
- type.providers.sort { |a,b|
- a.to_s <=> b.to_s
- }.each { |prov|
- puts "\n- **#{prov}**"
- puts @format.wrap(type.provider(prov).doc, :indent => 4, :scrub => true)
- }
+ end
+
+ # List details about attributes
+ def format_attrs(type, attrs)
+ docs = {}
+ type.allattrs.each do |name|
+ kind = type.attrtype(name)
+ docs[name] = type.attrclass(name).doc if attrs.include?(kind) && name != :provider
end
- def list_providers(type)
- list = type.providers.sort { |a,b|
- a.to_s <=> b.to_s
- }.join(", ")
- puts @format.wrap(list, :indent => 4)
+ docs.sort { |a,b|
+ a[0].to_s <=> b[0].to_s
+ }.each { |name, doc|
+ print "\n- **#{name}**"
+ if type.namevar == name and name != :name
+ puts " (*namevar*)"
+ else
+ puts ""
+ end
+ puts @format.wrap(doc, :indent => 4, :scrub => true)
+ }
+ end
+
+ # List the names of attributes
+ def list_attrs(type, attrs)
+ params = []
+ type.allattrs.each do |name|
+ kind = type.attrtype(name)
+ params << name.to_s if attrs.include?(kind) && name != :provider
end
+ puts @format.wrap(params.sort.join(", "), :indent => 4)
+ end
+
+ def format_providers(type)
+ type.providers.sort { |a,b|
+ a.to_s <=> b.to_s
+ }.each { |prov|
+ puts "\n- **#{prov}**"
+ puts @format.wrap(type.provider(prov).doc, :indent => 4, :scrub => true)
+ }
+ end
+
+ def list_providers(type)
+ list = type.providers.sort { |a,b|
+ a.to_s <=> b.to_s
+ }.join(", ")
+ puts @format.wrap(list, :indent => 4)
+ end
end
class Puppet::Application::Describe < Puppet::Application
- banner "puppet describe [options] [type]"
+ banner "puppet describe [options] [type]"
- should_not_parse_config
+ should_not_parse_config
- option("--short", "-s", "Only list parameters without detail") do |arg|
- options[:parameters] = false
- end
+ option("--short", "-s", "Only list parameters without detail") do |arg|
+ options[:parameters] = false
+ end
- option("--providers","-p")
- option("--list", "-l")
- option("--meta","-m")
+ option("--providers","-p")
+ option("--list", "-l")
+ option("--meta","-m")
- def preinit
- options[:parameters] = true
- end
+ def preinit
+ options[:parameters] = true
+ end
- def main
- doc = TypeDoc.new
+ def main
+ doc = TypeDoc.new
- if options[:list]
- doc.list_types
- else
- options[:types].each { |name| doc.format_type(name, options) }
- end
+ if options[:list]
+ doc.list_types
+ else
+ options[:types].each { |name| doc.format_type(name, options) }
end
+ end
- def setup
- options[:types] = command_line.args.dup
- handle_help(nil) unless options[:list] || options[:types].size > 0
- $stderr.puts "Warning: ignoring types when listing all types" if options[:list] && options[:types].size > 0
- end
+ def setup
+ options[:types] = command_line.args.dup
+ handle_help(nil) unless options[:list] || options[:types].size > 0
+ $stderr.puts "Warning: ignoring types when listing all types" if options[:list] && options[:types].size > 0
+ end
end
diff --git a/lib/puppet/application/doc.rb b/lib/puppet/application/doc.rb
index ba07f73cb..66aa6c8a1 100644
--- a/lib/puppet/application/doc.rb
+++ b/lib/puppet/application/doc.rb
@@ -2,214 +2,214 @@ require 'puppet/application'
class Puppet::Application::Doc < Puppet::Application
- should_not_parse_config
- run_mode :master
+ should_not_parse_config
+ run_mode :master
- attr_accessor :unknown_args, :manifest
+ attr_accessor :unknown_args, :manifest
- def preinit
- {:references => [], :mode => :text, :format => :to_rest }.each do |name,value|
- options[name] = value
- end
- @unknown_args = []
- @manifest = false
+ def preinit
+ {:references => [], :mode => :text, :format => :to_rest }.each do |name,value|
+ options[name] = value
end
-
- option("--all","-a")
- option("--outputdir OUTPUTDIR","-o")
- option("--verbose","-v")
- option("--debug","-d")
- option("--charset CHARSET")
-
- option("--format FORMAT", "-f") do |arg|
- method = "to_#{arg}"
- require 'puppet/util/reference'
- if Puppet::Util::Reference.method_defined?(method)
- options[:format] = method
- else
- raise "Invalid output format #{arg}"
- end
+ @unknown_args = []
+ @manifest = false
+ end
+
+ option("--all","-a")
+ option("--outputdir OUTPUTDIR","-o")
+ option("--verbose","-v")
+ option("--debug","-d")
+ option("--charset CHARSET")
+
+ option("--format FORMAT", "-f") do |arg|
+ method = "to_#{arg}"
+ require 'puppet/util/reference'
+ if Puppet::Util::Reference.method_defined?(method)
+ options[:format] = method
+ else
+ raise "Invalid output format #{arg}"
end
-
- option("--mode MODE", "-m") do |arg|
- require 'puppet/util/reference'
- if Puppet::Util::Reference.modes.include?(arg) or arg.intern==:rdoc
- options[:mode] = arg.intern
- else
- raise "Invalid output mode #{arg}"
- end
+ end
+
+ option("--mode MODE", "-m") do |arg|
+ require 'puppet/util/reference'
+ if Puppet::Util::Reference.modes.include?(arg) or arg.intern==:rdoc
+ options[:mode] = arg.intern
+ else
+ raise "Invalid output mode #{arg}"
end
-
- option("--list", "-l") do |arg|
- require 'puppet/util/reference'
- puts Puppet::Util::Reference.references.collect { |r| Puppet::Util::Reference.reference(r).doc }.join("\n")
- exit(0)
- end
-
- option("--reference REFERENCE", "-r") do |arg|
- options[:references] << arg.intern
+ end
+
+ option("--list", "-l") do |arg|
+ require 'puppet/util/reference'
+ puts Puppet::Util::Reference.references.collect { |r| Puppet::Util::Reference.reference(r).doc }.join("\n")
+ exit(0)
+ end
+
+ option("--reference REFERENCE", "-r") do |arg|
+ options[:references] << arg.intern
+ end
+
+ def handle_unknown( opt, arg )
+ @unknown_args << {:opt => opt, :arg => arg }
+ true
+ end
+
+ def run_command
+ return[:rdoc, :trac, :markdown].include?(options[:mode]) ? send(options[:mode]) : other
+ end
+
+ def rdoc
+ exit_code = 0
+ files = []
+ unless @manifest
+ env = Puppet::Node::Environment.new
+ files += env.modulepath
+ files << File.dirname(env[:manifest])
end
+ files += command_line.args
+ Puppet.info "scanning: #{files.inspect}"
- def handle_unknown( opt, arg )
- @unknown_args << {:opt => opt, :arg => arg }
- true
- end
-
- def run_command
- return[:rdoc, :trac, :markdown].include?(options[:mode]) ? send(options[:mode]) : other
- end
-
- def rdoc
- exit_code = 0
- files = []
- unless @manifest
- env = Puppet::Node::Environment.new
- files += env.modulepath
- files << File.dirname(env[:manifest])
- end
- files += command_line.args
- Puppet.info "scanning: #{files.inspect}"
-
- Puppet.settings.setdefaults(
- "puppetdoc",
+ Puppet.settings.setdefaults(
+ "puppetdoc",
- "document_all" => [false, "Document all resources"]
- )
- Puppet.settings[:document_all] = options[:all] || false
- begin
- require 'puppet/util/rdoc'
- if @manifest
- Puppet::Util::RDoc.manifestdoc(files)
- else
- options[:outputdir] = "doc" unless options[:outputdir]
- Puppet::Util::RDoc.rdoc(options[:outputdir], files, options[:charset])
- end
- rescue => detail
- puts detail.backtrace if Puppet[:trace]
- $stderr.puts "Could not generate documentation: #{detail}"
- exit_code = 1
- end
- exit exit_code
+ "document_all" => [false, "Document all resources"]
+ )
+ Puppet.settings[:document_all] = options[:all] || false
+ begin
+ require 'puppet/util/rdoc'
+ if @manifest
+ Puppet::Util::RDoc.manifestdoc(files)
+ else
+ options[:outputdir] = "doc" unless options[:outputdir]
+ Puppet::Util::RDoc.rdoc(options[:outputdir], files, options[:charset])
+ end
+ rescue => detail
+ puts detail.backtrace if Puppet[:trace]
+ $stderr.puts "Could not generate documentation: #{detail}"
+ exit_code = 1
end
-
- def trac
- require 'puppet/util/reference'
- options[:references].each do |name|
- section = Puppet::Util::Reference.reference(name) or raise "Could not find section #{name}"
- section.trac unless options[:mode] == :pdf
- end
+ exit exit_code
+ end
+
+ def trac
+ require 'puppet/util/reference'
+ options[:references].each do |name|
+ section = Puppet::Util::Reference.reference(name) or raise "Could not find section #{name}"
+ section.trac unless options[:mode] == :pdf
end
-
- def markdown
+ end
+
+ def markdown
+ text = ""
+ with_contents = false
+ exit_code = 0
+ require 'puppet/util/reference'
+ options[:references].sort { |a,b| a.to_s <=> b.to_s }.each do |name|
+ raise "Could not find reference #{name}" unless section = Puppet::Util::Reference.reference(name)
+
+ begin
+ # Add the per-section text, but with no ToC
+ text += section.send(options[:format], with_contents)
+ text += Puppet::Util::Reference.footer
+ text.gsub!(/`\w+\s+([^`]+)`:trac:/) { |m| $1 }
+ Puppet::Util::Reference.markdown(name, text)
text = ""
- with_contents = false
- exit_code = 0
- require 'puppet/util/reference'
- options[:references].sort { |a,b| a.to_s <=> b.to_s }.each do |name|
- raise "Could not find reference #{name}" unless section = Puppet::Util::Reference.reference(name)
-
- begin
- # Add the per-section text, but with no ToC
- text += section.send(options[:format], with_contents)
- text += Puppet::Util::Reference.footer
- text.gsub!(/`\w+\s+([^`]+)`:trac:/) { |m| $1 }
- Puppet::Util::Reference.markdown(name, text)
- text = ""
- rescue => detail
- puts detail.backtrace
- $stderr.puts "Could not generate reference #{name}: #{detail}"
- exit_code = 1
- next
- end
- end
-
- exit exit_code
+ rescue => detail
+ puts detail.backtrace
+ $stderr.puts "Could not generate reference #{name}: #{detail}"
+ exit_code = 1
+ next
+ end
end
- def other
- text = ""
- with_contents = options[:references].length <= 1
- exit_code = 0
- require 'puppet/util/reference'
- options[:references].sort { |a,b| a.to_s <=> b.to_s }.each do |name|
- raise "Could not find reference #{name}" unless section = Puppet::Util::Reference.reference(name)
-
- begin
- # Add the per-section text, but with no ToC
- text += section.send(options[:format], with_contents)
- rescue => detail
- puts detail.backtrace
- $stderr.puts "Could not generate reference #{name}: #{detail}"
- exit_code = 1
- next
- end
- end
+ exit exit_code
+ end
+
+ def other
+ text = ""
+ with_contents = options[:references].length <= 1
+ exit_code = 0
+ require 'puppet/util/reference'
+ options[:references].sort { |a,b| a.to_s <=> b.to_s }.each do |name|
+ raise "Could not find reference #{name}" unless section = Puppet::Util::Reference.reference(name)
+
+ begin
+ # Add the per-section text, but with no ToC
+ text += section.send(options[:format], with_contents)
+ rescue => detail
+ puts detail.backtrace
+ $stderr.puts "Could not generate reference #{name}: #{detail}"
+ exit_code = 1
+ next
+ end
+ end
- text += Puppet::Util::Reference.footer unless with_contents # We've only got one reference
+ 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 }
+ # 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
- puts text
- end
-
- exit exit_code
+ if options[:mode] == :pdf
+ Puppet::Util::Reference.pdf(text)
+ else
+ puts text
end
- def setup
- # sole manifest documentation
- if command_line.args.size > 0
- options[:mode] = :rdoc
- @manifest = true
- end
+ exit exit_code
+ end
- if options[:mode] == :rdoc
- setup_rdoc
- else
- setup_reference
- end
+ def setup
+ # sole manifest documentation
+ if command_line.args.size > 0
+ options[:mode] = :rdoc
+ @manifest = true
end
- def setup_reference
- if options[:all]
- # Don't add dynamic references to the "all" list.
- require 'puppet/util/reference'
- options[:references] = Puppet::Util::Reference.references.reject do |ref|
- Puppet::Util::Reference.reference(ref).dynamic?
- end
- end
-
- options[:references] << :type if options[:references].empty?
+ if options[:mode] == :rdoc
+ setup_rdoc
+ else
+ setup_reference
+ end
+ end
+
+ def setup_reference
+ if options[:all]
+ # Don't add dynamic references to the "all" list.
+ require 'puppet/util/reference'
+ options[:references] = Puppet::Util::Reference.references.reject do |ref|
+ Puppet::Util::Reference.reference(ref).dynamic?
+ end
end
- def setup_rdoc(dummy_argument=:work_arround_for_ruby_GC_bug)
- # consume the unknown options
- # and feed them as settings
- if @unknown_args.size > 0
- @unknown_args.each do |option|
- # force absolute path for modulepath when passed on commandline
- if option[:opt]=="--modulepath" or option[:opt] == "--manifestdir"
- option[:arg] = option[:arg].split(':').collect { |p| File.expand_path(p) }.join(':')
- end
- Puppet.settings.handlearg(option[:opt], option[:arg])
- end
+ options[:references] << :type if options[:references].empty?
+ end
+
+ def setup_rdoc(dummy_argument=:work_arround_for_ruby_GC_bug)
+ # consume the unknown options
+ # and feed them as settings
+ if @unknown_args.size > 0
+ @unknown_args.each do |option|
+ # force absolute path for modulepath when passed on commandline
+ if option[:opt]=="--modulepath" or option[:opt] == "--manifestdir"
+ option[:arg] = option[:arg].split(':').collect { |p| File.expand_path(p) }.join(':')
end
+ Puppet.settings.handlearg(option[:opt], option[:arg])
+ end
+ end
- # Now parse the config
- Puppet.parse_config
+ # Now parse the config
+ Puppet.parse_config
- # Handle the logging settings.
- if options[:debug] or options[:verbose]
- if options[:debug]
- Puppet::Util::Log.level = :debug
- else
- Puppet::Util::Log.level = :info
- end
+ # Handle the logging settings.
+ if options[:debug] or options[:verbose]
+ if options[:debug]
+ Puppet::Util::Log.level = :debug
+ else
+ Puppet::Util::Log.level = :info
+ end
- Puppet::Util::Log.newdestination(:console)
- end
+ Puppet::Util::Log.newdestination(:console)
end
+ end
end
diff --git a/lib/puppet/application/filebucket.rb b/lib/puppet/application/filebucket.rb
index 8da2d014d..9c3c79bc3 100644
--- a/lib/puppet/application/filebucket.rb
+++ b/lib/puppet/application/filebucket.rb
@@ -2,86 +2,86 @@ require 'puppet/application'
class Puppet::Application::Filebucket < Puppet::Application
- should_not_parse_config
-
- option("--bucket BUCKET","-b")
- option("--debug","-d")
- option("--local","-l")
- option("--remote","-r")
- option("--verbose","-v")
+ should_not_parse_config
+
+ option("--bucket BUCKET","-b")
+ option("--debug","-d")
+ option("--local","-l")
+ option("--remote","-r")
+ option("--verbose","-v")
+
+ attr :args
+
+ def run_command
+ @args = command_line.args
+ command = args.shift
+ return send(command) if %w{get backup restore}.include? command
+ help
+ end
+
+ def get
+ md5 = args.shift
+ out = @client.getfile(md5)
+ print out
+ end
+
+ def backup
+ args.each do |file|
+ unless FileTest.exists?(file)
+ $stderr.puts "#{file}: no such file"
+ next
+ end
+ unless FileTest.readable?(file)
+ $stderr.puts "#{file}: cannot read file"
+ next
+ end
+ md5 = @client.backup(file)
+ puts "#{file}: #{md5}"
+ end
+ end
- attr :args
+ def restore
+ file = args.shift
+ md5 = args.shift
+ @client.restore(file, md5)
+ end
- def run_command
- @args = command_line.args
- command = args.shift
- return send(command) if %w{get backup restore}.include? command
- help
- end
+ def setup
+ Puppet::Log.newdestination(:console)
- def get
- md5 = args.shift
- out = @client.getfile(md5)
- print out
- end
+ @client = nil
+ @server = nil
- def backup
- args.each do |file|
- unless FileTest.exists?(file)
- $stderr.puts "#{file}: no such file"
- next
- end
- unless FileTest.readable?(file)
- $stderr.puts "#{file}: cannot read file"
- next
- end
- md5 = @client.backup(file)
- puts "#{file}: #{md5}"
- end
+ trap(:INT) do
+ $stderr.puts "Cancelling"
+ exit(1)
end
- def restore
- file = args.shift
- md5 = args.shift
- @client.restore(file, md5)
+ if options[:debug]
+ Puppet::Log.level = :debug
+ elsif options[:verbose]
+ Puppet::Log.level = :info
end
- def setup
- Puppet::Log.newdestination(:console)
-
- @client = nil
- @server = nil
-
- trap(:INT) do
- $stderr.puts "Cancelling"
- exit(1)
- end
-
- if options[:debug]
- Puppet::Log.level = :debug
- elsif options[:verbose]
- Puppet::Log.level = :info
- end
-
- # Now parse the config
- Puppet.parse_config
-
- exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
-
- require 'puppet/file_bucket/dipper'
- begin
- if options[:local] or options[:bucket]
- path = options[:bucket] || Puppet[:bucketdir]
- @client = Puppet::FileBucket::Dipper.new(:Path => path)
- else
- @client = Puppet::FileBucket::Dipper.new(:Server => Puppet[:server])
- end
- rescue => detail
- $stderr.puts detail
- puts detail.backtrace if Puppet[:trace]
- exit(1)
- end
+ # Now parse the config
+ Puppet.parse_config
+
+ exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
+
+ require 'puppet/file_bucket/dipper'
+ begin
+ if options[:local] or options[:bucket]
+ path = options[:bucket] || Puppet[:bucketdir]
+ @client = Puppet::FileBucket::Dipper.new(:Path => path)
+ else
+ @client = Puppet::FileBucket::Dipper.new(:Server => Puppet[:server])
+ end
+ rescue => detail
+ $stderr.puts detail
+ puts detail.backtrace if Puppet[:trace]
+ exit(1)
end
+ end
end
diff --git a/lib/puppet/application/kick.rb b/lib/puppet/application/kick.rb
index 6c77e74f2..37aeb1ef2 100644
--- a/lib/puppet/application/kick.rb
+++ b/lib/puppet/application/kick.rb
@@ -2,211 +2,211 @@ require 'puppet/application'
class Puppet::Application::Kick < Puppet::Application
- should_not_parse_config
+ should_not_parse_config
+
+ attr_accessor :hosts, :tags, :classes
+
+ option("--all","-a")
+ option("--foreground","-f")
+ option("--debug","-d")
+ option("--ping","-P")
+ option("--test")
+
+ option("--host HOST") do |arg|
+ @hosts << arg
+ end
+
+ option("--tag TAG", "-t") do |arg|
+ @tags << arg
+ end
+
+ option("--class CLASS", "-c") do |arg|
+ @classes << arg
+ end
+
+ option("--no-fqdn", "-n") do |arg|
+ options[:fqdn] = false
+ end
+
+ option("--parallel PARALLEL", "-p") do |arg|
+ begin
+ options[:parallel] = Integer(arg)
+ rescue
+ $stderr.puts "Could not convert #{arg.inspect} to an integer"
+ exit(23)
+ end
+ end
- attr_accessor :hosts, :tags, :classes
+ def run_command
+ @hosts += command_line.args
+ options[:test] ? test : main
+ end
- option("--all","-a")
- option("--foreground","-f")
- option("--debug","-d")
- option("--ping","-P")
- option("--test")
+ def test
+ puts "Skipping execution in test mode"
+ exit(0)
+ end
- option("--host HOST") do |arg|
- @hosts << arg
- end
+ def main
+ require 'puppet/network/client'
- option("--tag TAG", "-t") do |arg|
- @tags << arg
- end
+ Puppet.warning "Failed to load ruby LDAP library. LDAP functionality will not be available" unless Puppet.features.ldap?
+ require 'puppet/util/ldap/connection'
- option("--class CLASS", "-c") do |arg|
- @classes << arg
- end
+ todo = @hosts.dup
- option("--no-fqdn", "-n") do |arg|
- options[:fqdn] = false
- end
+ failures = []
- option("--parallel PARALLEL", "-p") do |arg|
+ # Now do the actual work
+ go = true
+ while go
+ # If we don't have enough children in process and we still have hosts left to
+ # do, then do the next host.
+ if @children.length < options[:parallel] and ! todo.empty?
+ host = todo.shift
+ pid = fork do
+ run_for_host(host)
+ end
+ @children[pid] = host
+ else
+ # Else, see if we can reap a process.
begin
- options[:parallel] = Integer(arg)
- rescue
- $stderr.puts "Could not convert #{arg.inspect} to an integer"
- exit(23)
+ pid = Process.wait
+
+ if host = @children[pid]
+ # Remove our host from the list of children, so the parallelization
+ # continues working.
+ @children.delete(pid)
+ failures << host if $CHILD_STATUS.exitstatus != 0
+ print "#{host} finished with exit code #{$CHILD_STATUS.exitstatus}\n"
+ else
+ $stderr.puts "Could not find host for PID #{pid} with status #{$CHILD_STATUS.exitstatus}"
+ end
+ rescue Errno::ECHILD
+ # There are no children left, so just exit unless there are still
+ # children left to do.
+ next unless todo.empty?
+
+ if failures.empty?
+ puts "Finished"
+ exit(0)
+ else
+ puts "Failed: #{failures.join(", ")}"
+ exit(3)
+ end
end
+ end
end
-
- def run_command
- @hosts += command_line.args
- options[:test] ? test : main
+ end
+
+ def run_for_host(host)
+ if options[:ping]
+ out = %x{ping -c 1 #{host}}
+ unless $CHILD_STATUS == 0
+ $stderr.print "Could not contact #{host}\n"
+ next
+ end
end
- def test
- puts "Skipping execution in test mode"
- exit(0)
+ require 'puppet/run'
+ Puppet::Run.indirection.terminus_class = :rest
+ port = Puppet[:puppetport]
+ url = ["https://#{host}:#{port}", "production", "run", host].join('/')
+
+ print "Triggering #{host}\n"
+ begin
+ run_options = {
+ :tags => @tags,
+ :background => ! options[:foreground],
+ :ignoreschedules => options[:ignoreschedules]
+ }
+ run = Puppet::Run.new( run_options ).save( url )
+ puts "Getting status"
+ result = run.status
+ puts "status is #{result}"
+ rescue => detail
+ puts detail.backtrace if Puppet[:trace]
+ $stderr.puts "Host #{host} failed: #{detail}\n"
+ exit(2)
end
- def main
- require 'puppet/network/client'
-
- Puppet.warning "Failed to load ruby LDAP library. LDAP functionality will not be available" unless Puppet.features.ldap?
- require 'puppet/util/ldap/connection'
-
- todo = @hosts.dup
-
- failures = []
-
- # Now do the actual work
- go = true
- while go
- # If we don't have enough children in process and we still have hosts left to
- # do, then do the next host.
- if @children.length < options[:parallel] and ! todo.empty?
- host = todo.shift
- pid = fork do
- run_for_host(host)
- end
- @children[pid] = host
- else
- # Else, see if we can reap a process.
- begin
- pid = Process.wait
-
- if host = @children[pid]
- # Remove our host from the list of children, so the parallelization
- # continues working.
- @children.delete(pid)
- failures << host if $CHILD_STATUS.exitstatus != 0
- print "#{host} finished with exit code #{$CHILD_STATUS.exitstatus}\n"
- else
- $stderr.puts "Could not find host for PID #{pid} with status #{$CHILD_STATUS.exitstatus}"
- end
- rescue Errno::ECHILD
- # There are no children left, so just exit unless there are still
- # children left to do.
- next unless todo.empty?
-
- if failures.empty?
- puts "Finished"
- exit(0)
- else
- puts "Failed: #{failures.join(", ")}"
- exit(3)
- end
- end
- end
- end
+ case result
+ when "success";
+ exit(0)
+ when "running"
+ $stderr.puts "Host #{host} is already running"
+ exit(3)
+ else
+ $stderr.puts "Host #{host} returned unknown answer '#{result}'"
+ exit(12)
end
-
- def run_for_host(host)
- if options[:ping]
- out = %x{ping -c 1 #{host}}
- unless $CHILD_STATUS == 0
- $stderr.print "Could not contact #{host}\n"
- next
- end
- end
-
- require 'puppet/run'
- Puppet::Run.indirection.terminus_class = :rest
- port = Puppet[:puppetport]
- url = ["https://#{host}:#{port}", "production", "run", host].join('/')
-
- print "Triggering #{host}\n"
- begin
- run_options = {
- :tags => @tags,
- :background => ! options[:foreground],
- :ignoreschedules => options[:ignoreschedules]
- }
- run = Puppet::Run.new( run_options ).save( url )
- puts "Getting status"
- result = run.status
- puts "status is #{result}"
- rescue => detail
- puts detail.backtrace if Puppet[:trace]
- $stderr.puts "Host #{host} failed: #{detail}\n"
- exit(2)
- end
-
- case result
- when "success";
- exit(0)
- when "running"
- $stderr.puts "Host #{host} is already running"
- exit(3)
- else
- $stderr.puts "Host #{host} returned unknown answer '#{result}'"
- exit(12)
- end
+ end
+
+ def initialize(*args)
+ super
+ @hosts = []
+ @classes = []
+ @tags = []
+ end
+
+ def preinit
+ [:INT, :TERM].each do |signal|
+ trap(signal) do
+ $stderr.puts "Cancelling"
+ exit(1)
+ end
+ end
+ options[:parallel] = 1
+ options[:verbose] = true
+ options[:fqdn] = true
+ options[:ignoreschedules] = false
+ options[:foreground] = false
+ end
+
+ def setup
+ if options[:debug]
+ Puppet::Util::Log.level = :debug
+ else
+ Puppet::Util::Log.level = :info
end
- def initialize(*args)
- super
+ # Now parse the config
+ Puppet.parse_config
+
+ 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 }
+ puts "all: #{@hosts.join(", ")}"
+ else
@hosts = []
- @classes = []
- @tags = []
- end
+ @classes.each do |klass|
+ list = Puppet::Node.search("whatever", :fqdn => options[:fqdn], :class => klass).collect { |node| node.name }
+ puts "#{klass}: #{list.join(", ")}"
- def preinit
- [:INT, :TERM].each do |signal|
- trap(signal) do
- $stderr.puts "Cancelling"
- exit(1)
- end
+ @hosts += list
end
- options[:parallel] = 1
- options[:verbose] = true
- options[:fqdn] = true
- options[:ignoreschedules] = false
- options[:foreground] = false
+ end
+ elsif ! @classes.empty?
+ $stderr.puts "You must be using LDAP to specify host classes"
+ exit(24)
end
- def setup
- if options[:debug]
- Puppet::Util::Log.level = :debug
- else
- Puppet::Util::Log.level = :info
- end
+ @children = {}
- # Now parse the config
- Puppet.parse_config
-
- 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 }
- puts "all: #{@hosts.join(", ")}"
- else
- @hosts = []
- @classes.each do |klass|
- list = Puppet::Node.search("whatever", :fqdn => options[:fqdn], :class => klass).collect { |node| node.name }
- puts "#{klass}: #{list.join(", ")}"
-
- @hosts += list
- end
- end
- elsif ! @classes.empty?
- $stderr.puts "You must be using LDAP to specify host classes"
- exit(24)
+ # If we get a signal, then kill all of our children and get out.
+ [:INT, :TERM].each do |signal|
+ trap(signal) do
+ Puppet.notice "Caught #{signal}; shutting down"
+ @children.each do |pid, host|
+ Process.kill("INT", pid)
end
- @children = {}
-
- # If we get a signal, then kill all of our children and get out.
- [:INT, :TERM].each do |signal|
- trap(signal) do
- Puppet.notice "Caught #{signal}; shutting down"
- @children.each do |pid, host|
- Process.kill("INT", pid)
- end
-
- waitall
-
- exit(1)
- end
- end
+ waitall
+ exit(1)
+ end
end
+ end
+
end
diff --git a/lib/puppet/application/master.rb b/lib/puppet/application/master.rb
index 7485dcb3f..777a50eaa 100644
--- a/lib/puppet/application/master.rb
+++ b/lib/puppet/application/master.rb
@@ -2,155 +2,155 @@ require 'puppet/application'
class Puppet::Application::Master < Puppet::Application
- should_parse_config
- run_mode :master
-
- option("--debug", "-d")
- option("--verbose", "-v")
-
- # internal option, only to be used by ext/rack/config.ru
- option("--rack")
+ should_parse_config
+ run_mode :master
+
+ option("--debug", "-d")
+ option("--verbose", "-v")
+
+ # internal option, only to be used by ext/rack/config.ru
+ option("--rack")
+
+ option("--compile host", "-c host") do |arg|
+ options[:node] = arg
+ end
+
+ option("--logdest DEST", "-l DEST") do |arg|
+ begin
+ Puppet::Util::Log.newdestination(arg)
+ options[:setdest] = true
+ rescue => detail
+ puts detail.backtrace if Puppet[:debug]
+ $stderr.puts detail.to_s
+ end
+ end
- option("--compile host", "-c host") do |arg|
- options[:node] = arg
+ def preinit
+ trap(:INT) do
+ $stderr.puts "Cancelling startup"
+ exit(0)
end
- option("--logdest DEST", "-l DEST") do |arg|
- begin
- Puppet::Util::Log.newdestination(arg)
- options[:setdest] = true
- rescue => detail
- puts detail.backtrace if Puppet[:debug]
- $stderr.puts detail.to_s
- end
+ # Create this first-off, so we have ARGV
+ require 'puppet/daemon'
+ @daemon = Puppet::Daemon.new
+ @daemon.argv = ARGV.dup
+ end
+
+ def run_command
+ if options[:node]
+ compile
+ elsif Puppet[:parseonly]
+ parseonly
+ else
+ main
+ end
+ end
+
+ def compile
+ 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])
+ raise "Could not compile catalog for #{options[:node]}"
+ end
+
+ jj catalog.to_resource
+ rescue => detail
+ $stderr.puts detail
+ exit(30)
end
+ exit(0)
+ end
+
+ def parseonly
+ begin
+ Puppet::Node::Environment.new(Puppet[:environment]).known_resource_types
+ rescue => detail
+ Puppet.err detail
+ exit 1
+ end
+ exit(0)
+ end
- def preinit
- trap(:INT) do
- $stderr.puts "Cancelling startup"
- exit(0)
- end
+ def main
+ require 'etc'
+ require 'puppet/file_serving/content'
+ require 'puppet/file_serving/metadata'
- # Create this first-off, so we have ARGV
- require 'puppet/daemon'
- @daemon = Puppet::Daemon.new
- @daemon.argv = ARGV.dup
- end
+ xmlrpc_handlers = [:Status, :FileServer, :Master, :Report, :Filebucket]
- def run_command
- if options[:node]
- compile
- elsif Puppet[:parseonly]
- parseonly
- else
- main
- end
- end
+ xmlrpc_handlers << :CA if Puppet[:ca]
+
+ # Make sure we've got a localhost ssl cert
+ Puppet::SSL::Host.localhost
- def compile
- 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])
- raise "Could not compile catalog for #{options[:node]}"
- end
-
- jj catalog.to_resource
- rescue => detail
- $stderr.puts detail
- exit(30)
- end
- exit(0)
+ # And now configure our server to *only* hit the CA for data, because that's
+ # all it will have write access to.
+ Puppet::SSL::Host.ca_location = :only if Puppet::SSL::CertificateAuthority.ca?
+
+ if Puppet.features.root?
+ begin
+ Puppet::Util.chuser
+ rescue => detail
+ puts detail.backtrace if Puppet[:trace]
+ $stderr.puts "Could not change user to #{Puppet[:user]}: #{detail}"
+ exit(39)
+ end
end
- def parseonly
- begin
- Puppet::Node::Environment.new(Puppet[:environment]).known_resource_types
- rescue => detail
- Puppet.err detail
- exit 1
- end
- exit(0)
+ unless options[:rack]
+ require 'puppet/network/server'
+ @daemon.server = Puppet::Network::Server.new(:xmlrpc_handlers => xmlrpc_handlers)
+ @daemon.daemonize if Puppet[:daemonize]
+ else
+ require 'puppet/network/http/rack'
+ @app = Puppet::Network::HTTP::Rack.new(:xmlrpc_handlers => xmlrpc_handlers, :protocols => [:rest, :xmlrpc])
end
- def main
- require 'etc'
- require 'puppet/file_serving/content'
- require 'puppet/file_serving/metadata'
-
- xmlrpc_handlers = [:Status, :FileServer, :Master, :Report, :Filebucket]
-
- xmlrpc_handlers << :CA if Puppet[:ca]
-
- # Make sure we've got a localhost ssl cert
- Puppet::SSL::Host.localhost
-
- # And now configure our server to *only* hit the CA for data, because that's
- # all it will have write access to.
- Puppet::SSL::Host.ca_location = :only if Puppet::SSL::CertificateAuthority.ca?
-
- if Puppet.features.root?
- begin
- Puppet::Util.chuser
- rescue => detail
- puts detail.backtrace if Puppet[:trace]
- $stderr.puts "Could not change user to #{Puppet[:user]}: #{detail}"
- exit(39)
- end
- end
-
- unless options[:rack]
- require 'puppet/network/server'
- @daemon.server = Puppet::Network::Server.new(:xmlrpc_handlers => xmlrpc_handlers)
- @daemon.daemonize if Puppet[:daemonize]
- else
- require 'puppet/network/http/rack'
- @app = Puppet::Network::HTTP::Rack.new(:xmlrpc_handlers => xmlrpc_handlers, :protocols => [:rest, :xmlrpc])
- end
-
- Puppet.notice "Starting Puppet master version #{Puppet.version}"
-
- unless options[:rack]
- @daemon.start
- else
- return @app
- end
+ Puppet.notice "Starting Puppet master version #{Puppet.version}"
+
+ unless options[:rack]
+ @daemon.start
+ else
+ return @app
end
+ end
+
+ def setup
+ # Handle the logging settings.
+ if options[:debug] or options[:verbose]
+ if options[:debug]
+ Puppet::Util::Log.level = :debug
+ else
+ Puppet::Util::Log.level = :info
+ end
+
+ unless Puppet[:daemonize] or options[:rack]
+ Puppet::Util::Log.newdestination(:console)
+ options[:setdest] = true
+ end
+ end
+
+ Puppet::Util::Log.newdestination(:syslog) unless options[:setdest]
+
+ exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
+
+ Puppet.settings.use :main, :master, :ssl
+
+ # A temporary solution, to at least make the master work for now.
+ Puppet::Node::Facts.terminus_class = :yaml
+
+ # Cache our nodes in yaml. Currently not configurable.
+ Puppet::Node.cache_class = :yaml
- def setup
- # Handle the logging settings.
- if options[:debug] or options[:verbose]
- if options[:debug]
- Puppet::Util::Log.level = :debug
- else
- Puppet::Util::Log.level = :info
- end
-
- unless Puppet[:daemonize] or options[:rack]
- Puppet::Util::Log.newdestination(:console)
- options[:setdest] = true
- end
- end
-
- Puppet::Util::Log.newdestination(:syslog) unless options[:setdest]
-
- exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
-
- Puppet.settings.use :main, :master, :ssl
-
- # A temporary solution, to at least make the master work for now.
- Puppet::Node::Facts.terminus_class = :yaml
-
- # Cache our nodes in yaml. Currently not configurable.
- Puppet::Node.cache_class = :yaml
-
- # Configure all of the SSL stuff.
- if Puppet::SSL::CertificateAuthority.ca?
- Puppet::SSL::Host.ca_location = :local
- Puppet.settings.use :ca
- Puppet::SSL::CertificateAuthority.instance
- else
- Puppet::SSL::Host.ca_location = :none
- end
+ # Configure all of the SSL stuff.
+ if Puppet::SSL::CertificateAuthority.ca?
+ Puppet::SSL::Host.ca_location = :local
+ Puppet.settings.use :ca
+ Puppet::SSL::CertificateAuthority.instance
+ else
+ Puppet::SSL::Host.ca_location = :none
end
+ end
end
diff --git a/lib/puppet/application/queue.rb b/lib/puppet/application/queue.rb
index 6531f6f92..6df825dd1 100644
--- a/lib/puppet/application/queue.rb
+++ b/lib/puppet/application/queue.rb
@@ -2,90 +2,90 @@ require 'puppet/application'
require 'puppet/util'
class Puppet::Application::Queue < Puppet::Application
- should_parse_config
+ should_parse_config
- attr_accessor :daemon
+ attr_accessor :daemon
- def preinit
- require 'puppet/daemon'
- @daemon = Puppet::Daemon.new
- @daemon.argv = ARGV.dup
- Puppet::Util::Log.newdestination(:console)
+ def preinit
+ require 'puppet/daemon'
+ @daemon = Puppet::Daemon.new
+ @daemon.argv = ARGV.dup
+ Puppet::Util::Log.newdestination(:console)
- # Do an initial trap, so that cancels don't get a stack trace.
+ # Do an initial trap, so that cancels don't get a stack trace.
- # This exits with exit code 1
- trap(:INT) do
- $stderr.puts "Caught SIGINT; shutting down"
- exit(1)
- end
-
- # This is a normal shutdown, so code 0
- trap(:TERM) do
- $stderr.puts "Caught SIGTERM; shutting down"
- exit(0)
- end
+ # This exits with exit code 1
+ trap(:INT) do
+ $stderr.puts "Caught SIGINT; shutting down"
+ exit(1)
+ end
- {
- :verbose => false,
- :debug => false
- }.each do |opt,val|
- options[opt] = val
- end
+ # This is a normal shutdown, so code 0
+ trap(:TERM) do
+ $stderr.puts "Caught SIGTERM; shutting down"
+ exit(0)
end
- option("--debug","-d")
- option("--verbose","-v")
-
- def main
- 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
- # 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
- rescue => detail
- puts detail.backtrace if Puppet[:trace]
- Puppet.err "Could not save queued catalog for #{catalog.name}: #{detail}"
- end
- end
+ {
+ :verbose => false,
+ :debug => false
+ }.each do |opt,val|
+ options[opt] = val
+ end
+ end
+
+ option("--debug","-d")
+ option("--verbose","-v")
+
+ def main
+ 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
+ # 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
+ rescue => detail
+ puts detail.backtrace if Puppet[:trace]
+ Puppet.err "Could not save queued catalog for #{catalog.name}: #{detail}"
end
-
- Thread.list.each { |thread| thread.join }
+ end
end
- # Handle the logging settings.
- def setup_logs
- if options[:debug] or options[:verbose]
- Puppet::Util::Log.newdestination(:console)
- if options[:debug]
- Puppet::Util::Log.level = :debug
- else
- Puppet::Util::Log.level = :info
- end
- end
+ Thread.list.each { |thread| thread.join }
+ end
+
+ # Handle the logging settings.
+ def setup_logs
+ if options[:debug] or options[:verbose]
+ Puppet::Util::Log.newdestination(:console)
+ if options[:debug]
+ Puppet::Util::Log.level = :debug
+ else
+ Puppet::Util::Log.level = :info
+ end
end
+ end
- def setup
- unless Puppet.features.stomp?
- raise ArgumentError, "Could not load the 'stomp' library, which must be present for queueing to work. You must install the required library."
- end
+ def setup
+ unless Puppet.features.stomp?
+ raise ArgumentError, "Could not load the 'stomp' library, which must be present for queueing to work. You must install the required library."
+ end
- setup_logs
+ setup_logs
- exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
+ exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
- require 'puppet/resource/catalog'
- Puppet::Resource::Catalog.terminus_class = :active_record
+ require 'puppet/resource/catalog'
+ Puppet::Resource::Catalog.terminus_class = :active_record
- daemon.daemonize if Puppet[:daemonize]
+ daemon.daemonize if Puppet[:daemonize]
- # We want to make sure that we don't have a cache
- # 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
- end
+ # We want to make sure that we don't have a cache
+ # 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
+ end
end
diff --git a/lib/puppet/application/resource.rb b/lib/puppet/application/resource.rb
index 9e1efe2ef..f55caa58a 100644
--- a/lib/puppet/application/resource.rb
+++ b/lib/puppet/application/resource.rb
@@ -2,117 +2,117 @@ require 'puppet/application'
class Puppet::Application::Resource < Puppet::Application
- should_not_parse_config
-
- attr_accessor :host, :extra_params
-
- def preinit
- @extra_params = []
- @host = nil
- Facter.loadfacts
+ should_not_parse_config
+
+ attr_accessor :host, :extra_params
+
+ def preinit
+ @extra_params = []
+ @host = nil
+ Facter.loadfacts
+ end
+
+ option("--debug","-d")
+ option("--verbose","-v")
+ option("--edit","-e")
+
+ option("--host HOST","-H") do |arg|
+ @host = arg
+ end
+
+ option("--types", "-t") do |arg|
+ types = []
+ Puppet::Type.loadall
+ Puppet::Type.eachtype do |t|
+ next if t.name == :component
+ types << t.name.to_s
end
-
- option("--debug","-d")
- option("--verbose","-v")
- option("--edit","-e")
-
- option("--host HOST","-H") do |arg|
- @host = arg
+ puts types.sort
+ exit
+ end
+
+ option("--param PARAM", "-p") do |arg|
+ @extra_params << arg.to_sym
+ end
+
+ def main
+ args = command_line.args
+ type = args.shift or raise "You must specify the type to display"
+ typeobj = Puppet::Type.type(type) or raise "Could not find type #{type}"
+ name = args.shift
+ params = {}
+ args.each do |setting|
+ if setting =~ /^(\w+)=(.+)$/
+ params[$1] = $2
+ else
+ raise "Invalid parameter setting #{setting}"
+ end
end
- option("--types", "-t") do |arg|
- types = []
- Puppet::Type.loadall
- Puppet::Type.eachtype do |t|
- next if t.name == :component
- types << t.name.to_s
- end
- puts types.sort
- exit
- end
+ raise "You cannot edit a remote host" if options[:edit] and @host
- option("--param PARAM", "-p") do |arg|
- @extra_params << arg.to_sym
- end
+ properties = typeobj.properties.collect { |s| s.name }
- def main
- args = command_line.args
- type = args.shift or raise "You must specify the type to display"
- typeobj = Puppet::Type.type(type) or raise "Could not find type #{type}"
- name = args.shift
- params = {}
- args.each do |setting|
- if setting =~ /^(\w+)=(.+)$/
- params[$1] = $2
- else
- raise "Invalid parameter setting #{setting}"
- end
+ format = proc {|trans|
+ trans.dup.collect do |param, value|
+ if value.nil? or value.to_s.empty?
+ trans.delete(param)
+ elsif value.to_s == "absent" and param.to_s != "ensure"
+ trans.delete(param)
end
- raise "You cannot edit a remote host" if options[:edit] and @host
-
- properties = typeobj.properties.collect { |s| s.name }
-
- format = proc {|trans|
- trans.dup.collect do |param, value|
- if value.nil? or value.to_s.empty?
- trans.delete(param)
- elsif value.to_s == "absent" and param.to_s != "ensure"
- trans.delete(param)
- end
-
- trans.delete(param) unless properties.include?(param) or @extra_params.include?(param)
- end
- trans.to_manifest
- }
-
- if @host
- Puppet::Resource.indirection.terminus_class = :rest
- port = Puppet[:puppetport]
- key = ["https://#{host}:#{port}", "production", "resources", type, name].join('/')
- else
- key = [type, name].join('/')
- end
+ trans.delete(param) unless properties.include?(param) or @extra_params.include?(param)
+ end
+ trans.to_manifest
+ }
+
+ if @host
+ Puppet::Resource.indirection.terminus_class = :rest
+ port = Puppet[:puppetport]
+ key = ["https://#{host}:#{port}", "production", "resources", type, name].join('/')
+ else
+ key = [type, name].join('/')
+ end
- text = if name
- if params.empty?
- [ Puppet::Resource.find( key ) ]
- else
- [ Puppet::Resource.new( type, name, :parameters => params ).save( key ) ]
- end
- else
- Puppet::Resource.search( key, {} )
- end.map(&format).join("\n")
-
- if options[:edit]
- file = "/tmp/x2puppet-#{Process.pid}.pp"
- begin
- File.open(file, "w") do |f|
- f.puts text
- end
- ENV["EDITOR"] ||= "vi"
- system(ENV["EDITOR"], file)
- system("puppet -v #{file}")
- ensure
- #if FileTest.exists? file
- # File.unlink(file)
- #end
- end
- else
- puts text
+ text = if name
+ if params.empty?
+ [ Puppet::Resource.find( key ) ]
+ else
+ [ Puppet::Resource.new( type, name, :parameters => params ).save( key ) ]
+ end
+ else
+ Puppet::Resource.search( key, {} )
+ end.map(&format).join("\n")
+
+ if options[:edit]
+ file = "/tmp/x2puppet-#{Process.pid}.pp"
+ begin
+ File.open(file, "w") do |f|
+ f.puts text
end
+ ENV["EDITOR"] ||= "vi"
+ system(ENV["EDITOR"], file)
+ system("puppet -v #{file}")
+ ensure
+ #if FileTest.exists? file
+ # File.unlink(file)
+ #end
+ end
+ else
+ puts text
end
+ end
- def setup
- Puppet::Util::Log.newdestination(:console)
+ def setup
+ Puppet::Util::Log.newdestination(:console)
- # Now parse the config
- Puppet.parse_config
+ # Now parse the config
+ Puppet.parse_config
- if options[:debug]
- Puppet::Util::Log.level = :debug
- elsif options[:verbose]
- Puppet::Util::Log.level = :info
- end
+ if options[:debug]
+ Puppet::Util::Log.level = :debug
+ elsif options[:verbose]
+ Puppet::Util::Log.level = :info
end
+ end
end