summaryrefslogtreecommitdiffstats
path: root/lib/puppet/node.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/node.rb')
-rw-r--r--lib/puppet/node.rb34
1 files changed, 30 insertions, 4 deletions
diff --git a/lib/puppet/node.rb b/lib/puppet/node.rb
index 2d3ac712e..d71bd507e 100644
--- a/lib/puppet/node.rb
+++ b/lib/puppet/node.rb
@@ -1,10 +1,27 @@
+require 'puppet/indirector'
+
# A simplistic class for managing the node information itself.
class Puppet::Node
+ require 'puppet/node/facts'
+
+ # Set up indirection, so that nodes can be looked for in
+ # the node sources.
+ extend Puppet::Indirector
+
+ # Use the node source as the indirection terminus.
+ indirects :node
+
+ # Add the node-searching methods. This is what people will actually
+ # interact with that will find the node with the list of names or
+ # will search for a default node.
+ require 'puppet/node/searching'
+ extend Puppet::Node::Searching
+
attr_accessor :name, :classes, :parameters, :source, :ipaddress, :names
attr_reader :time
attr_writer :environment
- # Do not return environments tha are empty string, and use
+ # Do not return environments that are the empty string, and use
# explicitly set environments, then facts, then a central env
# value.
def environment
@@ -21,6 +38,9 @@ class Puppet::Node
end
def initialize(name, options = {})
+ unless name
+ raise ArgumentError, "Node names cannot be nil"
+ end
@name = name
# Provide a default value.
@@ -52,9 +72,15 @@ class Puppet::Node
end
# Merge the node facts with parameters from the node source.
- # This is only called if the node source has 'fact_merge' set to true.
- def fact_merge(facts)
- facts.each do |name, value|
+ def fact_merge
+ if facts = Puppet::Node::Facts.find(name)
+ merge(facts.values)
+ end
+ end
+
+ # Merge any random parameters into our parameter list.
+ def merge(params)
+ params.each do |name, value|
@parameters[name] = value unless @parameters.include?(name)
end
end