From 23fc4db954c22bce2c6cc8996d5fafb175e2b747 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Thu, 17 Feb 2011 14:59:59 -0800 Subject: (#5132) Provide a query REST interface for inventory This REST interface returns a list of nodes that match a fact query. Fact queries can use (in)equality testing as a string comparison, and >, <, >=, <= numerical comparisons. Multiple tests can be done as AND comparisons, not OR. The fact queries need to be prefixed by facts, and the comparisons other than equality are specified with a .comparison_type after the fact name. This will be better explained in the REST documentation on the website. Searches that don't match anything now return empty array instead of a 404 error. Conflicts: spec/spec_helper.rb --- lib/puppet/node/inventory.rb | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 lib/puppet/node/inventory.rb (limited to 'lib/puppet/node') diff --git a/lib/puppet/node/inventory.rb b/lib/puppet/node/inventory.rb new file mode 100644 index 000000000..fd99163b0 --- /dev/null +++ b/lib/puppet/node/inventory.rb @@ -0,0 +1,7 @@ +require 'puppet/node' +require 'puppet/indirector' + +class Puppet::Node::Inventory + extend Puppet::Indirector + indirects :inventory, :terminus_setting => :inventory_terminus +end -- cgit From 2d2f9ab04d8d6964df99762f73d329b0e5e57d8a Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Thu, 17 Feb 2011 15:15:50 -0800 Subject: Maint: backport timestamp accessor for facts from 2.7 branch Paired-with: Jesse Wolfe --- lib/puppet/node/facts.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/puppet/node') diff --git a/lib/puppet/node/facts.rb b/lib/puppet/node/facts.rb index b77ad22d5..562690026 100755 --- a/lib/puppet/node/facts.rb +++ b/lib/puppet/node/facts.rb @@ -54,6 +54,14 @@ class Puppet::Node::Facts strip_internal == other.send(:strip_internal) end + def timestamp=(time) + self.values[:_timestamp] = time + end + + def timestamp + self.values[:_timestamp] + end + private # Add internal data to the facts for storage. -- cgit From c3baa2899d88fadd4bbe94e008015e33f98132c7 Mon Sep 17 00:00:00 2001 From: Nick Lewis Date: Thu, 3 Mar 2011 14:12:44 -0800 Subject: (#6338) Remove inventory indirection, and move to facts indirection The inventory indirection was just providing the search method for facts. Because the route is now facts_search instead of inventory, it can just be implemented as the search method for facts. Reviewed-By: Daniel Pittman --- lib/puppet/node/inventory.rb | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 lib/puppet/node/inventory.rb (limited to 'lib/puppet/node') 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 -- cgit From 8bd80a99a259e6409a9ac0a8a60325f94b5c5e9d Mon Sep 17 00:00:00 2001 From: Nick Lewis Date: Thu, 28 Oct 2010 12:49:19 -0700 Subject: (#5148) Add support for PSON to facts Previously, facts could be fetched via the REST API in PSON, but came back as the to_s representation of a Ruby object, rather than as proper PSON data. This patch adds to_pson and from_pson to facts, so they can be properly used with PSON. --- lib/puppet/node/facts.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'lib/puppet/node') diff --git a/lib/puppet/node/facts.rb b/lib/puppet/node/facts.rb index 562690026..0a96e553b 100755 --- a/lib/puppet/node/facts.rb +++ b/lib/puppet/node/facts.rb @@ -1,12 +1,17 @@ +require 'time' + require 'puppet/node' require 'puppet/indirector' +require 'puppet/util/pson' + # Manage a given node's facts. This either accepts facts and stores them, or # returns facts for a given node. class Puppet::Node::Facts # Set up indirection, so that nodes can be looked for in # the node sources. extend Puppet::Indirector + extend Puppet::Util::Pson # We want to expire any cached nodes if the facts are saved. module NodeExpirer @@ -62,6 +67,22 @@ class Puppet::Node::Facts self.values[:_timestamp] end + def self.from_pson(data) + result = new(data['name'], data['values']) + result.timestamp = Time.parse(data['timestamp']) + result.expiration = Time.parse(data['expiration']) + result + end + + def to_pson(*args) + { + 'expiration' => expiration, + 'name' => name, + 'timestamp' => timestamp, + 'values' => strip_internal, + }.to_pson(*args) + end + private # Add internal data to the facts for storage. -- cgit