f2bd19f197ae4177d40e1a6f88fb72dbe9e6dfd8
[packages/precise/mcollective.git] / lib / mcollective / facts.rb
1 module MCollective
2   # This is a class that gives access to the configured fact provider
3   # such as MCollectives::Facts::Facter that uses Reductive Labs facter
4   #
5   # The actual provider is pluggable and configurable using the 'factsource'
6   # configuration option.
7   #
8   # To develop a new factsource simply create a class under MCollective::Facts::
9   # and provide the following classes:
10   #
11   #   self.get_fact(fact)
12   #   self.has_fact?(fact)
13   #
14   # You can also just inherit from MCollective::Facts::Base and provide just the
15   #
16   #   self.get_facts
17   #
18   # method that should return a hash of facts.
19   module Facts
20     autoload :Base, "mcollective/facts/base"
21
22     @@config = nil
23
24     # True if we know of a specific fact else false
25     def self.has_fact?(fact, value)
26       PluginManager["facts_plugin"].get_fact(fact) == value ? true : false
27     end
28
29     # Get the value of a fact
30     def self.get_fact(fact)
31       PluginManager["facts_plugin"].get_fact(fact)
32     end
33
34     # Get the value of a fact
35     def self.[](fact)
36       PluginManager["facts_plugin"].get_fact(fact)
37     end
38   end
39 end