summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/interpreter.rb
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-01-05 04:44:24 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-01-05 04:44:24 +0000
commitf6beef5c57381973c68468be9d4b1cac593a037c (patch)
tree1da3355c6f5c3e09e176124b5c44711f54050efe /lib/puppet/parser/interpreter.rb
parentf8f7c57b9e10477fc14f6bc655ad194598c91980 (diff)
downloadpuppet-f6beef5c57381973c68468be9d4b1cac593a037c.tar.gz
puppet-f6beef5c57381973c68468be9d4b1cac593a037c.tar.xz
puppet-f6beef5c57381973c68468be9d4b1cac593a037c.zip
Fixing #407. You can use external_node to specify a command to retrieve your node information.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2049 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/parser/interpreter.rb')
-rw-r--r--lib/puppet/parser/interpreter.rb50
1 files changed, 49 insertions, 1 deletions
diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb
index a00b10042..0117ac2dd 100644
--- a/lib/puppet/parser/interpreter.rb
+++ b/lib/puppet/parser/interpreter.rb
@@ -15,7 +15,16 @@ class Puppet::Parser::Interpreter
:casesensitive => [false,
"Whether matching in case statements and selectors
should be case-sensitive. Case insensitivity is
- handled by downcasing all values before comparison."])
+ handled by downcasing all values before comparison."],
+ :external_nodes => ["none",
+ "An external command that can produce node information. The
+ first line of output must be either the parent node or blank,
+ and if there is a second line of output it should be a list of
+ whitespace-separated classes to include on that node. This command
+ makes it straightforward to store your node mapping information
+ in other data sources like databases.
+
+ For unknown nodes, the commands should exit with an exit code of 1."])
Puppet.setdefaults("ldap",
:ldapnodes => [false,
@@ -642,6 +651,45 @@ class Puppet::Parser::Interpreter
def nodesearch_code(name)
@nodetable[name]
end
+
+ # Look for external node definitions.
+ def nodesearch_external(name)
+ return nil unless Puppet[:external_nodes] != "none"
+
+ begin
+ output = Puppet::Util.execute([Puppet[:external_nodes], name])
+ 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
+ puts "empty response for %s" % name
+ return nil
+ end
+
+ lines = output.split("\n")
+
+ args = {}
+ parent = lines[0].gsub(/\s+/, '')
+ args[:parentnode] = parent unless parent == ""
+
+ if lines[1]
+ classes = lines[1].sub(/^\s+/,'').sub(/\s+$/,'').split(/\s+/)
+ args[:classes] = classes unless classes.empty?
+ end
+
+ if args.empty?
+ Puppet.warning "Somehow got a node with no information"
+ return nil
+ else
+ return gennode(name, args)
+ end
+ end
# Look for our node in ldap.
def nodesearch_ldap(node)