summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-06-14 14:37:33 -0500
committerLuke Kanies <luke@madstop.com>2008-06-15 13:31:47 -0500
commit51e1ba8c02f1bd9085ef15138c4828accbb29dec (patch)
tree2c8aeaeb8ad6f9a398329b3a5fa5b896397fdda7 /lib/puppet
parentfb4e84321d47c5ebe31d257e1f7e0037a9ff34c1 (diff)
downloadpuppet-51e1ba8c02f1bd9085ef15138c4828accbb29dec.tar.gz
puppet-51e1ba8c02f1bd9085ef15138c4828accbb29dec.tar.xz
puppet-51e1ba8c02f1bd9085ef15138c4828accbb29dec.zip
The LDAP Node terminus now searches for the fqdn, short name, and default.
This provides something like the multiple name scenario previously used by the parser but now implemented in each terminus.
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/indirector/ldap.rb12
-rw-r--r--lib/puppet/indirector/node/ldap.rb34
2 files changed, 32 insertions, 14 deletions
diff --git a/lib/puppet/indirector/ldap.rb b/lib/puppet/indirector/ldap.rb
index 07ad38933..695d38a95 100644
--- a/lib/puppet/indirector/ldap.rb
+++ b/lib/puppet/indirector/ldap.rb
@@ -1,14 +1,16 @@
require 'puppet/indirector/terminus'
class Puppet::Indirector::Ldap < Puppet::Indirector::Terminus
- # Perform our ldap search and process the result.
- def find(request)
+ # We split this apart so it's easy to call multiple times with different names.
+ def entry2hash(name)
# We have to use 'yield' here because the LDAP::Entry objects
# get destroyed outside the scope of the search, strangely.
- ldapsearch(request.key) { |entry| return process(request.key, entry) }
+ ldapsearch(name) { |entry| return process(name, entry) }
+ end
- # Return nil if we haven't found something.
- return nil
+ # Perform our ldap search and process the result.
+ def find(request)
+ return entry2hash(request.key) || nil
end
# Process the found entry. We assume that we don't just want the
diff --git a/lib/puppet/indirector/node/ldap.rb b/lib/puppet/indirector/node/ldap.rb
index 5cf560e86..4ed053eff 100644
--- a/lib/puppet/indirector/node/ldap.rb
+++ b/lib/puppet/indirector/node/ldap.rb
@@ -3,7 +3,9 @@ require 'puppet/indirector/ldap'
class Puppet::Node::Ldap < Puppet::Indirector::Ldap
desc "Search in LDAP for node configuration information. See
- the `LdapNodes`:trac: page for more information."
+ the `LdapNodes`:trac: page for more information. This will first
+ search for whatever the certificate name is, then (if that name
+ contains a '.') for the short name, then 'default'."
# The attributes that Puppet class information is stored in.
def class_attributes
@@ -13,7 +15,17 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap
# Look for our node in ldap.
def find(request)
- return nil unless information = super
+ names = [request.key]
+ if request.key.include?(".") # we assume it's an fqdn
+ names << request.key.sub(/\..+/, '')
+ end
+ names << "default"
+
+ information = nil
+ names.each do |name|
+ break if information = entry2hash(name)
+ end
+ return nil unless information
name = request.key
@@ -129,17 +141,21 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap
parent = find_and_merge_parent(parent, information)
end
- information[:stacked].each do |value|
- param = value.split('=', 2)
- information[:stacked_parameters][param[0]] = param[1]
+ if information[:stacked]
+ information[:stacked].each do |value|
+ param = value.split('=', 2)
+ information[:stacked_parameters][param[0]] = param[1]
+ end
end
- information[:stacked_parameters].each do |param, value|
- information[:parameters][param] = value unless information[:parameters].include?(param)
+ if information[:stacked_parameters]
+ information[:stacked_parameters].each do |param, value|
+ information[:parameters][param] = value unless information[:parameters].include?(param)
+ end
end
- node.classes = information[:classes].uniq unless information[:classes].empty?
- node.parameters = information[:parameters] unless information[:parameters].empty?
+ node.classes = information[:classes].uniq unless information[:classes].nil? or information[:classes].empty?
+ node.parameters = information[:parameters] unless information[:parameters].nil? or information[:parameters].empty?
node.environment = information[:environment] if information[:environment]
node.fact_merge
end