summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util/plugins.rb
Commit message (Collapse)AuthorAgeFilesLines
* (#6490) Add plugin initialization callback system to coreMarkus Roberts2011-04-061-0/+82
The recurring pattern "drop-in code needs to have something done at startup" is presently being solved with a variety of ad-hock mechanism. This commit adds a general, extensible, centralized system for adding such hooks and manages an extensible set of metadata about plugins which it collects by searching for files named "plugin_init.rb" in a series of directories. Initially, these are simply the $LOAD_PATH. Applications can add more places to look for plugins without risk of adding duplicates or changing the order of ones that have already been found with: Puppet::Plugins.look_in(*paths) The contents of each file found is executed in the context of a Puppet::Plugins object (and thus scoped). An example file might contain: ------------------------------------------------------- @name = "Greet the CA" @description = %q{ This plugin causes a friendly greeting to print out on a master that is operating as the CA, after it has been set up but before it does anything. } def after_application_setup(options) if options[:application_object].is_a?(Puppet::Application::Master) && Puppet::SSL::CertificateAuthority.ca? puts "Hey, this is the CA! Hi everyone!!!" end end ------------------------------------------------------- Note that the instance variables are local to this Puppet::Plugin (and so may be used for maintaining state, etc.) but the plugin system does not provide any thread safety assurances, so they may not be adequate for some complex use cases. Presently supported hooks: before_application_preinit( :application_object => ... ) after_application_preinit( :application_object => ... ) before_application_parse_options( :application_object => ... ) after_application_parse_options( :application_object => ... ) before_application_setup( :application_object => ... ) after_application_setup( :application_object => ... ) before_application_run_command( :application_object => ... ) after_application_run_command( :application_object => ... ) on_commandline_initialization(:command_line_object => ... ) on_application_initialization(:appliation_object => ... ) Paired-with: Daniel Pitman