diff options
| author | Luke Kanies <luke@madstop.com> | 2009-01-22 16:05:43 -0600 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2009-02-06 18:08:40 -0600 |
| commit | 54faf7825bbffc5a4ca252389305dd23ae8d2d84 (patch) | |
| tree | c9d059cb83b3f0de52ddc52c33278eb53dd2edd7 /lib/puppet/agent | |
| parent | 9d76b70c07c86f0041a0e6a1537227de1b619017 (diff) | |
| download | puppet-54faf7825bbffc5a4ca252389305dd23ae8d2d84.tar.gz puppet-54faf7825bbffc5a4ca252389305dd23ae8d2d84.tar.xz puppet-54faf7825bbffc5a4ca252389305dd23ae8d2d84.zip | |
Moving fact and plugin handling into modules
This doesn't change functionality, it just simplifies
the agent class.
I've also started the work to get the catalog handling
done using REST/the Indirector.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet/agent')
| -rw-r--r-- | lib/puppet/agent/downloader.rb | 3 | ||||
| -rw-r--r-- | lib/puppet/agent/fact_handler.rb | 71 | ||||
| -rw-r--r-- | lib/puppet/agent/plugin_handler.rb | 25 |
3 files changed, 98 insertions, 1 deletions
diff --git a/lib/puppet/agent/downloader.rb b/lib/puppet/agent/downloader.rb index 46a64d52d..edc5931c3 100644 --- a/lib/puppet/agent/downloader.rb +++ b/lib/puppet/agent/downloader.rb @@ -1,4 +1,5 @@ require 'puppet/agent' +require 'puppet/resource/catalog' class Puppet::Agent::Downloader attr_reader :name, :path, :source, :ignore @@ -48,7 +49,7 @@ class Puppet::Agent::Downloader end def catalog - catalog = Puppet::Node::Catalog.new + catalog = Puppet::Resource::Catalog.new catalog.add_resource(file) catalog end diff --git a/lib/puppet/agent/fact_handler.rb b/lib/puppet/agent/fact_handler.rb new file mode 100644 index 000000000..4c9280bfc --- /dev/null +++ b/lib/puppet/agent/fact_handler.rb @@ -0,0 +1,71 @@ +# Break out the code related to facts. This module is +# just included into the agent, but having it here makes it +# easier to test. +module Puppet::Agent::FactHandler + def download_fact_plugins? + Puppet[:factsync] + end + + def upload_facts + # XXX down = Puppet[:downcasefacts] + + reload_facter() + + # This works because puppetd configures Facts to use 'facter' for + # finding facts and the 'rest' terminus for caching them. Thus, we'll + # compile them and then "cache" them on the server. + Puppet::Node::Facts.find(Puppet[:certname]) + end + + # Retrieve facts from the central server. + def download_fact_plugins + return unless download_fact_plugins? + + Puppet::Agent::Downloader.new("fact", Puppet[:factsource], Puppet[:factdest], Puppet[:factsignore]).evaluate + end + + def load_fact_plugins + # LAK:NOTE See http://snurl.com/21zf8 [groups_google_com] + x = Puppet[:factpath].split(":").each do |dir| + load_facts_in_dir(dir) + end + end + + def load_facts_in_dir(dir) + return unless FileTest.directory?(dir) + + Dir.chdir(dir) do + Dir.glob("*.rb").each do |file| + fqfile = ::File.join(dir, file) + begin + Puppet.info "Loading facts in %s" % [::File.basename(file.sub(".rb",''))] + Timeout::timeout(Puppet::Agent.timeout) do + load file + end + rescue => detail + Puppet.warning "Could not load fact file %s: %s" % [fqfile, detail] + end + end + end + end + + # Clear out all of the loaded facts and reload them from disk. + # NOTE: This is clumsy and shouldn't be required for later (1.5.x) versions + # of Facter. + def reload_facter + Facter.clear + + # Reload everything. + if Facter.respond_to? :loadfacts + Facter.loadfacts + elsif Facter.respond_to? :load + Facter.load + else + Puppet.warning "You should upgrade your version of Facter to at least 1.3.8" + end + + # This loads all existing facts and any new ones. We have to remove and + # reload because there's no way to unload specific facts. + load_fact_plugins() + end +end diff --git a/lib/puppet/agent/plugin_handler.rb b/lib/puppet/agent/plugin_handler.rb new file mode 100644 index 000000000..306b8b6df --- /dev/null +++ b/lib/puppet/agent/plugin_handler.rb @@ -0,0 +1,25 @@ +# Break out the code related to plugins. This module is +# just included into the agent, but having it here makes it +# easier to test. +module Puppet::Agent::PluginHandler + def download_plugins? + Puppet[:pluginsync] + end + + # Retrieve facts from the central server. + def download_plugins + return nil unless download_plugins? + Puppet::Agent::Downloader.new("plugin", Puppet[:pluginsource], Puppet[:plugindest], Puppet[:pluginsignore]).evaluate.each { |file| load_plugin(file) } + end + + def load_plugin(file) + return if FileTest.directory?(file) + + begin + Puppet.info "Loading downloaded plugin %s" % file + load file + rescue Exception => detail + Puppet.err "Could not load downloaded file %s: %s" % [file, detail] + end + end +end |
