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/exec/node.rb | |
| 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/exec/node.rb')
| -rw-r--r-- | lib/puppet/indirector/exec/node.rb | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/puppet/indirector/exec/node.rb b/lib/puppet/indirector/exec/node.rb new file mode 100644 index 000000000..033afe3f0 --- /dev/null +++ b/lib/puppet/indirector/exec/node.rb @@ -0,0 +1,50 @@ +require 'puppet/indirector/exec' + +class Puppet::Indirector::Exec::Node < Puppet::Indirector::Exec + desc "Call an external program to get node information." + include Puppet::Util + + def command + command = Puppet[:external_nodes] + unless command != "none" + raise ArgumentError, "You must set the 'external_nodes' parameter to use the external node terminus" + end + command.split + end + + # Look for external node definitions. + def find(name) + output = super or return nil + + # 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 + + node.fact_merge + return node + 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 |
