module Puppet::ApplicationSupport

Public Class Methods

configure_indirector_routes(application_name) click to toggle source

Reads the routes YAML settings from the file specified by Puppet and resets indirector termini for the current application class if listed.

For instance, PE uses this to set the master facts terminus to 'puppetdb' and its cache terminus to 'yaml'.

@param application_name [String] The name of the current application. @return [void] @api private

   # File lib/puppet/application_support.rb
53 def self.configure_indirector_routes(application_name)
54   route_file = Puppet[:route_file]
55   if Puppet::FileSystem.exist?(route_file)
56     routes = Puppet::Util::Yaml.safe_load_file(route_file, [Symbol])
57     if routes["server"] && routes["master"]
58       Puppet.warning("Route file #{route_file} contains both server and master route settings.")
59     elsif routes["server"] && !routes["master"]
60       routes["master"] = routes["server"]
61     elsif routes["master"] && !routes["server"]
62       routes["server"] = routes["master"]
63     end
64     application_routes = routes[application_name]
65     Puppet::Indirector.configure_routes(application_routes) if application_routes
66   end
67 end
push_application_context(run_mode, environment_mode = :local) click to toggle source

Pushes a Puppet Context configured with a remote environment for an agent (one that exists at the master end), and a regular environment for other modes. The configuration is overridden with options from the command line before being set in a pushed Puppet Context.

@param run_mode [Puppet::Util::RunMode] Puppet's current Run Mode. @param environment_mode [Symbol] optional, Puppet's

current Environment Mode. Defaults to :local

@return [void] @api private

   # File lib/puppet/application_support.rb
22 def self.push_application_context(run_mode, environment_mode = :local)
23   Puppet.push_context_global(Puppet.base_context(Puppet.settings), "Update for application settings (#{run_mode})")
24   # This use of configured environment is correct, this is used to establish
25   # the defaults for an application that does not override, or where an override
26   # has not been made from the command line.
27   #
28   configured_environment_name = Puppet[:environment]
29   if run_mode.name == :agent
30     configured_environment = Puppet::Node::Environment.remote(configured_environment_name)
31   elsif environment_mode == :not_required
32     configured_environment =
33       Puppet.lookup(:environments).get(configured_environment_name) || Puppet::Node::Environment.remote(configured_environment_name)
34   else
35     configured_environment = Puppet.lookup(:environments).get!(configured_environment_name)
36   end
37   configured_environment = configured_environment.override_from_commandline(Puppet.settings)
38 
39   # Setup a new context using the app's configuration
40   Puppet.push_context({:current_environment => configured_environment},
41                       "Update current environment from application's configuration")
42 end