diff options
| author | Luke Kanies <luke@madstop.com> | 2007-12-10 21:13:48 -0600 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2007-12-10 21:13:48 -0600 |
| commit | f127d04934b679b3e5edd7f55d31342abce3c96e (patch) | |
| tree | bb8bc15e086b473bc27104cd6fcbbf548a68678e /lib/puppet | |
| parent | 7a4ae082c216d68092f140ed1f5cca40ffb1a09e (diff) | |
| download | puppet-f127d04934b679b3e5edd7f55d31342abce3c96e.tar.gz puppet-f127d04934b679b3e5edd7f55d31342abce3c96e.tar.xz puppet-f127d04934b679b3e5edd7f55d31342abce3c96e.zip | |
Fixing #951 -- external nodes work again, but you have to
set the 'node_terminus' setting to 'exec'.
Diffstat (limited to 'lib/puppet')
| -rw-r--r-- | lib/puppet/defaults.rb | 9 | ||||
| -rw-r--r-- | lib/puppet/indirector/configuration/compiler.rb | 6 | ||||
| -rw-r--r-- | lib/puppet/indirector/indirection.rb | 22 | ||||
| -rw-r--r-- | lib/puppet/network/handler/configuration.rb | 4 | ||||
| -rw-r--r-- | lib/puppet/node.rb | 84 | ||||
| -rw-r--r-- | lib/puppet/node/searching.rb | 106 | ||||
| -rw-r--r-- | lib/puppet/reference/node_source.rb (renamed from lib/puppet/reference/node_sources.rb) | 6 |
7 files changed, 108 insertions, 129 deletions
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb index 33f3eda91..2e0daf60f 100644 --- a/lib/puppet/defaults.rb +++ b/lib/puppet/defaults.rb @@ -152,7 +152,8 @@ module Puppet :maximum_uid => [4294967290, "The maximum allowed UID. Some platforms use negative UIDs but then ship with tools that do not know how to handle signed ints, so the UIDs show up as huge numbers that can then not be fed back into the system. This is a hackish way to fail in a - slightly more useful way when that happens."] + slightly more useful way when that happens."], + :node_terminus => ["null", "Where to find information about nodes."] ) hostname = Facter["hostname"].value @@ -578,11 +579,7 @@ module Puppet setdefaults(:parser, :typecheck => [true, "Whether to validate types during parsing."], - :paramcheck => [true, "Whether to validate parameters during parsing."], - :node_terminus => ["null", "Where to look for node configuration information. - The default node source, ``none``, just returns a node with its facts - filled in, which is required for normal functionality. - See the `NodeSourceReference`:trac: for more information."] + :paramcheck => [true, "Whether to validate parameters during parsing."] ) setdefaults(:main, diff --git a/lib/puppet/indirector/configuration/compiler.rb b/lib/puppet/indirector/configuration/compiler.rb index 9fc8a7939..598f50451 100644 --- a/lib/puppet/indirector/configuration/compiler.rb +++ b/lib/puppet/indirector/configuration/compiler.rb @@ -55,7 +55,7 @@ class Puppet::Node::Configuration::Compiler < Puppet::Indirector::Code # use timestamps; once one of them moves to using real versions, # the comparison stops working. def version(key) - if node = Puppet::Node.search(key) + if node = Puppet::Node.find_by_any_name(key) return [Puppet::Node.version(key).to_f, Puppet::Node::Facts.version(key).to_f, interpreter.configuration_version(node).to_f].sort[-1] else # This is the standard for "got nothing for ya". @@ -108,9 +108,9 @@ class Puppet::Node::Configuration::Compiler < Puppet::Indirector::Code #end # Note that this is reasonable, because either their node source should actually - # know about the node, or they should be using the ``none`` node source, which + # know about the node, or they should be using the ``null`` node source, which # will always return data. - unless node = Puppet::Node.search(key) + unless node = Puppet::Node.find_by_any_name(key) raise Puppet::Error, "Could not find node '%s'" % key end diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb index 816b4ffc5..f6f867a5f 100644 --- a/lib/puppet/indirector/indirection.rb +++ b/lib/puppet/indirector/indirection.rb @@ -59,6 +59,7 @@ class Puppet::Indirector::Indirection @termini = {} @cache_class = nil + @terminus_class = nil raise(ArgumentError, "Indirection %s is already defined" % @name) if @@indirections.find { |i| i.name == @name } @@indirections << self @@ -88,12 +89,25 @@ class Puppet::Indirector::Indirection return @termini[terminus_name] ||= make_terminus(terminus_name) end - attr_reader :terminus_class + # This can be used to select the terminus class. + attr_accessor :terminus_setting + + # Determine the terminus class. + def terminus_class + unless @terminus_class + if setting = self.terminus_setting + self.terminus_class = Puppet.settings[setting].to_sym + else + raise Puppet::DevError, "No terminus class nor terminus setting was provided for indirection %s" % self.name + end + end + @terminus_class + end # Specify the terminus class to use. - def terminus_class=(terminus_class) - validate_terminus_class(terminus_class) - @terminus_class = terminus_class + def terminus_class=(klass) + validate_terminus_class(klass) + @terminus_class = klass end # This is used by terminus_class= and cache=. diff --git a/lib/puppet/network/handler/configuration.rb b/lib/puppet/network/handler/configuration.rb index 680304e2a..8168ce1d5 100644 --- a/lib/puppet/network/handler/configuration.rb +++ b/lib/puppet/network/handler/configuration.rb @@ -30,7 +30,7 @@ class Puppet::Network::Handler # Note that this is reasonable, because either their node source should actually # know about the node, or they should be using the ``none`` node source, which # will always return data. - unless node = Puppet::Node.search(key) + unless node = Puppet::Node.find_by_any_name(key) raise Puppet::Error, "Could not find node '%s'" % key end @@ -62,7 +62,7 @@ class Puppet::Network::Handler # Return the configuration version. def version(client = nil, clientip = nil) - if client and node = Puppet::Node.search(client) + if client and node = Puppet::Node.find_by_any_name(client) update_node_check(node) return interpreter.configuration_version(node) else diff --git a/lib/puppet/node.rb b/lib/puppet/node.rb index 2d87b6515..4b3a8e9c9 100644 --- a/lib/puppet/node.rb +++ b/lib/puppet/node.rb @@ -10,13 +10,85 @@ class Puppet::Node extend Puppet::Indirector # Use the node source as the indirection terminus. - indirects :node, :terminus_class => :null + indirects :node, :terminus_setting => :node_terminus - # 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 + # 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 + + facts = node_facts(key) + node = nil + names = node_names(key, facts) + 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 + + if node + node.names = names + + return node + else + return nil + end + end + + private + + # Look up the node facts from our fact handler. + def self.node_facts(key) + if facts = Puppet::Node::Facts.find(key) + facts.values + else + {} + 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 = [] + + if hostname = facts["hostname"] + unless hostname == key + names << hostname + 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 + 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 + end + + public attr_accessor :name, :classes, :parameters, :source, :ipaddress, :names attr_reader :time diff --git a/lib/puppet/node/searching.rb b/lib/puppet/node/searching.rb deleted file mode 100644 index 10dd588ab..000000000 --- a/lib/puppet/node/searching.rb +++ /dev/null @@ -1,106 +0,0 @@ -# The module that handles actually searching for nodes. This is only included -# in the Node class, but it's completely stand-alone functionality, so it's -# worth making it a separate module to simplify testing. -module Puppet::Node::Searching - # Retrieve a node from the node source, with some additional munging - # thrown in for kicks. - def search(key) - return nil unless key - if node = cached?(key) - return node - end - facts = node_facts(key) - node = nil - names = node_names(key, facts) - names.each do |name| - name = name.to_s if name.is_a?(Symbol) - if node = find(name) - #Puppet.info "Found %s in %s" % [name, @source] - break - end - 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 - - if node - node.names = names - - cache(node) - - return node - else - return nil - end - end - - private - - # Store the node to make things a bit faster. - def cache(node) - @node_cache ||= {} - @node_cache[node.name] = node - end - - # If the node is cached, return it. - def cached?(name) - # Don't use cache when the filetimeout is set to 0 - return false if [0, "0"].include?(Puppet[:filetimeout]) - @node_cache ||= {} - - if node = @node_cache[name] and Time.now - node.time < Puppet[:filetimeout] - return node - else - return false - end - end - - # Look up the node facts from our fact handler. - def node_facts(key) - if facts = Puppet::Node::Facts.find(key) - facts.values - else - {} - end - end - - # Calculate the list of node names we should use for looking - # up our node. - def node_names(key, facts = nil) - facts ||= node_facts(key) - names = [] - - if hostname = facts["hostname"] - unless hostname == key - names << hostname - 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 - 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 - end -end diff --git a/lib/puppet/reference/node_sources.rb b/lib/puppet/reference/node_source.rb index 33a4c539c..29a01f850 100644 --- a/lib/puppet/reference/node_sources.rb +++ b/lib/puppet/reference/node_source.rb @@ -1,7 +1,9 @@ +require 'puppet/node' + noderef = Puppet::Util::Reference.newreference :node_source, :doc => "Sources of node configuration information" do - Puppet::Network::Handler.node.sourcedocs + Puppet::Network::Handler.node.docs end -nodref.header = " +noderef.header = " Nodes can be searched for in different locations. This document describes those different locations. " |
