summaryrefslogtreecommitdiffstats
path: root/lib/puppet/indirector/exec.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-09-22 00:16:39 -0500
committerLuke Kanies <luke@madstop.com>2007-09-22 00:16:39 -0500
commitebe7290bf0c9119e268c9037c33da515e527aa5b (patch)
tree3f59b5b3fc46c35f5ef18e0a1110381c94187692 /lib/puppet/indirector/exec.rb
parentb9dc6cb22f087f419b328cafa945c9604043b22f (diff)
downloadpuppet-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.rb')
-rw-r--r--lib/puppet/indirector/exec.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/puppet/indirector/exec.rb b/lib/puppet/indirector/exec.rb
new file mode 100644
index 000000000..7e4ac8d18
--- /dev/null
+++ b/lib/puppet/indirector/exec.rb
@@ -0,0 +1,57 @@
+require 'puppet/indirector/terminus'
+require 'puppet/util'
+
+class Puppet::Indirector::Exec < Puppet::Indirector::Terminus
+ # Look for external node definitions.
+ def find(name)
+ # Run the command.
+ unless output = query(name)
+ return nil
+ end
+
+ # Translate the output to ruby.
+ return output
+ end
+
+ private
+
+ # Proxy the execution, so it's easier to test.
+ def execute(command)
+ Puppet::Util.execute(command)
+ end
+
+ # Call the external command and see if it returns our output.
+ def query(name)
+ external_command = command
+
+ # Make sure it's an arry
+ unless external_command.is_a?(Array)
+ raise Puppet::DevError, "Exec commands must be an array"
+ end
+
+ # Make sure it's fully qualified.
+ unless external_command[0][0] == File::SEPARATOR[0]
+ raise ArgumentError, "You must set the exec parameter to a fully qualified command"
+ end
+
+ # Add our name to it.
+ external_command << name
+ begin
+ output = execute(external_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 exec %s terminus" % [name, self.name]
+ return nil
+ else
+ return output
+ end
+ end
+end