diff options
| author | Paul Berry <paul@puppetlabs.com> | 2010-11-01 13:48:48 -0700 |
|---|---|---|
| committer | Paul Berry <paul@puppetlabs.com> | 2010-11-01 13:48:48 -0700 |
| commit | a82f4d23fe5a025b8a9e893d29933f092973f014 (patch) | |
| tree | 7db8f8f29f3c20235940374f7f6a68f6d92a247b /lib/puppet | |
| parent | ee4eda825c33469e09c88a1f8c4234202cce5ce9 (diff) | |
| parent | 3d32fe836eefac1974e00b2763322c998b452ddb (diff) | |
| download | puppet-a82f4d23fe5a025b8a9e893d29933f092973f014.tar.gz puppet-a82f4d23fe5a025b8a9e893d29933f092973f014.tar.xz puppet-a82f4d23fe5a025b8a9e893d29933f092973f014.zip | |
Merge branch 'ticket/next/5166' into next
Diffstat (limited to 'lib/puppet')
| -rw-r--r-- | lib/puppet/indirector/inventory/yaml.rb | 68 |
1 files changed, 51 insertions, 17 deletions
diff --git a/lib/puppet/indirector/inventory/yaml.rb b/lib/puppet/indirector/inventory/yaml.rb index c6b1a14aa..fe3489a95 100644 --- a/lib/puppet/indirector/inventory/yaml.rb +++ b/lib/puppet/indirector/inventory/yaml.rb @@ -15,23 +15,7 @@ class Puppet::Node::Inventory::Yaml < Puppet::Indirector::Yaml type, name, operator = key.to_s.split(".") operator ||= 'eq' - next unless type == "facts" - return false unless facts.values[name] - - return false unless case operator - when "eq" - facts.values[name].to_s == value.to_s - when "le" - facts.values[name].to_f <= value.to_f - when "ge" - facts.values[name].to_f >= value.to_f - when "lt" - facts.values[name].to_f < value.to_f - when "gt" - facts.values[name].to_f > value.to_f - when "ne" - facts.values[name].to_s != value.to_s - end + return false unless node_matches_option?(type, name, operator, value, facts) end return true end @@ -44,4 +28,54 @@ class Puppet::Node::Inventory::Yaml < Puppet::Indirector::Yaml end node_names end + + private + + def node_matches_option?(type, name, operator, value, facts) + case type + when "meta" + case name + when "timestamp" + compare_timestamp(operator, facts.timestamp, Time.parse(value)) + end + when "facts" + compare_facts(operator, facts.values[name], value) + end + end + + 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 + + def compare_timestamp(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 end |
