diff options
author | Nick Lewis <nick@puppetlabs.com> | 2010-10-28 12:49:19 -0700 |
---|---|---|
committer | Nick Lewis <nick@puppetlabs.com> | 2010-10-28 13:23:29 -0700 |
commit | c2ea112de1f08707aa301060b4df24bd0bb6072a (patch) | |
tree | bf6e966bd8f83a42b6fb8b4f6270fb624e450ed6 /lib/puppet/node | |
parent | 85543a41978924a42490d0c3f1f5437c95b7c869 (diff) | |
download | puppet-c2ea112de1f08707aa301060b4df24bd0bb6072a.tar.gz puppet-c2ea112de1f08707aa301060b4df24bd0bb6072a.tar.xz puppet-c2ea112de1f08707aa301060b4df24bd0bb6072a.zip |
(#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.
Diffstat (limited to 'lib/puppet/node')
-rwxr-xr-x | lib/puppet/node/facts.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/puppet/node/facts.rb b/lib/puppet/node/facts.rb index b77ad22d5..ad4b91e98 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 @@ -54,6 +59,22 @@ class Puppet::Node::Facts strip_internal == other.send(:strip_internal) end + def self.from_pson(data) + result = new(data['name'], data['values']) + result.values[:_timestamp] = Time.parse(data['timestamp']) + result.expiration = Time.parse(data['expiration']) + result + end + + def to_pson(*args) + { + 'expiration' => expiration, + 'name' => name, + 'timestamp' => values[:_timestamp], + 'values' => values.reject {|k,v| k == :_timestamp}, + }.to_pson(*args) + end + private # Add internal data to the facts for storage. |