Manage a given node’s facts. This either accepts facts and stores them, or returns facts for a given node.
# File lib/puppet/node/facts.rb, line 52 def self.from_pson(data) result = new(data['name'], data['values']) result.timestamp = Time.parse(data['timestamp']) if data['timestamp'] result.expiration = Time.parse(data['expiration']) if data['expiration'] result end
# File lib/puppet/node/facts.rb, line 33 def initialize(name, values = {}) @name = name @values = values add_timestamp end
# File lib/puppet/node/facts.rb, line 47 def ==(other) return false unless self.name == other.name strip_internal == other.send(:strip_internal) end
# File lib/puppet/node/facts.rb, line 28 def add_local_facts values["clientcert"] = Puppet.settings[:certname] values["clientversion"] = Puppet.version.to_s end
Add internal data to the facts for storage.
# File lib/puppet/node/facts.rb, line 72 def add_timestamp self.timestamp = Time.now end
Convert all fact values into strings.
# File lib/puppet/node/facts.rb, line 41 def stringify values.each do |fact, value| values[fact] = value.to_s end end
# File lib/puppet/node/facts.rb, line 80 def timestamp self.values[:_timestamp] end
# File lib/puppet/node/facts.rb, line 76 def timestamp=(time) self.values[:_timestamp] = time end
# File lib/puppet/node/facts.rb, line 59 def to_pson(*args) result = { 'name' => name, 'values' => strip_internal, } result['timestamp'] = timestamp if timestamp result['expiration'] = expiration if expiration result.to_pson(*args) end
Strip out that internal data.
# File lib/puppet/node/facts.rb, line 87 def strip_internal newvals = values.dup newvals.find_all { |name, value| name.to_s =~ /^_/ }.each { |name, value| newvals.delete(name) } newvals end