Class: Puppet::Node::Facts::Facter
- Inherits:
-
Indirector::Code
- Object
- Indirector::Terminus
- Indirector::Code
- Puppet::Node::Facts::Facter
- Defined in:
- lib/puppet/indirector/facts/facter.rb
Instance Attribute Summary
Attributes included from Util::Docs
Class Method Summary collapse
Instance Method Summary collapse
- #destroy(facts) ⇒ Object
-
#find(request) ⇒ Object
Look a host’s facts up in Facter.
-
#initialize(*args) ⇒ Facter
constructor
A new instance of Facter.
- #save(facts) ⇒ Object
Methods inherited from Indirector::Terminus
abstract_terminus?, const2name, #indirection, indirection_name, inherited, mark_as_abstract_terminus, #model, model, #name, name2const, register_terminus_class, terminus_class, terminus_classes, #terminus_type
Methods included from Util::InstanceLoader
#instance_docs, #instance_hash, #instance_load, #instance_loader, #instance_loading?, #loaded_instance, #loaded_instances
Methods included from Util
activerecord_version, benchmark, chuser, classproxy, #execfail, #execpipe, execute, logmethods, memory, proxy, recmkdir, secure_open, symbolize, symbolizehash, symbolizehash!, synchronize_on, thinmark, #threadlock, which, withumask
Methods included from Util::POSIX
#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
Methods included from Util::Docs
#desc, #dochook, #doctable, #nodoc?, #pad, scrub
Constructor Details
#initialize(*args) ⇒ Facter
Returns a new instance of Facter.
60 61 62 63 |
# File 'lib/puppet/indirector/facts/facter.rb', line 60 def initialize(*args) super self.class.load_fact_plugins end |
Class Method Details
.load_fact_plugins ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/puppet/indirector/facts/facter.rb', line 10 def self.load_fact_plugins # Add any per-module fact directories to the factpath module_fact_dirs = Puppet[:modulepath].split(":").collect do |d| ["lib", "plugins"].map do |subdirectory| Dir.glob("#{d}/*/#{subdirectory}/facter") end end.flatten dirs = module_fact_dirs + Puppet[:factpath].split(":") x = dirs.each do |dir| load_facts_in_dir(dir) end end |
.load_facts_in_dir(dir) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/puppet/indirector/facts/facter.rb', line 23 def self.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 #{::File.basename(file.sub(".rb",''))}" Timeout::timeout(self.timeout) do load file end rescue SystemExit,NoMemoryError raise rescue Exception => detail Puppet.warning "Could not load fact file #{fqfile}: #{detail}" end end end end |
.timeout ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/puppet/indirector/facts/facter.rb', line 43 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 timeout end |
Instance Method Details
#destroy(facts) ⇒ Object
65 66 67 |
# File 'lib/puppet/indirector/facts/facter.rb', line 65 def destroy(facts) raise Puppet::DevError, "You cannot destroy facts in the code store; it is only used for getting facts from Facter" end |
#find(request) ⇒ Object
Look a host’s facts up in Facter.
70 71 72 73 74 75 76 77 78 |
# File 'lib/puppet/indirector/facts/facter.rb', line 70 def find(request) result = Puppet::Node::Facts.new(request.key, Facter.to_hash) result.add_local_facts result.stringify result.downcase_if_necessary result end |
#save(facts) ⇒ Object
80 81 82 |
# File 'lib/puppet/indirector/facts/facter.rb', line 80 def save(facts) raise Puppet::DevError, "You cannot save facts to the code store; it is only used for getting facts from Facter" end |