summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorNick Lewis <nick@puppetlabs.com>2011-03-03 16:58:07 -0800
committerNick Lewis <nick@puppetlabs.com>2011-03-03 16:58:07 -0800
commitc65ef89e533e73d0f9ec34244be630bae00b53d5 (patch)
treeeb68cab014a36166326e5a20d9df47aa0e14ab3e /lib/puppet
parentf519899dacab51c23db3ecf043feb481d1aa4bc1 (diff)
parentc3baa2899d88fadd4bbe94e008015e33f98132c7 (diff)
downloadpuppet-c65ef89e533e73d0f9ec34244be630bae00b53d5.tar.gz
puppet-c65ef89e533e73d0f9ec34244be630bae00b53d5.tar.xz
puppet-c65ef89e533e73d0f9ec34244be630bae00b53d5.zip
Merge branch 'ticket/2.6.next/6581' into 2.6.next
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/indirector/facts/yaml.rb75
-rw-r--r--lib/puppet/indirector/inventory/yaml.rb81
-rw-r--r--lib/puppet/node.rb1
-rw-r--r--lib/puppet/node/inventory.rb7
4 files changed, 75 insertions, 89 deletions
diff --git a/lib/puppet/indirector/facts/yaml.rb b/lib/puppet/indirector/facts/yaml.rb
index 89feaf2ab..65bd78354 100644
--- a/lib/puppet/indirector/facts/yaml.rb
+++ b/lib/puppet/indirector/facts/yaml.rb
@@ -4,4 +4,79 @@ require 'puppet/indirector/yaml'
class Puppet::Node::Facts::Yaml < Puppet::Indirector::Yaml
desc "Store client facts as flat files, serialized using YAML, or
return deserialized facts from disk."
+
+ def search(request)
+ node_names = []
+ Dir.glob(yaml_dir_path).each do |file|
+ facts = YAML.load_file(file)
+ node_names << facts.name if node_matches?(facts, request.options)
+ end
+ node_names
+ end
+
+ private
+
+ # Return the path to a given node's file.
+ def yaml_dir_path
+ base = Puppet.run_mode.master? ? Puppet[:yamldir] : Puppet[:clientyamldir]
+ File.join(base, 'facts', '*.yaml')
+ end
+
+ def node_matches?(facts, options)
+ options.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
+ return true
+ end
+
+ 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
diff --git a/lib/puppet/indirector/inventory/yaml.rb b/lib/puppet/indirector/inventory/yaml.rb
deleted file mode 100644
index fe3489a95..000000000
--- a/lib/puppet/indirector/inventory/yaml.rb
+++ /dev/null
@@ -1,81 +0,0 @@
-require 'puppet/node/inventory'
-require 'puppet/indirector/yaml'
-
-class Puppet::Node::Inventory::Yaml < Puppet::Indirector::Yaml
- desc "Return node names matching the fact query"
-
- # Return the path to a given node's file.
- def yaml_dir_path
- base = Puppet.run_mode.master? ? Puppet[:yamldir] : Puppet[:clientyamldir]
- File.join(base, 'facts', '*.yaml')
- end
-
- def node_matches?(facts, options)
- options.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
- return true
- end
-
- def search(request)
- node_names = []
- Dir.glob(yaml_dir_path).each do |file|
- facts = YAML.load_file(file)
- node_names << facts.name if node_matches?(facts, request.options)
- 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
diff --git a/lib/puppet/node.rb b/lib/puppet/node.rb
index e8d58e6be..2453cd1d5 100644
--- a/lib/puppet/node.rb
+++ b/lib/puppet/node.rb
@@ -3,7 +3,6 @@ require 'puppet/indirector'
# A class for managing nodes, including their facts and environment.
class Puppet::Node
require 'puppet/node/facts'
- require 'puppet/node/inventory'
require 'puppet/node/environment'
# Set up indirection, so that nodes can be looked for in
diff --git a/lib/puppet/node/inventory.rb b/lib/puppet/node/inventory.rb
deleted file mode 100644
index fd99163b0..000000000
--- a/lib/puppet/node/inventory.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require 'puppet/node'
-require 'puppet/indirector'
-
-class Puppet::Node::Inventory
- extend Puppet::Indirector
- indirects :inventory, :terminus_setting => :inventory_terminus
-end