summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorNick Lewis <nick@puppetlabs.com>2011-04-12 14:52:14 -0700
committerNick Lewis <nick@puppetlabs.com>2011-04-12 14:52:14 -0700
commit789aad8dd692e1bac5748e16e0acdfada2d197c7 (patch)
tree60c02e8aeafb42952a9fd9a86f68e635bf39c206 /lib
parent2dfa0afb57ec80f451a54ef96341d413819c14c7 (diff)
parentb2831e102f4cc57d6e0101f55e208695188d426a (diff)
downloadpuppet-789aad8dd692e1bac5748e16e0acdfada2d197c7.tar.gz
puppet-789aad8dd692e1bac5748e16e0acdfada2d197c7.tar.xz
puppet-789aad8dd692e1bac5748e16e0acdfada2d197c7.zip
Merge branch 'ticket/next/2150' into next
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/application.rb22
-rw-r--r--lib/puppet/defaults.rb1
-rw-r--r--lib/puppet/indirector.rb16
3 files changed, 33 insertions, 6 deletions
diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb
index 57bd88877..4c5a5a967 100644
--- a/lib/puppet/application.rb
+++ b/lib/puppet/application.rb
@@ -299,11 +299,12 @@ class Application
# This is the main application entry point
def run
- exit_on_fail("initialize") { hook('preinit') { preinit } }
- exit_on_fail("parse options") { hook('parse_options') { parse_options } }
- exit_on_fail("parse configuration file") { Puppet.settings.parse } if should_parse_config?
- exit_on_fail("prepare for execution") { hook('setup') { setup } }
- exit_on_fail("run") { hook('run_command') { run_command } }
+ exit_on_fail("initialize") { hook('preinit') { preinit } }
+ exit_on_fail("parse options") { hook('parse_options') { parse_options } }
+ exit_on_fail("parse configuration file") { Puppet.settings.parse } if should_parse_config?
+ exit_on_fail("prepare for execution") { hook('setup') { setup } }
+ exit_on_fail("configure routes from #{Puppet[:route_file]}") { configure_indirector_routes }
+ exit_on_fail("run") { hook('run_command') { run_command } }
end
def main
@@ -328,6 +329,15 @@ class Application
Puppet::Util::Log.newdestination(:syslog) unless options[:setdest]
end
+ def configure_indirector_routes
+ route_file = Puppet[:route_file]
+ if File.exists?(route_file)
+ routes = YAML.load_file(route_file)
+ application_routes = routes[name.to_s]
+ Puppet::Indirector.configure_routes(application_routes) if application_routes
+ end
+ end
+
def parse_options
# Create an option parser
option_parser = OptionParser.new(self.class.banner)
@@ -394,7 +404,7 @@ class Application
def exit_on_fail(message, code = 1)
yield
- rescue RuntimeError, NotImplementedError => detail
+ rescue ArgumentError, RuntimeError, NotImplementedError => detail
puts detail.backtrace if Puppet[:trace]
$stderr.puts "Could not #{message}: #{detail}"
exit(code)
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb
index 76c40824c..89f3e169d 100644
--- a/lib/puppet/defaults.rb
+++ b/lib/puppet/defaults.rb
@@ -116,6 +116,7 @@ module Puppet
but then ship with tools that do not know how to handle signed ints, so the UIDs show up as
huge numbers that can then not be fed back into the system. This is a hackish way to fail in a
slightly more useful way when that happens."],
+ :route_file => ["$confdir/routes.yaml", "The YAML file containing indirector route configuration."],
:node_terminus => ["plain", "Where to find information about nodes."],
:catalog_terminus => ["compiler", "Where to get node catalogs. This is useful to change if, for instance,
you'd like to pre-compile catalogs and store them in memcached or some other easily-accessed store."],
diff --git a/lib/puppet/indirector.rb b/lib/puppet/indirector.rb
index 9effc5cdd..7267ac7f3 100644
--- a/lib/puppet/indirector.rb
+++ b/lib/puppet/indirector.rb
@@ -12,6 +12,22 @@ module Puppet::Indirector
require 'puppet/indirector/envelope'
require 'puppet/network/format_handler'
+ def self.configure_routes(application_routes)
+ application_routes.each do |indirection_name, termini|
+ indirection_name = indirection_name.to_sym
+ terminus_name = termini["terminus"]
+ cache_name = termini["cache"]
+
+ Puppet::Indirector::Terminus.terminus_classes(indirection_name)
+
+ indirection = Puppet::Indirector::Indirection.instance(indirection_name)
+ raise "Indirection #{indirection_name} does not exist" unless indirection
+
+ indirection.terminus_class = terminus_name if terminus_name
+ indirection.cache_class = cache_name if cache_name
+ end
+ end
+
# Declare that the including class indirects its methods to
# this terminus. The terminus name must be the name of a Puppet
# default, not the value -- if it's the value, then it gets