diff options
| author | Luke Kanies <luke@madstop.com> | 2007-09-22 00:16:39 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2007-09-22 00:16:39 -0500 |
| commit | ebe7290bf0c9119e268c9037c33da515e527aa5b (patch) | |
| tree | 3f59b5b3fc46c35f5ef18e0a1110381c94187692 /lib/puppet/indirector/node | |
| parent | b9dc6cb22f087f419b328cafa945c9604043b22f (diff) | |
| download | puppet-ebe7290bf0c9119e268c9037c33da515e527aa5b.tar.gz puppet-ebe7290bf0c9119e268c9037c33da515e527aa5b.tar.xz puppet-ebe7290bf0c9119e268c9037c33da515e527aa5b.zip | |
All indirections are working, and they have all
been migrated over to the new organization. Where we
would have previously had an 'ldap' node terminus at
puppet/indirector/node/ldap.rb, we would not have it at
puppet/indirector/ldap/node.rb, and it would be a subclass
of puppet/indirector/ldap.rb.
These are called terminus classes, and there are now three
categories of them: The base class itself, abstract classes
that provide most of the functionality (e.g., the ldap and
yaml classes), and the classes themselves that implement
the functionality for a given model like Node or Facts.
The base terminus class handles auto-loading any of these
classes from disk.
Diffstat (limited to 'lib/puppet/indirector/node')
| -rw-r--r-- | lib/puppet/indirector/node/external.rb | 89 | ||||
| -rw-r--r-- | lib/puppet/indirector/node/ldap.rb | 140 | ||||
| -rw-r--r-- | lib/puppet/indirector/node/none.rb | 14 |
3 files changed, 0 insertions, 243 deletions
diff --git a/lib/puppet/indirector/node/external.rb b/lib/puppet/indirector/node/external.rb deleted file mode 100644 index 66aca6048..000000000 --- a/lib/puppet/indirector/node/external.rb +++ /dev/null @@ -1,89 +0,0 @@ -require 'puppet/node/facts' - -Puppet::Indirector.register_terminus :node, :external do - desc "Call an external program to get node information." - - include Puppet::Util - - # Proxy the execution, so it's easier to test. - def execute(command) - Puppet::Util.execute(command) - end - - # Look for external node definitions. - def find(name) - unless Puppet[:external_nodes] != "none" - raise ArgumentError, "You must set the 'external_nodes' parameter to use the external node source" - end - - unless Puppet[:external_nodes][0] == File::SEPARATOR[0] - raise ArgumentError, "You must set the 'external_nodes' parameter to a fully qualified command" - end - - # Run the command. - unless output = query(name) - return nil - end - - # Translate the output to ruby. - result = translate(name, output) - - return create_node(name, result) - end - - private - - # Turn our outputted objects into a Puppet::Node instance. - def create_node(name, result) - node = Puppet::Node.new(name) - set = false - [:parameters, :classes].each do |param| - if value = result[param] - node.send(param.to_s + "=", value) - set = true - end - end - - if set - node.fact_merge - return node - else - return nil - end - end - - # Call the external command and see if it returns our output. - def query(name) - # This is a very cheap way to do this, since it will break on - # commands that have spaces in the arguments. But it's good - # enough for most cases. - external_node_command = Puppet[:external_nodes].split - external_node_command << name - begin - output = execute(external_node_command) - rescue Puppet::ExecutionFailure => detail - if $?.exitstatus == 1 - return nil - else - Puppet.err "Could not retrieve external node information for %s: %s" % [name, detail] - end - return nil - end - - if output =~ /\A\s*\Z/ # all whitespace - Puppet.debug "Empty response for %s from external node source" % name - return nil - else - return output - end - end - - # Translate the yaml string into Ruby objects. - def translate(name, output) - begin - YAML.load(output).inject({}) { |hash, data| hash[symbolize(data[0])] = data[1]; hash } - rescue => detail - raise Puppet::Error, "Could not load external node results for %s: %s" % [name, detail] - end - end -end diff --git a/lib/puppet/indirector/node/ldap.rb b/lib/puppet/indirector/node/ldap.rb deleted file mode 100644 index 230ca2467..000000000 --- a/lib/puppet/indirector/node/ldap.rb +++ /dev/null @@ -1,140 +0,0 @@ -Puppet::Indirector.register_terminus :node, :ldap do - desc "Search in LDAP for node configuration information." - - # Look for our node in ldap. - def find(name) - unless ary = ldapsearch(name) - return nil - end - parent, classes, parameters = ary - - while parent - parent, tmpclasses, tmpparams = ldapsearch(parent) - classes += tmpclasses if tmpclasses - tmpparams.each do |param, value| - # Specifically test for whether it's set, so false values are handled - # correctly. - parameters[param] = value unless parameters.include?(param) - end - end - - node = Puppet::Node.new(name, :classes => classes, :source => "ldap", :parameters => parameters) - node.fact_merge - return node - end - - # Find the ldap node, return the class list and parent node specially, - # and everything else in a parameter hash. - def ldapsearch(node) - filter = Puppet[:ldapstring] - classattrs = Puppet[:ldapclassattrs].split("\s*,\s*") - if Puppet[:ldapattrs] == "all" - # A nil value here causes all attributes to be returned. - search_attrs = nil - else - search_attrs = classattrs + Puppet[:ldapattrs].split("\s*,\s*") - end - pattr = nil - if pattr = Puppet[:ldapparentattr] - if pattr == "" - pattr = nil - else - search_attrs << pattr unless search_attrs.nil? - end - end - - if filter =~ /%s/ - filter = filter.gsub(/%s/, node) - end - - parent = nil - classes = [] - parameters = nil - - found = false - count = 0 - - begin - # We're always doing a sub here; oh well. - ldap.search(Puppet[:ldapbase], 2, filter, search_attrs) do |entry| - found = true - if pattr - if values = entry.vals(pattr) - if values.length > 1 - raise Puppet::Error, - "Node %s has more than one parent: %s" % - [node, values.inspect] - end - unless values.empty? - parent = values.shift - end - end - end - - classattrs.each { |attr| - if values = entry.vals(attr) - values.each do |v| classes << v end - end - } - - parameters = entry.to_hash.inject({}) do |hash, ary| - if ary[1].length == 1 - hash[ary[0]] = ary[1].shift - else - hash[ary[0]] = ary[1] - end - hash - end - end - rescue => detail - if count == 0 - # Try reconnecting to ldap - @ldap = nil - retry - else - raise Puppet::Error, "LDAP Search failed: %s" % detail - end - end - - classes.flatten! - - if classes.empty? - classes = nil - end - - if parent or classes or parameters - return parent, classes, parameters - else - return nil - end - end - - private - - # Create an ldap connection. - def ldap - unless defined? @ldap and @ldap - unless Puppet.features.ldap? - raise Puppet::Error, "Could not set up LDAP Connection: Missing ruby/ldap libraries" - end - begin - if Puppet[:ldapssl] - @ldap = LDAP::SSLConn.new(Puppet[:ldapserver], Puppet[:ldapport]) - elsif Puppet[:ldaptls] - @ldap = LDAP::SSLConn.new( - Puppet[:ldapserver], Puppet[:ldapport], true - ) - else - @ldap = LDAP::Conn.new(Puppet[:ldapserver], Puppet[:ldapport]) - end - @ldap.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3) - @ldap.set_option(LDAP::LDAP_OPT_REFERRALS, LDAP::LDAP_OPT_ON) - @ldap.simple_bind(Puppet[:ldapuser], Puppet[:ldappassword]) - rescue => detail - raise Puppet::Error, "Could not connect to LDAP: %s" % detail - end - end - - return @ldap - end -end diff --git a/lib/puppet/indirector/node/none.rb b/lib/puppet/indirector/node/none.rb deleted file mode 100644 index 034c0b349..000000000 --- a/lib/puppet/indirector/node/none.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'puppet/node/facts' - -Puppet::Indirector.register_terminus :node, :none do - desc "Always return an empty node object. This is the node source you should - use when you don't have some other, functional source you want to use, - as the compiler will not work without this node information." - - # Just return an empty node. - def find(name) - node = Puppet::Node.new(name) - node.fact_merge - node - end -end |
