From b7bd427eb98001fb051f0d8910a0a87d1b810c15 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 10 Jun 2008 00:32:56 -0500 Subject: Converting the Node.node_names class method into an instance method. This effectively removes the ability to search node termini for multiple names; only the parser will use these names. Temporarily retaining the 'find_by_any_name' method; it will be removed in a later commit. --- lib/puppet/node.rb | 100 ++++++++++++++++++++--------------------------------- 1 file changed, 37 insertions(+), 63 deletions(-) (limited to 'lib/puppet/node.rb') diff --git a/lib/puppet/node.rb b/lib/puppet/node.rb index 576e2265d..a2024e6b5 100644 --- a/lib/puppet/node.rb +++ b/lib/puppet/node.rb @@ -17,32 +17,7 @@ class Puppet::Node # thrown in for kicks. def self.find_by_any_name(key) return nil unless key - - node = nil - names = node_names(key) - names.each do |name| - name = name.to_s if name.is_a?(Symbol) - break if node = find(name) - end - - # If they made it this far, we haven't found anything, so look for a - # default node. - unless node or names.include?("default") - if node = find("default") - Puppet.notice "Using default node for %s" % key - end - end - - return nil unless node - - node.names = names - - # This is critical, because it forces our node's name to always - # be the key, which is nearly always the node's certificate. - # This is how the node instance is linked to the Facts instance, - # so it quite matters. - node.name = key - return node + find(key) end private @@ -56,45 +31,9 @@ class Puppet::Node end end - # Calculate the list of node names we should use for looking - # up our node. - def self.node_names(key, facts = nil) - facts ||= node_facts(key) - names = [] - - # First, get the fqdn - unless fqdn = facts["fqdn"] - if domain = facts["domain"] - fqdn = facts["hostname"] + "." + facts["domain"] - end - end - - # Now that we (might) have the fqdn, add each piece to the name - # list to search, in order of longest to shortest. - if fqdn - list = fqdn.split(".") - tmp = [] - list.each_with_index do |short, i| - tmp << list[0..i].join(".") - end - names += tmp.reverse - end - - # And make sure the key is first, since that's the most - # likely usage. - # The key is usually the Certificate CN, but it can be - # set to the 'facter' hostname instead. - if Puppet[:node_name] == 'cert' - names.unshift key - else - names.unshift facts["hostname"] - end - names.uniq - end - public - attr_accessor :name, :classes, :parameters, :source, :ipaddress, :names + attr_accessor :name, :classes, :parameters, :source, :ipaddress attr_reader :time # Set the environment, making sure that it's valid. @@ -165,4 +104,39 @@ class Puppet::Node @parameters[name] = value unless @parameters.include?(name) end end + + # Calculate the list of names we might use for looking + # up our node. This is only used for AST nodes. + def names + names = [] + + # First, get the fqdn + unless fqdn = parameters["fqdn"] + if domain = parameters["domain"] + fqdn = parameters["hostname"] + "." + parameters["domain"] + end + end + + # Now that we (might) have the fqdn, add each piece to the name + # list to search, in order of longest to shortest. + if fqdn + list = fqdn.split(".") + tmp = [] + list.each_with_index do |short, i| + tmp << list[0..i].join(".") + end + names += tmp.reverse + end + + # And make sure the node name is first, since that's the most + # likely usage. + # The name is usually the Certificate CN, but it can be + # set to the 'facter' hostname instead. + if Puppet[:node_name] == 'cert' + names.unshift name + else + names.unshift parameters["hostname"] + end + names.uniq + end end -- cgit From 317af3608caae060d15b407fe0b78304f355c106 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 10 Jun 2008 00:33:39 -0500 Subject: Removing the now-obsolete Node.node_facts method. --- lib/puppet/node.rb | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'lib/puppet/node.rb') diff --git a/lib/puppet/node.rb b/lib/puppet/node.rb index a2024e6b5..75b7197fd 100644 --- a/lib/puppet/node.rb +++ b/lib/puppet/node.rb @@ -20,19 +20,6 @@ class Puppet::Node find(key) end - private - - # Look up the node facts so we can generate the node names to use. - def self.node_facts(key) - if facts = Puppet::Node::Facts.find(key) - facts.values - else - {} - end - end - - public - attr_accessor :name, :classes, :parameters, :source, :ipaddress attr_reader :time -- cgit From 1f19453dddf0f3a7822c21157f6f8d06c388cdb8 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Sun, 15 Jun 2008 13:58:37 -0500 Subject: Removing the Node.find_by_name method. We just use the regular Node.find method now, since the nodes don't need to do any magical naming. --- lib/puppet/node.rb | 7 ------- 1 file changed, 7 deletions(-) (limited to 'lib/puppet/node.rb') diff --git a/lib/puppet/node.rb b/lib/puppet/node.rb index 75b7197fd..14d0f6ac7 100644 --- a/lib/puppet/node.rb +++ b/lib/puppet/node.rb @@ -13,13 +13,6 @@ class Puppet::Node indirects :node, :terminus_setting => :node_terminus, :doc => "Where to find node information. A node is composed of its name, its facts, and its environment." - # Retrieve a node from the node source, with some additional munging - # thrown in for kicks. - def self.find_by_any_name(key) - return nil unless key - find(key) - end - attr_accessor :name, :classes, :parameters, :source, :ipaddress attr_reader :time -- cgit