diff options
author | Rick Bradley <rick@rickbradley.com> | 2007-10-06 13:25:12 -0500 |
---|---|---|
committer | Rick Bradley <rick@rickbradley.com> | 2007-10-06 13:25:12 -0500 |
commit | 42b98562b5237797e1a51fdcdd57aa3c6825b404 (patch) | |
tree | 0f5cc25fb42b348f3c851c988f3b86979871794a /lib/puppet/indirector/code | |
parent | 1befcc46926a27ec5f799d6ad8caa59c3b808c4c (diff) | |
parent | cdaad286b1fe5fc3c1ab363c890bb6a8a752c9b5 (diff) | |
download | puppet-42b98562b5237797e1a51fdcdd57aa3c6825b404.tar.gz puppet-42b98562b5237797e1a51fdcdd57aa3c6825b404.tar.xz puppet-42b98562b5237797e1a51fdcdd57aa3c6825b404.zip |
Merge branch 'master' of git://reductivelabs.com/puppet into routing
Diffstat (limited to 'lib/puppet/indirector/code')
-rw-r--r-- | lib/puppet/indirector/code/configuration.rb | 71 |
1 files changed, 33 insertions, 38 deletions
diff --git a/lib/puppet/indirector/code/configuration.rb b/lib/puppet/indirector/code/configuration.rb index 6d0317204..2d8fedcc8 100644 --- a/lib/puppet/indirector/code/configuration.rb +++ b/lib/puppet/indirector/code/configuration.rb @@ -15,21 +15,12 @@ class Puppet::Indirector::Code::Configuration < Puppet::Indirector::Code # Compile a node's configuration. def find(key, client = nil, clientip = nil) - # If we want to use the cert name as our key - if Puppet[:node_name] == 'cert' and client - key = client - end - - # Note that this is reasonable, because either their node source should actually - # know about the node, or they should be using the ``none`` node source, which - # will always return data. - unless node = Puppet::Node.search(key) - raise Puppet::Error, "Could not find node '%s'" % key + if key.is_a?(Puppet::Node) + node = key + else + node = find_node(key) end - # Add any external data to the node. - add_node_data(node) - configuration = compile(node) return configuration @@ -47,6 +38,11 @@ class Puppet::Indirector::Code::Configuration < Puppet::Indirector::Code @interpreter end + # Is our compiler part of a network, or are we just local? + def networked? + $0 =~ /puppetmasterd/ + end + # Return the configuration version. def version(client = nil, clientip = nil) if client and node = Puppet::Node.search(client) @@ -76,22 +72,14 @@ class Puppet::Indirector::Code::Configuration < Puppet::Indirector::Code end config = nil - # LAK:FIXME This should log at :none when our client is - # local, since we don't want 'puppet' (vs. puppetmasterd) to - # log compile times. - benchmark(:notice, "Compiled configuration for %s" % node.name) do + loglevel = networked? ? :notice : :none + + benchmark(loglevel, "Compiled configuration for %s" % node.name) do begin config = interpreter.compile(node) rescue Puppet::Error => detail - if Puppet[:trace] - puts detail.backtrace - end - unless local? - Puppet.err detail.to_s - end - raise XMLRPC::FaultException.new( - 1, detail.to_s - ) + Puppet.err(detail.to_s) if networked? + raise end end @@ -100,21 +88,28 @@ class Puppet::Indirector::Code::Configuration < Puppet::Indirector::Code # Create our interpreter object. def create_interpreter - args = {} + return Puppet::Parser::Interpreter.new + end - # Allow specification of a code snippet or of a file - if self.code - args[:Code] = self.code + # Turn our host name into a node object. + def find_node(key) + # If we want to use the cert name as our key + # LAK:FIXME This needs to be figured out somehow, but it requires the routing. + #if Puppet[:node_name] == 'cert' and client + # key = client + #end + + # Note that this is reasonable, because either their node source should actually + # know about the node, or they should be using the ``none`` node source, which + # will always return data. + unless node = Puppet::Node.search(key) + raise Puppet::Error, "Could not find node '%s'" % key end - # LAK:FIXME This needs to be handled somehow. - #if options.include?(:UseNodes) - # args[:UseNodes] = options[:UseNodes] - #elsif @local - # args[:UseNodes] = false - #end + # Add any external data to the node. + add_node_data(node) - return Puppet::Parser::Interpreter.new(args) + node end # Initialize our server fact hash; we add these to each client, and they @@ -150,7 +145,7 @@ class Puppet::Indirector::Code::Configuration < Puppet::Indirector::Code # LAK:FIXME This method should probably be part of the protocol, but it # shouldn't be here. def translate(config) - if local? + unless networked? config else CGI.escape(config.to_yaml(:UseBlock => true)) |