Module: Puppet::Indirector::FactSearch
- Included in:
- Node::Facts::Json, Node::Facts::Yaml
- Defined in:
- lib/puppet/indirector/fact_search.rb
Overview
module containing common methods used by json and yaml facts indirection terminus
Instance Method Summary collapse
- #compare_facts(operator, value1, value2) ⇒ Object
- #compare_timestamp(operator, value1, value2) ⇒ Object
- #node_matches?(facts, options) ⇒ Boolean
- #node_matches_option?(type, name, operator, value, facts) ⇒ Boolean
Instance Method Details
#compare_facts(operator, value1, value2) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/puppet/indirector/fact_search.rb', line 27 def compare_facts(operator, value1, value2) return false unless value1 case operator when "eq" value1.to_s == value2.to_s when "le" value1.to_f <= value2.to_f when "ge" value1.to_f >= value2.to_f when "lt" value1.to_f < value2.to_f when "gt" value1.to_f > value2.to_f when "ne" value1.to_s != value2.to_s end end |
#compare_timestamp(operator, value1, value2) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/puppet/indirector/fact_search.rb', line 46 def (operator, value1, value2) case operator when "eq" value1 == value2 when "le" value1 <= value2 when "ge" value1 >= value2 when "lt" value1 < value2 when "gt" value1 > value2 when "ne" value1 != value2 end end |
#node_matches?(facts, options) ⇒ Boolean
5 6 7 8 9 10 11 12 13 |
# File 'lib/puppet/indirector/fact_search.rb', line 5 def node_matches?(facts, ) .each do |key, value| type, name, operator = key.to_s.split(".") operator ||= 'eq' return false unless node_matches_option?(type, name, operator, value, facts) end true end |
#node_matches_option?(type, name, operator, value, facts) ⇒ Boolean
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/puppet/indirector/fact_search.rb', line 15 def node_matches_option?(type, name, operator, value, facts) case type when "meta" case name when "timestamp" (operator, facts., Time.parse(value)) end when "facts" compare_facts(operator, facts.values[name], value) end end |