Class: Puppet::Configurer
- Includes:
- FactHandler, Util
- Defined in:
- lib/puppet/configurer.rb
Defined Under Namespace
Modules: FactHandler Classes: Downloader, DownloaderFactory, PluginHandler
Constant Summary
Constants included from Util
Util::AbsolutePathPosix, Util::AbsolutePathWindows, Util::DEFAULT_POSIX_MODE, Util::DEFAULT_WINDOWS_MODE
Constants included from Util::POSIX
Util::POSIX::LOCALE_ENV_VARS, Util::POSIX::USER_ENV_VARS
Constants included from Util::SymbolicFileMode
Util::SymbolicFileMode::SetGIDBit, Util::SymbolicFileMode::SetUIDBit, Util::SymbolicFileMode::StickyBit, Util::SymbolicFileMode::SymbolicMode, Util::SymbolicFileMode::SymbolicSpecialToBit
Instance Attribute Summary collapse
- #compile_time ⇒ Object readonly
- #environment ⇒ Object readonly
Class Method Summary collapse
-
.to_s ⇒ Object
Provide more helpful strings to the logging that the Agent does.
Instance Method Summary collapse
-
#apply_catalog(catalog, options) ⇒ Object
Retrieve (optionally) and apply a catalog.
-
#convert_catalog(result, duration) ⇒ Object
Convert a plain resource catalog into our full host catalog.
- #execute_postrun_command ⇒ Object
- #execute_prerun_command ⇒ Object
- #get_facts(options) ⇒ Object
-
#init_storage ⇒ Object
Initialize and load storage.
-
#initialize(factory = Puppet::Configurer::DownloaderFactory.new) ⇒ Configurer
constructor
A new instance of Configurer.
- #prepare_and_retrieve_catalog(options, query_options) ⇒ Object
-
#retrieve_catalog(query_options) ⇒ Object
Get the remote catalog, yo.
-
#run(options = {}) ⇒ Object
The code that actually runs the catalog.
- #save_last_run_summary(report) ⇒ Object
- #send_report(report) ⇒ Object
Methods included from Util
absolute_path?, benchmark, chuser, deterministic_rand, deterministic_rand_int, exit_on_fail, logmethods, path_to_uri, pretty_backtrace, replace_file, safe_posix_fork, symbolizehash, thinmark, uri_to_path, which, withenv, withumask
Methods included from Util::POSIX
#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
Methods included from Util::SymbolicFileMode
#normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?
Methods included from FactHandler
#facts_for_uploading, #find_facts
Constructor Details
#initialize(factory = Puppet::Configurer::DownloaderFactory.new) ⇒ Configurer
Returns a new instance of Configurer.
47 48 49 50 51 52 53 |
# File 'lib/puppet/configurer.rb', line 47 def initialize(factory = Puppet::Configurer::DownloaderFactory.new) @running = false @splayed = false @environment = Puppet[:environment] @transaction_uuid = SecureRandom.uuid @handler = Puppet::Configurer::PluginHandler.new(factory) end |
Instance Attribute Details
#compile_time ⇒ Object (readonly)
18 19 20 |
# File 'lib/puppet/configurer.rb', line 18 def compile_time @compile_time end |
#environment ⇒ Object (readonly)
18 19 20 |
# File 'lib/puppet/configurer.rb', line 18 def environment @environment end |
Class Method Details
.to_s ⇒ Object
Provide more helpful strings to the logging that the Agent does
21 22 23 |
# File 'lib/puppet/configurer.rb', line 21 def self.to_s "Puppet configuration client" end |
Instance Method Details
#apply_catalog(catalog, options) ⇒ Object
Retrieve (optionally) and apply a catalog. If a catalog is passed in the options, then apply that one, otherwise retrieve it.
113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/puppet/configurer.rb', line 113 def apply_catalog(catalog, ) report = [:report] begin report.configuration_version = catalog.version benchmark(:notice, "Applied catalog") do catalog.apply() end ensure report.finalize_report end report end |
#convert_catalog(result, duration) ⇒ Object
Convert a plain resource catalog into our full host catalog.
73 74 75 76 77 78 79 80 |
# File 'lib/puppet/configurer.rb', line 73 def convert_catalog(result, duration) catalog = result.to_ral catalog.finalize catalog.retrieval_duration = duration catalog.write_class_file catalog.write_resource_file catalog end |
#execute_postrun_command ⇒ Object
25 26 27 |
# File 'lib/puppet/configurer.rb', line 25 def execute_postrun_command execute_from_setting(:postrun_command) end |
#execute_prerun_command ⇒ Object
29 30 31 |
# File 'lib/puppet/configurer.rb', line 29 def execute_prerun_command execute_from_setting(:prerun_command) end |
#get_facts(options) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/puppet/configurer.rb', line 82 def get_facts() if [:pluginsync] remote_environment_for_plugins = Puppet::Node::Environment.remote(@environment) download_plugins(remote_environment_for_plugins) end facts_hash = {} if Puppet::Resource::Catalog.indirection.terminus_class == :rest # This is a bit complicated. We need the serialized and escaped facts, # and we need to know which format they're encoded in. Thus, we # get a hash with both of these pieces of information. # # facts_for_uploading may set Puppet[:node_name_value] as a side effect facts_hash = facts_for_uploading end facts_hash end |
#init_storage ⇒ Object
Initialize and load storage
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/puppet/configurer.rb', line 34 def init_storage Puppet::Util::Storage.load @compile_time ||= Puppet::Util::Storage.cache(:configuration)[:compile_time] rescue => detail Puppet.log_exception(detail, "Removing corrupt state file #{Puppet[:statefile]}: #{detail}") begin Puppet::FileSystem.unlink(Puppet[:statefile]) retry rescue => detail raise Puppet::Error.new("Cannot remove #{Puppet[:statefile]}: #{detail}", detail) end end |
#prepare_and_retrieve_catalog(options, query_options) ⇒ Object
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/puppet/configurer.rb', line 100 def prepare_and_retrieve_catalog(, ) # set report host name now that we have the fact [:report].host = Puppet[:node_name_value] unless catalog = (.delete(:catalog) || retrieve_catalog()) Puppet.err "Could not retrieve catalog; skipping run" return end catalog end |
#retrieve_catalog(query_options) ⇒ Object
Get the remote catalog, yo. Returns nil if no catalog can be found.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/puppet/configurer.rb', line 56 def retrieve_catalog() ||= {} # First try it with no cache, then with the cache. unless (Puppet[:use_cached_catalog] and result = retrieve_catalog_from_cache()) or result = retrieve_new_catalog() if ! Puppet[:usecacheonfailure] Puppet.warning "Not using cache on failed catalog" return nil end result = retrieve_catalog_from_cache() end return nil unless result convert_catalog(result, @duration) end |
#run(options = {}) ⇒ Object
The code that actually runs the catalog. This just passes any options on to the catalog, which accepts :tags and :ignoreschedules.
130 131 132 133 134 135 136 137 138 139 |
# File 'lib/puppet/configurer.rb', line 130 def run( = {}) pool = Puppet::Network::HTTP::Pool.new(Puppet[:http_keepalive_timeout]) begin Puppet.override(:http_pool => pool) do run_internal() end ensure pool.close end end |
#save_last_run_summary(report) ⇒ Object
260 261 262 263 264 265 266 267 |
# File 'lib/puppet/configurer.rb', line 260 def save_last_run_summary(report) mode = Puppet.settings.setting(:lastrunfile).mode Puppet::Util.replace_file(Puppet[:lastrunfile], mode) do |fh| fh.print YAML.dump(report.raw_summary) end rescue => detail Puppet.log_exception(detail, "Could not save last run local report: #{detail}") end |
#send_report(report) ⇒ Object
252 253 254 255 256 257 258 |
# File 'lib/puppet/configurer.rb', line 252 def send_report(report) puts report.summary if Puppet[:summarize] save_last_run_summary(report) Puppet::Transaction::Report.indirection.save(report, nil, :environment => Puppet::Node::Environment.remote(@environment)) if Puppet[:report] rescue => detail Puppet.log_exception(detail, "Could not send report: #{detail}") end |