diff options
| author | Luke Kanies <luke@madstop.com> | 2007-09-11 16:19:03 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2007-09-11 16:19:03 -0500 |
| commit | 65c1501504dd7e9166176661f9ed9f80300954db (patch) | |
| tree | 9e1bc22b924457561ce0de1b25590effbcd33a4a /lib/puppet/node.rb | |
| parent | 5aa4440b6fb8c9199ee549bd8fe0e4afb296c259 (diff) | |
| download | puppet-65c1501504dd7e9166176661f9ed9f80300954db.tar.gz puppet-65c1501504dd7e9166176661f9ed9f80300954db.tar.xz puppet-65c1501504dd7e9166176661f9ed9f80300954db.zip | |
The Node handler is now obsolete. Node searching is handled through the indirector. I have not yet added the tests for the node handlers themselves, which is next.
Diffstat (limited to 'lib/puppet/node.rb')
| -rw-r--r-- | lib/puppet/node.rb | 115 |
1 files changed, 5 insertions, 110 deletions
diff --git a/lib/puppet/node.rb b/lib/puppet/node.rb index f04de91c5..9c5d2d397 100644 --- a/lib/puppet/node.rb +++ b/lib/puppet/node.rb @@ -8,116 +8,11 @@ class Puppet::Node # Use the node source as the indirection terminus. indirects :node, :to => :node_source - # Retrieve a node from the node source, with some additional munging - # thrown in for kicks. - # LAK:FIXME Crap. This won't work, because we might have two copies of this class, - # one remote and one local, and we won't know which one should do all of the - # extra crap. - def self.get(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 = nodesearch(name) and @source != "none" - 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 = nodesearch("default") - Puppet.notice "Using default node for %s" % key - end - end - - if node - node.source = @source - node.names = names - - # Merge the facts into the parameters. - if fact_merge? - node.fact_merge(facts) - end - - cache(node) - - return node - else - return nil - end - end - - private - - # Store the node to make things a bit faster. - def self.cache(node) - @node_cache[node.name] = node - end - - # If the node is cached, return it. - def self.cached?(name) - # Don't use cache when the filetimeout is set to 0 - return false if [0, "0"].include?(Puppet[:filetimeout]) - - 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 self.node_facts(key) - if facts = Puppet::Node::Facts.get(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 + # 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 |
