| Module | MCollective::PluginManager |
| In: |
lib/mcollective/pluginmanager.rb
|
A simple plugin manager, it stores one plugin each of a specific type the idea is that we can only have one security provider, one connector etc.
Adds a plugin to the list of plugins, we expect a hash like:
{:type => "base",
:class => foo.new}
or like:
{:type => "base",
:class => "Foo::Bar"}
In the event that we already have a class with the given type an exception will be raised.
If the :class passed is a String then we will delay instantiation till the first time someone asks for the plugin, this is because most likely the registration gets done by inherited() hooks, at which point the plugin class is not final.
If we were to do a .new here the Class initialize method would get called and not the plugins, we there for only initialize the classes when they get requested via []
By default all plugin instances are cached and returned later so there‘s always a single instance. You can pass :single_instance => false when calling this to instruct it to always return a new instance when a copy is requested. This only works with sending a String for :class.
Finds plugins in all configured libdirs
find("agent")
will return an array of just agent names, for example:
["puppetd", "package"]
Can also be used to find files of other extensions:
find("agent", "ddl")
Will return the same list but only of files with extension .ddl in the agent subdirectory
Finds and loads from disk all plugins from all libdirs that match certain criteria.
find_and_load("pluginpackager")
Will find all .rb files in the libdir/mcollective/pluginpackager/ directory in all libdirs and load them from disk.
You can influence what plugins get loaded using a block notation:
find_and_load("pluginpackager") do |plugin|
plugin.match(/puppet/)
end
This will load only plugins matching /puppet/