Class: Puppet::Node
Overview
Just define it, so this class has fewer load dependencies.
Defined Under Namespace
Classes: ActiveRecord, Environment, Exec, Facts, Ldap, Memory, Msgpack, Plain, Rest, StoreConfigs, WriteOnlyYaml, Yaml
Constant Summary
collapse
- ENVIRONMENT =
'environment'.freeze
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
Constructor Details
#initialize(name, options = {}) ⇒ Node
Returns a new instance of Node.
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/puppet/node.rb', line 98
def initialize(name, options = {})
raise ArgumentError, "Node names cannot be nil" unless name
@name = name
if classes = options[:classes]
if classes.is_a?(String)
@classes = [classes]
else
@classes = classes
end
else
@classes = []
end
@parameters = options[:parameters] || {}
@facts = options[:facts]
if env = options[:environment]
self.environment = env
end
@time = Time.now
end
|
Instance Attribute Details
16
17
18
|
# File 'lib/puppet/node.rb', line 16
def classes
@classes
end
|
#environment_name ⇒ Object
16
17
18
|
# File 'lib/puppet/node.rb', line 16
def environment_name
@environment_name
end
|
17
18
19
|
# File 'lib/puppet/node.rb', line 17
def facts
@facts
end
|
#ipaddress ⇒ Object
16
17
18
|
# File 'lib/puppet/node.rb', line 16
def ipaddress
@ipaddress
end
|
16
17
18
|
# File 'lib/puppet/node.rb', line 16
def name
@name
end
|
#parameters ⇒ Object
16
17
18
|
# File 'lib/puppet/node.rb', line 16
def parameters
@parameters
end
|
16
17
18
|
# File 'lib/puppet/node.rb', line 16
def source
@source
end
|
17
18
19
|
# File 'lib/puppet/node.rb', line 17
def time
@time
end
|
#trusted_data ⇒ Object
16
17
18
|
# File 'lib/puppet/node.rb', line 16
def trusted_data
@trusted_data
end
|
Class Method Details
.from_data_hash(data) ⇒ Object
23
24
25
26
27
28
29
30
31
|
# File 'lib/puppet/node.rb', line 23
def self.from_data_hash(data)
raise ArgumentError, "No name provided in serialized data" unless name = data['name']
node = new(name)
node.classes = data['classes']
node.parameters = data['parameters']
node.environment_name = data['environment']
node
end
|
.from_pson(pson) ⇒ Object
33
34
35
36
|
# File 'lib/puppet/node.rb', line 33
def self.from_pson(pson)
Puppet.deprecation_warning("from_pson is being removed in favour of from_data_hash.")
self.from_data_hash(pson)
end
|
Instance Method Details
#environment ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/puppet/node.rb', line 59
def environment
if @environment
@environment
else
if env = parameters[ENVIRONMENT]
self.environment = env
elsif environment_name
self.environment = environment_name
else
self.environment = Puppet.lookup(:environments).get!(Puppet[:environment])
end
@environment
end
end
|
#environment=(env) ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/puppet/node.rb', line 79
def environment=(env)
if env.is_a?(String) or env.is_a?(Symbol)
@environment = Puppet.lookup(:environments).get!(env)
else
@environment = env
end
unless @environment.nil?
@parameters[ENVIRONMENT] = @environment.name if @parameters.include?(ENVIRONMENT)
self.environment_name = @environment.name if instance_variable_defined?(:@environment_name)
end
@environment
end
|
#fact_merge ⇒ Object
Merge the node facts with parameters from the node source.
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/puppet/node.rb', line 124
def fact_merge
if @facts = Puppet::Node::Facts.indirection.find(name, :environment => environment)
@facts.sanitize
merge(@facts.values)
end
rescue => detail
error = Puppet::Error.new("Could not retrieve facts for #{name}: #{detail}")
error.set_backtrace(detail.backtrace)
raise error
end
|
#has_environment_instance? ⇒ Boolean
94
95
96
|
# File 'lib/puppet/node.rb', line 94
def has_environment_instance?
!@environment.nil?
end
|
#merge(params) ⇒ Object
Merge any random parameters into our parameter list.
136
137
138
139
140
141
142
|
# File 'lib/puppet/node.rb', line 136
def merge(params)
params.each do |name, value|
@parameters[name] = value unless @parameters.include?(name)
end
@parameters[ENVIRONMENT] ||= self.environment.name.to_s
end
|
Calculate the list of names we might use for looking up our node. This is only used for AST nodes.
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
# File 'lib/puppet/node.rb', line 146
def names
return [name] if Puppet.settings[:strict_hostname_checking]
names = []
names += split_name(name) if name.include?(".")
unless fqdn = parameters["fqdn"]
if parameters["hostname"] and parameters["domain"]
fqdn = parameters["hostname"] + "." + parameters["domain"]
else
Puppet.warning "Host is missing hostname and/or domain: #{name}"
end
end
names += split_name(fqdn) if fqdn
if Puppet[:node_name] == 'cert'
names.unshift name
else
names.unshift parameters["hostname"]
end
names.uniq
end
|
#split_name(name) ⇒ Object
178
179
180
181
182
183
184
185
|
# File 'lib/puppet/node.rb', line 178
def split_name(name)
list = name.split(".")
tmp = []
list.each_with_index do |short, i|
tmp << list[0..i].join(".")
end
tmp.reverse
end
|
#to_data_hash ⇒ Object
38
39
40
41
42
43
44
45
46
|
# File 'lib/puppet/node.rb', line 38
def to_data_hash
result = {
'name' => name,
'environment' => environment.name,
}
result['classes'] = classes unless classes.empty?
result['parameters'] = parameters unless parameters.empty?
result
end
|
#to_pson(*args) ⇒ Object
55
56
57
|
# File 'lib/puppet/node.rb', line 55
def to_pson(*args)
to_pson_data_hash.to_pson(*args)
end
|
#to_pson_data_hash(*args) ⇒ Object
48
49
50
51
52
53
|
# File 'lib/puppet/node.rb', line 48
def to_pson_data_hash(*args)
{
'document_type' => "Node",
'data' => to_data_hash,
}
end
|