Class: Puppet::Node::Facts
Overview
Manage a given node’s facts. This either accepts facts and stores them, or returns facts for a given node.
Defined Under Namespace
Modules: NodeExpirer Classes: Facter, Json, Memory, NetworkDevice, Rest, StoreConfigs, Yaml
Constant Summary
Constants included from Indirector
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#values ⇒ Object
Returns the value of attribute values.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#add_extra_values(extra_values) ⇒ Object
private
Add extra values, such as facts given to lookup on the command line.
- #add_local_facts ⇒ Object
- #add_timestamp ⇒ Object
-
#initialize(name, values = {}) ⇒ Facts
constructor
A new instance of Facts.
- #initialize_from_hash(data) ⇒ Object
-
#sanitize ⇒ Object
Sanitize fact values by converting everything not a string, Boolean numeric, array or hash into strings.
- #to_data_hash ⇒ Object
- #to_yaml ⇒ Object
Methods included from Indirector
Methods included from Util::PsychSupport
Constructor Details
#initialize(name, values = {}) ⇒ Facts
Returns a new instance of Facts.
36 37 38 39 40 41 |
# File 'lib/puppet/node/facts.rb', line 36 def initialize(name, values = {}) @name = name @values = values end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
28 29 30 |
# File 'lib/puppet/node/facts.rb', line 28 def name @name end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
28 29 30 |
# File 'lib/puppet/node/facts.rb', line 28 def @timestamp end |
#values ⇒ Object
Returns the value of attribute values.
28 29 30 |
# File 'lib/puppet/node/facts.rb', line 28 def values @values end |
Class Method Details
.from_data_hash(data) ⇒ Object
86 87 88 89 90 |
# File 'lib/puppet/node/facts.rb', line 86 def self.from_data_hash(data) new_facts = allocate new_facts.initialize_from_hash(data) new_facts end |
Instance Method Details
#==(other) ⇒ Object
80 81 82 83 84 |
# File 'lib/puppet/node/facts.rb', line 80 def ==(other) return false unless name == other.name values == other.values end |
#add_extra_values(extra_values) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Add extra values, such as facts given to lookup on the command line. The extra values will override existing values.
67 68 69 70 |
# File 'lib/puppet/node/facts.rb', line 67 def add_extra_values(extra_values) @values.merge!(extra_values) nil end |
#add_local_facts ⇒ Object
30 31 32 33 34 |
# File 'lib/puppet/node/facts.rb', line 30 def add_local_facts values["clientcert"] = Puppet.settings[:certname] values["clientversion"] = Puppet.version.to_s values["clientnoop"] = Puppet.settings[:noop] end |
#add_timestamp ⇒ Object
117 118 119 |
# File 'lib/puppet/node/facts.rb', line 117 def @timestamp = Time.now end |
#initialize_from_hash(data) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/puppet/node/facts.rb', line 43 def initialize_from_hash(data) @name = data['name'] @values = data['values'] # Timestamp will be here in YAML, e.g. when reading old reports = @values.delete('_timestamp') # Timestamp will be here in JSON ||= data['timestamp'] if .is_a? String @timestamp = Time.parse() else @timestamp = end self.expiration = data['expiration'] if expiration.is_a? String self.expiration = Time.parse(expiration) end end |
#sanitize ⇒ Object
Sanitize fact values by converting everything not a string, Boolean numeric, array or hash into strings.
74 75 76 77 78 |
# File 'lib/puppet/node/facts.rb', line 74 def sanitize values.each do |fact, value| values[fact] = sanitize_fact value end end |
#to_data_hash ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/puppet/node/facts.rb', line 92 def to_data_hash result = { 'name' => name, 'values' => values } if @timestamp if @timestamp.is_a? Time result['timestamp'] = @timestamp.iso8601(9) else result['timestamp'] = @timestamp end end if expiration if expiration.is_a? Time result['expiration'] = expiration.iso8601(9) else result['expiration'] = expiration end end result end |
#to_yaml ⇒ Object
121 122 123 124 |
# File 'lib/puppet/node/facts.rb', line 121 def to_yaml facts_to_display = Psych.parse_stream(YAML.dump(self)) quote_special_strings(facts_to_display) end |