summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-12-11 14:17:56 -0600
committerLuke Kanies <luke@madstop.com>2007-12-11 14:17:56 -0600
commita21ee0059fbfc31988430e7e6bf0d102cb6f1d5a (patch)
treec4a537d683b6c8447a0918c3567a0b95b38d0cda /lib
parentadd245a12ae65b0254165d6724143e4be99387f8 (diff)
downloadpuppet-a21ee0059fbfc31988430e7e6bf0d102cb6f1d5a.tar.gz
puppet-a21ee0059fbfc31988430e7e6bf0d102cb6f1d5a.tar.xz
puppet-a21ee0059fbfc31988430e7e6bf0d102cb6f1d5a.zip
Copying the fact-loading code from the network client to
the Facter terminus until I have a better solution. This problem was discovered becomes of #958.
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/indirector/facts/facter.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/puppet/indirector/facts/facter.rb b/lib/puppet/indirector/facts/facter.rb
index 96d22e0c1..5b9a7b3c0 100644
--- a/lib/puppet/indirector/facts/facter.rb
+++ b/lib/puppet/indirector/facts/facter.rb
@@ -6,6 +6,50 @@ class Puppet::Node::Facts::Facter < Puppet::Indirector::Code
between Puppet and Facter. It's only `somewhat` abstract because it always
returns the local host's facts, regardless of what you attempt to find."
+ def self.loaddir(dir, type)
+ return unless FileTest.directory?(dir)
+
+ Dir.entries(dir).find_all { |e| e =~ /\.rb$/ }.each do |file|
+ fqfile = ::File.join(dir, file)
+ begin
+ Puppet.info "Loading #{type} %s" % ::File.basename(file.sub(".rb",''))
+ Timeout::timeout(self.timeout) do
+ load fqfile
+ end
+ rescue => detail
+ Puppet.warning "Could not load #{type} %s: %s" % [fqfile, detail]
+ end
+ end
+ end
+
+ def self.loadfacts
+ Puppet[:factpath].split(":").each do |dir|
+ loaddir(dir, "fact")
+ end
+ end
+
+ def self.timeout
+ timeout = Puppet[:configtimeout]
+ case timeout
+ when String:
+ if timeout =~ /^\d+$/
+ timeout = Integer(timeout)
+ else
+ raise ArgumentError, "Configuration timeout must be an integer"
+ end
+ when Integer: # nothing
+ else
+ raise ArgumentError, "Configuration timeout must be an integer"
+ end
+
+ return timeout
+ end
+
+ def initialize(*args)
+ super
+ self.class.loadfacts
+ end
+
def destroy(facts)
raise Puppet::DevError, "You cannot destroy facts in the code store; it is only used for getting facts from Facter"
end