diff options
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/network/handler/master.rb | 24 | ||||
-rw-r--r-- | lib/puppet/node.rb | 59 |
2 files changed, 33 insertions, 50 deletions
diff --git a/lib/puppet/network/handler/master.rb b/lib/puppet/network/handler/master.rb index 851ccc7b2..a050b089b 100644 --- a/lib/puppet/network/handler/master.rb +++ b/lib/puppet/network/handler/master.rb @@ -56,7 +56,8 @@ class Puppet::Network::Handler # Call our various handlers; this handler is getting deprecated. def getconfig(facts, format = "marshal", client = nil, clientip = nil) facts = decode_facts(facts) - client, clientip = clientname(client, clientip, facts) + + client ||= facts["hostname"] # Pass the facts to the fact handler Puppet::Node::Facts.new(client, facts).save unless local? @@ -66,27 +67,6 @@ class Puppet::Network::Handler return translate(catalog.extract) end - private - - # Manipulate the client name as appropriate. - def clientname(name, ip, facts) - # Always use the hostname from Facter. - client = facts["hostname"] - clientip = facts["ipaddress"] - if Puppet[:node_name] == 'cert' - if name - client = name - facts["fqdn"] = client - facts["hostname"], facts["domain"] = client.split('.', 2) - end - if ip - clientip = ip - end - end - - return client, clientip - end - # def decode_facts(facts) if @local diff --git a/lib/puppet/node.rb b/lib/puppet/node.rb index c0628ecdc..576e2265d 100644 --- a/lib/puppet/node.rb +++ b/lib/puppet/node.rb @@ -18,9 +18,8 @@ class Puppet::Node def self.find_by_any_name(key) return nil unless key - facts = node_facts(key) node = nil - names = node_names(key, facts) + names = node_names(key) names.each do |name| name = name.to_s if name.is_a?(Symbol) break if node = find(name) @@ -34,13 +33,16 @@ class Puppet::Node end end - if node - node.names = names + return nil unless node - return node - else - return nil - end + 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 end private @@ -60,33 +62,34 @@ class Puppet::Node facts ||= node_facts(key) names = [] - if hostname = facts["hostname"] - unless hostname == key - names << hostname + # First, get the fqdn + unless fqdn = facts["fqdn"] + if domain = facts["domain"] + fqdn = facts["hostname"] + "." + facts["domain"] end - else - hostname = key - end - - if fqdn = facts["fqdn"] - hostname = fqdn - names << fqdn end - # Make sure both the fqdn and the short name of the - # host can be used in the manifest - if hostname =~ /\./ - names << hostname.sub(/\..+/,'') - elsif domain = facts['domain'] - names << hostname + "." + domain + # 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 - # Sort the names inversely by name length. - names.sort! { |a,b| b.length <=> a.length } - # And make sure the key is first, since that's the most # likely usage. - ([key] + names).uniq + # 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 |