Class: Puppet::Node::Facts::Facter

Inherits:
Indirector::Code show all
Defined in:
lib/vendor/puppet/indirector/facts/facter.rb

Constant Summary

Constants included from Util

Util::AbsolutePathPosix, Util::AbsolutePathWindows

Constants included from Util::Docs

Util::Docs::HEADER_LEVELS

Instance Attribute Summary

Attributes included from Util::Docs

#doc, #nodoc

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Indirector::Terminus

abstract_terminus?, const2name, #indirection, indirection_name, inherited, #initialize, 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

absolute_path?, activerecord_version, benchmark, binread, chuser, classproxy, #execfail, #execpipe, execute, execute_posix, execute_windows, logmethods, memory, path_to_uri, proxy, replace_file, safe_posix_fork, symbolize, symbolizehash, symbolizehash!, synchronize_on, thinmark, #threadlock, uri_to_path, wait_for_output, 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, #markdown_definitionlist, #markdown_header, #nodoc?, #pad, scrub

Constructor Details

This class inherits a constructor from Puppet::Indirector::Terminus

Class Method Details

.load_fact_pluginsObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/vendor/puppet/indirector/facts/facter.rb', line 26

def self.load_fact_plugins
  # Add any per-module fact directories to the factpath
  module_fact_dirs = Puppet[:modulepath].split(File::PATH_SEPARATOR).collect do |d|
    ["lib", "plugins"].map do |subdirectory|
      Dir.glob("#{d}/*/#{subdirectory}/facter")
    end
  end.flatten
  dirs = module_fact_dirs + Puppet[:factpath].split(File::PATH_SEPARATOR)
  x = dirs.uniq.each do |dir|
    load_facts_in_dir(dir)
  end
end

.load_facts_in_dir(dir) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/vendor/puppet/indirector/facts/facter.rb', line 39

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 #{fqfile}"
        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

.reload_facterObject

Clear out all of the loaded facts. Reload facter but not puppet facts. NOTE: This is clumsy and shouldn’t be required for later (1.5.x) versions of Facter.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/vendor/puppet/indirector/facts/facter.rb', line 13

def self.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
end

.timeoutObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/vendor/puppet/indirector/facts/facter.rb', line 59

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

Raises:



76
77
78
# File 'lib/vendor/puppet/indirector/facts/facter.rb', line 76

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.



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/vendor/puppet/indirector/facts/facter.rb', line 81

def find(request)
  self.class.reload_facter
  self.class.load_fact_plugins
  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

Raises:



93
94
95
# File 'lib/vendor/puppet/indirector/facts/facter.rb', line 93

def save(facts)
  raise Puppet::DevError, "You cannot save facts to the code store; it is only used for getting facts from Facter"
end