summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRick Bradley <rick@rickbradley.com>2007-10-06 13:25:12 -0500
committerRick Bradley <rick@rickbradley.com>2007-10-06 13:25:12 -0500
commit42b98562b5237797e1a51fdcdd57aa3c6825b404 (patch)
tree0f5cc25fb42b348f3c851c988f3b86979871794a /lib
parent1befcc46926a27ec5f799d6ad8caa59c3b808c4c (diff)
parentcdaad286b1fe5fc3c1ab363c890bb6a8a752c9b5 (diff)
Merge branch 'master' of git://reductivelabs.com/puppet into routing
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/defaults.rb3
-rw-r--r--lib/puppet/dsl.rb11
-rw-r--r--lib/puppet/indirector.rb21
-rw-r--r--lib/puppet/indirector/code/configuration.rb71
-rw-r--r--lib/puppet/network/client/master.rb2
-rw-r--r--lib/puppet/network/handler/configuration.rb45
-rw-r--r--lib/puppet/network/handler/master.rb15
-rw-r--r--lib/puppet/node.rb2
-rw-r--r--lib/puppet/node/configuration.rb2
-rwxr-xr-xlib/puppet/node/facts.rb2
-rw-r--r--lib/puppet/parser/compile.rb4
-rw-r--r--lib/puppet/parser/interpreter.rb26
-rw-r--r--lib/puppet/parser/parser_support.rb10
13 files changed, 94 insertions, 120 deletions
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb
index 6ea4eef4c..ce1411b62 100644
--- a/lib/puppet/defaults.rb
+++ b/lib/puppet/defaults.rb
@@ -292,6 +292,9 @@ module Puppet
"Where puppetmasterd looks for its manifests."],
:manifest => ["$manifestdir/site.pp",
"The entry-point manifest for puppetmasterd."],
+ :code => ["", "Code to parse directly. This is essentially only used
+ by ``puppet`, and should only be set if you're writing your own Puppet
+ executable"],
:masterlog => { :default => "$logdir/puppetmaster.log",
:owner => "$user",
:group => "$group",
diff --git a/lib/puppet/dsl.rb b/lib/puppet/dsl.rb
index 75bc81b2b..97d06a4ec 100644
--- a/lib/puppet/dsl.rb
+++ b/lib/puppet/dsl.rb
@@ -251,12 +251,17 @@ module Puppet
def scope
unless defined?(@scope)
- @interp = Puppet::Parser::Interpreter.new :Code => ""
+ # Set the code to something innocuous; we just need the
+ # scopes, not the interpreter. Hackish, but true.
+ Puppet[:code] = " "
+ @interp = Puppet::Parser::Interpreter.new
require 'puppet/node'
@node = Puppet::Node.new(Facter.value(:hostname))
+ if env = Puppet[:environment] and env == ""
+ env = nil
+ end
@node.parameters = Facter.to_hash
- @interp = Puppet::Parser::Interpreter.new :Code => ""
- @compile = Puppet::Parser::Compile.new(@node, @interp.send(:parser, Puppet[:environment]))
+ @compile = Puppet::Parser::Compile.new(@node, @interp.send(:parser, env))
@scope = @compile.topscope
end
@scope
diff --git a/lib/puppet/indirector.rb b/lib/puppet/indirector.rb
index 6ff2de1b4..7ceaa43e2 100644
--- a/lib/puppet/indirector.rb
+++ b/lib/puppet/indirector.rb
@@ -15,7 +15,7 @@ module Puppet::Indirector
# default, not the value -- if it's the value, then it gets
# evaluated at parse time, which is before the user has had a chance
# to override it.
- def indirects(indirection)
+ def indirects(indirection, options = {})
raise(ArgumentError, "Already handling indirection for %s; cannot also handle %s" % [@indirection.name, indirection]) if defined?(@indirection) and @indirection
# populate this class with the various new methods
extend ClassMethods
@@ -24,10 +24,29 @@ module Puppet::Indirector
# instantiate the actual Terminus for that type and this name (:ldap, w/ args :node)
# & hook the instantiated Terminus into this class (Node: @indirection = terminus)
@indirection = Puppet::Indirector::Indirection.new(self, indirection)
+
+ unless options.empty?
+ options.each do |param, value|
+ case param
+ when :terminus_class: @indirection.terminus_class = value
+ else
+ raise ArgumenError, "Invalid option '%s' to 'indirects'" % param
+ end
+ end
+ end
+ @indirection
end
module ClassMethods
attr_reader :indirection
+
+ def cache_class=(klass)
+ indirection.cache_class = klass
+ end
+
+ def terminus_class=(klass)
+ indirection.terminus_class = klass
+ end
def find(*args)
indirection.find(*args)
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))
diff --git a/lib/puppet/network/client/master.rb b/lib/puppet/network/client/master.rb
index f950a6059..5408cabe4 100644
--- a/lib/puppet/network/client/master.rb
+++ b/lib/puppet/network/client/master.rb
@@ -266,6 +266,7 @@ class Puppet::Network::Client::Master < Puppet::Network::Client
self.getconfig
end
rescue => detail
+ puts detail.backtrace if Puppet[:trace]
Puppet.err "Could not retrieve configuration: %s" % detail
end
@@ -544,6 +545,7 @@ class Puppet::Network::Client::Master < Puppet::Network::Client
end
rescue => detail
+ puts detail.backtrace
Puppet.err "Could not retrieve configuration: %s" % detail
unless Puppet[:usecacheonfailure]
diff --git a/lib/puppet/network/handler/configuration.rb b/lib/puppet/network/handler/configuration.rb
index 353693bdc..09c4b971a 100644
--- a/lib/puppet/network/handler/configuration.rb
+++ b/lib/puppet/network/handler/configuration.rb
@@ -49,10 +49,14 @@ class Puppet::Network::Handler
@local = false
end
- # Just store the options, rather than creating the interpreter
- # immediately. Mostly, this is so we can create the interpreter
- # on-demand, which is easier for testing.
- @options = options
+ options.each do |param, value|
+ case param
+ when :Classes: @classes = value
+ when :Local: self.local = true
+ else
+ raise ArgumentError, "Configuration handler does not accept %s" % param
+ end
+ end
set_server_facts
end
@@ -82,8 +86,8 @@ class Puppet::Network::Handler
node.merge(@server_facts)
# Add any specified classes to the node's class list.
- if classes = @options[:Classes]
- classes.each do |klass|
+ if @classes
+ @classes.each do |klass|
node.classes << klass
end
end
@@ -121,37 +125,14 @@ class Puppet::Network::Handler
end
# Create our interpreter object.
- def create_interpreter(options)
- args = {}
-
- # Allow specification of a code snippet or of a file
- if code = options[:Code]
- args[:Code] = code
- elsif options[:Manifest]
- args[:Manifest] = options[:Manifest]
- end
-
- args[:Local] = local?
-
- if options.include?(:UseNodes)
- args[:UseNodes] = options[:UseNodes]
- elsif @local
- args[:UseNodes] = false
- end
-
- # This is only used by the cfengine module, or if --loadclasses was
- # specified in +puppet+.
- if options.include?(:Classes)
- args[:Classes] = options[:Classes]
- end
-
- return Puppet::Parser::Interpreter.new(args)
+ def create_interpreter
+ return Puppet::Parser::Interpreter.new
end
# Create/return our interpreter.
def interpreter
unless defined?(@interpreter) and @interpreter
- @interpreter = create_interpreter(@options)
+ @interpreter = create_interpreter
end
@interpreter
end
diff --git a/lib/puppet/network/handler/master.rb b/lib/puppet/network/handler/master.rb
index 25c4318b8..1c7f7310e 100644
--- a/lib/puppet/network/handler/master.rb
+++ b/lib/puppet/network/handler/master.rb
@@ -30,13 +30,6 @@ class Puppet::Network::Handler
def initialize(hash = {})
args = {}
- # Allow specification of a code snippet or of a file
- if code = hash[:Code]
- args[:Code] = code
- elsif man = hash[:Manifest]
- args[:Manifest] = man
- end
-
if hash[:Local]
@local = hash[:Local]
else
@@ -53,12 +46,6 @@ class Puppet::Network::Handler
Puppet.debug("Creating interpreter")
- if hash.include?(:UseNodes)
- args[:UseNodes] = hash[:UseNodes]
- elsif @local
- args[:UseNodes] = false
- end
-
# This is only used by the cfengine module, or if --loadclasses was
# specified in +puppet+.
if hash.include?(:Classes)
@@ -74,7 +61,7 @@ class Puppet::Network::Handler
client, clientip = clientname(client, clientip, facts)
# Pass the facts to the fact handler
- Puppet::Node::Facts.new(client, facts).save
+ Puppet::Node::Facts.new(client, facts).save unless local?
# And get the configuration from the config handler
config = config_handler.configuration(client)
diff --git a/lib/puppet/node.rb b/lib/puppet/node.rb
index d71bd507e..9758c895c 100644
--- a/lib/puppet/node.rb
+++ b/lib/puppet/node.rb
@@ -9,7 +9,7 @@ class Puppet::Node
extend Puppet::Indirector
# Use the node source as the indirection terminus.
- indirects :node
+ indirects :node, :terminus_class => :null
# Add the node-searching methods. This is what people will actually
# interact with that will find the node with the list of names or
diff --git a/lib/puppet/node/configuration.rb b/lib/puppet/node/configuration.rb
index 3571eecda..084bdf880 100644
--- a/lib/puppet/node/configuration.rb
+++ b/lib/puppet/node/configuration.rb
@@ -7,7 +7,7 @@ require 'puppet/external/gratr/digraph'
# and the relationships between them.
class Puppet::Node::Configuration < Puppet::PGraph
extend Puppet::Indirector
- indirects :configuration
+ indirects :configuration, :terminus_class => :code
# The host name this is a configuration for.
attr_accessor :name
diff --git a/lib/puppet/node/facts.rb b/lib/puppet/node/facts.rb
index a2e6d9c04..2da6c488e 100755
--- a/lib/puppet/node/facts.rb
+++ b/lib/puppet/node/facts.rb
@@ -9,7 +9,7 @@ class Puppet::Node::Facts
extend Puppet::Indirector
# Use the node source as the indirection terminus.
- indirects :facts
+ indirects :facts, :terminus_class => :code
attr_accessor :name, :values
diff --git a/lib/puppet/parser/compile.rb b/lib/puppet/parser/compile.rb
index 6aeebeaae..992b165e5 100644
--- a/lib/puppet/parser/compile.rb
+++ b/lib/puppet/parser/compile.rb
@@ -16,8 +16,6 @@ class Puppet::Parser::Compile
include Puppet::Util::Errors
attr_reader :topscope, :parser, :node, :facts, :collections, :configuration
- attr_writer :ast_nodes
-
# Add a collection to the global list.
def add_collection(coll)
@collections << coll
@@ -25,7 +23,7 @@ class Puppet::Parser::Compile
# Do we use nodes found in the code, vs. the external node sources?
def ast_nodes?
- defined?(@ast_nodes) and @ast_nodes
+ parser.nodes.length > 0
end
# Store the fact that we've evaluated a class, and store a reference to
diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb
index 0b8c035ba..87513cb18 100644
--- a/lib/puppet/parser/interpreter.rb
+++ b/lib/puppet/parser/interpreter.rb
@@ -14,7 +14,6 @@ class Puppet::Parser::Interpreter
include Puppet::Util
attr_accessor :usenodes
- attr_accessor :code, :file
include Puppet::Util::Errors
@@ -26,21 +25,11 @@ class Puppet::Parser::Interpreter
# evaluate our whole tree
def compile(node)
raise Puppet::ParseError, "Could not parse configuration; cannot compile" unless env_parser = parser(node.environment)
- return Puppet::Parser::Compile.new(node, env_parser, :ast_nodes => usenodes?).compile
+ return Puppet::Parser::Compile.new(node, env_parser).compile
end
# create our interpreter
- def initialize(options = {})
- if @code = options[:Code]
- elsif @file = options[:Manifest]
- end
-
- if options.include?(:UseNodes)
- @usenodes = options[:UseNodes]
- else
- @usenodes = true
- end
-
+ def initialize
# The class won't always be defined during testing.
if Puppet[:storeconfigs]
if Puppet.features.rails?
@@ -53,21 +42,14 @@ class Puppet::Parser::Interpreter
@parsers = {}
end
- # Should we parse ast nodes?
- def usenodes?
- defined?(@usenodes) and @usenodes
- end
-
private
# Create a new parser object and pre-parse the configuration.
def create_parser(environment)
begin
parser = Puppet::Parser::Parser.new(:environment => environment)
- if self.code
- parser.string = self.code
- elsif self.file
- parser.file = self.file
+ if code = Puppet.settings.value(:code, environment) and code != ""
+ parser.string = code
else
file = Puppet.settings.value(:manifest, environment)
parser.file = file
diff --git a/lib/puppet/parser/parser_support.rb b/lib/puppet/parser/parser_support.rb
index 8cf0dcfe8..acf3c9f7c 100644
--- a/lib/puppet/parser/parser_support.rb
+++ b/lib/puppet/parser/parser_support.rb
@@ -366,10 +366,12 @@ class Puppet::Parser::Parser
end
def on_error(token,value,stack)
- #on '%s' at '%s' in\n'%s'" % [token,value,stack]
- #error = "line %s: parse error after '%s'" %
- # [@lexer.line,@lexer.last]
- error = "Syntax error at '%s'" % [value]
+ if token == 0 # denotes end of file
+ value = 'end of file'
+ else
+ value = "'%s'" % value
+ end
+ error = "Syntax error at %s" % [value]
if brace = @lexer.expected
error += "; expected '%s'" % brace