module Puppet::Indirector::FactSearch

module containing common methods used by json and yaml facts indirection terminus

Public Instance Methods

compare_facts(operator, value1, value2) click to toggle source
   # File lib/puppet/indirector/fact_search.rb
25 def compare_facts(operator, value1, value2)
26   return false unless value1
27 
28   case operator
29   when "eq"
30     value1.to_s == value2.to_s
31   when "le"
32     value1.to_f <= value2.to_f
33   when "ge"
34     value1.to_f >= value2.to_f
35   when "lt"
36     value1.to_f < value2.to_f
37   when "gt"
38     value1.to_f > value2.to_f
39   when "ne"
40     value1.to_s != value2.to_s
41   end
42 end
compare_timestamp(operator, value1, value2) click to toggle source
   # File lib/puppet/indirector/fact_search.rb
44 def compare_timestamp(operator, value1, value2)
45   case operator
46   when "eq"
47     value1 == value2
48   when "le"
49     value1 <= value2
50   when "ge"
51     value1 >= value2
52   when "lt"
53     value1 < value2
54   when "gt"
55     value1 > value2
56   when "ne"
57     value1 != value2
58   end
59 end
node_matches?(facts, options) click to toggle source
   # File lib/puppet/indirector/fact_search.rb
 3 def node_matches?(facts, options)
 4   options.each do |key, value|
 5     type, name, operator = key.to_s.split(".")
 6     operator ||= 'eq'
 7 
 8     return false unless node_matches_option?(type, name, operator, value, facts)
 9   end
10   return true
11 end
node_matches_option?(type, name, operator, value, facts) click to toggle source
   # File lib/puppet/indirector/fact_search.rb
13 def node_matches_option?(type, name, operator, value, facts)
14   case type
15   when "meta"
16     case name
17     when "timestamp"
18       compare_timestamp(operator, facts.timestamp, Time.parse(value))
19     end
20   when "facts"
21     compare_facts(operator, facts.values[name], value)
22   end
23 end