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: ActiveRecord, Couch, Facter, InventoryActiveRecord, InventoryService, Memory, NetworkDevice, Rest, StoreConfigs, Yaml
Constant Summary
Constants included
from Indirector
Indirector::BadNameRegexp
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Indirector
configure_routes, indirects
Methods included from Util::Pson
pson_create
Constructor Details
#initialize(name, values = {}) ⇒ Facts
Returns a new instance of Facts.
34
35
36
37
38
39
|
# File 'lib/puppet/node/facts.rb', line 34
def initialize(name, values = {})
@name = name
@values = values
add_timestamp
end
|
Instance Attribute Details
26
27
28
|
# File 'lib/puppet/node/facts.rb', line 26
def name
@name
end
|
26
27
28
|
# File 'lib/puppet/node/facts.rb', line 26
def values
@values
end
|
Class Method Details
.from_data_hash(data) ⇒ Object
81
82
83
84
85
|
# File 'lib/puppet/node/facts.rb', line 81
def self.from_data_hash(data)
new_facts = allocate
new_facts.initialize_from_hash(data)
new_facts
end
|
.from_pson(data) ⇒ Object
87
88
89
90
|
# File 'lib/puppet/node/facts.rb', line 87
def self.from_pson(data)
Puppet.deprecation_warning("from_pson is being removed in favour of from_data_hash.")
self.from_data_hash(data)
end
|
Instance Method Details
#==(other) ⇒ Object
76
77
78
79
|
# File 'lib/puppet/node/facts.rb', line 76
def ==(other)
return false unless self.name == other.name
strip_internal == other.send(:strip_internal)
end
|
#add_local_facts ⇒ Object
28
29
30
31
32
|
# File 'lib/puppet/node/facts.rb', line 28
def add_local_facts
values["clientcert"] = Puppet.settings[:certname]
values["clientversion"] = Puppet.version.to_s
values["clientnoop"] = Puppet.settings[:noop]
end
|
#add_timestamp ⇒ Object
Add internal data to the facts for storage.
118
119
120
|
# File 'lib/puppet/node/facts.rb', line 118
def add_timestamp
self.timestamp = Time.now
end
|
#initialize_from_hash(data) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/puppet/node/facts.rb', line 41
def initialize_from_hash(data)
@name = data['name']
@values = data['values']
timestamp = data['values']['_timestamp']
@values.delete_if do |key, val|
key =~ /^_/
end
timestamp ||= data['timestamp']
timestamp = Time.parse(timestamp) if timestamp.is_a? String
self.timestamp = timestamp
self.expiration = data['expiration']
if expiration.is_a? String
self.expiration = Time.parse(expiration)
end
end
|
Sanitize fact values by converting everything not a string, boolean numeric, array or hash into strings.
70
71
72
73
74
|
# File 'lib/puppet/node/facts.rb', line 70
def sanitize
values.each do |fact, value|
values[fact] = sanitize_fact value
end
end
|
#stringify ⇒ Object
Convert all fact values into strings.
62
63
64
65
66
|
# File 'lib/puppet/node/facts.rb', line 62
def stringify
values.each do |fact, value|
values[fact] = value.to_s
end
end
|
#strip_internal ⇒ Object
Strip out that internal data.
131
132
133
134
135
|
# File 'lib/puppet/node/facts.rb', line 131
def strip_internal
newvals = values.dup
newvals.find_all { |name, value| name.to_s =~ /^_/ }.each { |name, value| newvals.delete(name) }
newvals
end
|
#timestamp ⇒ Object
126
127
128
|
# File 'lib/puppet/node/facts.rb', line 126
def timestamp
self.values['_timestamp']
end
|
#timestamp=(time) ⇒ Object
122
123
124
|
# File 'lib/puppet/node/facts.rb', line 122
def timestamp=(time)
self.values['_timestamp'] = time
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' => strip_internal,
}
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
|