diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-04-04 22:23:08 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-04-04 22:23:08 +0000 |
| commit | d8b4b0dbf35b2b183cd62adf591ebf4650448a0d (patch) | |
| tree | d51d99be35d0702ffc08bd0e8a28e82d8daf2e6b /lib/puppet | |
| parent | c0a9e5f2e9df8e6e1aed74653ae675029af8a9bb (diff) | |
| download | puppet-d8b4b0dbf35b2b183cd62adf591ebf4650448a0d.tar.gz puppet-d8b4b0dbf35b2b183cd62adf591ebf4650448a0d.tar.xz puppet-d8b4b0dbf35b2b183cd62adf591ebf4650448a0d.zip | |
adding -e ability to puppet executable
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1065 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet')
| -rw-r--r-- | lib/puppet/client/master.rb | 22 | ||||
| -rw-r--r-- | lib/puppet/log.rb | 14 | ||||
| -rw-r--r-- | lib/puppet/parser/interpreter.rb | 46 | ||||
| -rw-r--r-- | lib/puppet/server/master.rb | 23 |
4 files changed, 65 insertions, 40 deletions
diff --git a/lib/puppet/client/master.rb b/lib/puppet/client/master.rb index cb2d6f444..390c07220 100644 --- a/lib/puppet/client/master.rb +++ b/lib/puppet/client/master.rb @@ -26,7 +26,9 @@ class Puppet::Client::MasterClient < Puppet::Client # objects. For now, just descend into the tree and perform and # necessary manipulations. def apply - Puppet.notice "Beginning configuration run" + unless @local + Puppet.notice "Beginning configuration run" + end dostorage() unless defined? @objects raise Puppet::Error, "Cannot apply; objects not defined" @@ -65,7 +67,9 @@ class Puppet::Client::MasterClient < Puppet::Client Metric.store Metric.graph end - Puppet.notice "Finished configuration run" + unless @local + Puppet.notice "Finished configuration run" + end return transaction end @@ -228,11 +232,7 @@ class Puppet::Client::MasterClient < Puppet::Client "Invalid returned objects of type %s" % objects.class end - if classes = objects.classes - self.setclasses(classes) - else - Puppet.info "No classes to store" - end + self.setclasses(objects.classes) # Clear all existing objects, so we can recreate our stack. if defined? @objects @@ -280,7 +280,15 @@ class Puppet::Client::MasterClient < Puppet::Client end end + # Store the classes in the classfile, but only if we're not local. def setclasses(ary) + if @local + return + end + unless ary and ary.length > 0 + Puppet.info "No classes to store" + return + end begin File.open(Puppet[:classfile], "w") { |f| f.puts ary.join("\n") diff --git a/lib/puppet/log.rb b/lib/puppet/log.rb index 6b8a55c18..1a392ac64 100644 --- a/lib/puppet/log.rb +++ b/lib/puppet/log.rb @@ -195,14 +195,20 @@ module Puppet dest.puts("%s %s (%s): %s" % [msg.time, msg.source, msg.level, msg.to_s]) when :console + color = "" + reset = "" + if Puppet[:color] + color = @colors[msg.level] + reset = RESET + end if msg.source == "Puppet" - puts @colors[msg.level] + "%s: %s" % [ + puts color + "%s: %s" % [ msg.level, msg.to_s - ] + RESET + ] + reset else - puts @colors[msg.level] + "%s: %s: %s" % [ + puts color + "%s: %s: %s" % [ msg.level, msg.source, msg.to_s - ] + RESET + ] + reset end when Puppet::Client::LogClient unless msg.is_a?(String) or msg.remote diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb index 4f5f1f69a..730b59e15 100644 --- a/lib/puppet/parser/interpreter.rb +++ b/lib/puppet/parser/interpreter.rb @@ -42,11 +42,11 @@ module Puppet # create our interpreter def initialize(hash) - unless hash.include?(:Manifest) - raise Puppet::DevError, "Interpreter was not passed a manifest" + if @code = hash[:Code] + @file = nil # to avoid warnings + elsif ! @file = hash[:Manifest] + raise Puppet::DevError, "You must provide code or a manifest" end - - @file = hash[:Manifest] @filetimeout = hash[:ParseCheck] || 15 @lastchecked = 0 @@ -258,24 +258,26 @@ module Puppet end def parsefiles - if defined? @parser - # Only check the files every 15 seconds or so, not on - # every single connection - if (Time.now - @lastchecked).to_i >= @filetimeout.to_i - unless @parser.reparse? - @lastchecked = Time.now - return false + if @file + if defined? @parser + # Only check the files every 15 seconds or so, not on + # every single connection + if (Time.now - @lastchecked).to_i >= @filetimeout.to_i + unless @parser.reparse? + @lastchecked = Time.now + return false + end + else + return end - else - return end - end - unless FileTest.exists?(@file) - if @ast - return - else - raise Puppet::Error, "Manifest %s must exist" % @file + unless FileTest.exists?(@file) + if @ast + return + else + raise Puppet::Error, "Manifest %s must exist" % @file + end end end @@ -284,7 +286,11 @@ module Puppet end # should i be creating a new parser each time...? @parser = Puppet::Parser::Parser.new() - @parser.file = @file + if @code + @parser.string = @code + else + @parser.file = @file + end @ast = @parser.parse # Mark when we parsed, so we can check freshness diff --git a/lib/puppet/server/master.rb b/lib/puppet/server/master.rb index 07a476efd..7e719452f 100644 --- a/lib/puppet/server/master.rb +++ b/lib/puppet/server/master.rb @@ -35,10 +35,14 @@ class Server end def initialize(hash = {}) - # FIXME this should all be s/:File/:Manifest/g or something - # build our AST - @file = hash[:File] || Puppet[:manifest] - hash.delete(:File) + args = {} + + # Allow specification of a code snippet or of a file + if code = hash[:Code] + args[:Code] = code + else + args[:Manifest] = hash[:Manifest] || Puppet[:manifest] + end if hash[:Local] @local = hash[:Local] @@ -52,19 +56,18 @@ class Server @ca = nil end - @parsecheck = hash[:FileTimeout] || 15 + args[:ParseCheck] = hash[:FileTimeout] || 15 Puppet.debug("Creating interpreter") - args = {:Manifest => @file, :ParseCheck => @parsecheck} - if hash.include?(:UseNodes) args[:UseNodes] = hash[:UseNodes] elsif @local args[:UseNodes] = false end - # This is only used by the cfengine module + # This is only used by the cfengine module, or if --loadclasses was specified + # in +puppet+. if hash.include?(:Classes) args[:Classes] = hash[:Classes] end @@ -110,7 +113,9 @@ class Server clientip = facts["ipaddress"] end - Puppet.notice("Compiling configuration for %s" % client) + unless @local + Puppet.notice("Compiling configuration for %s" % client) + end begin retobjects = @interpreter.run(client, facts) rescue Puppet::Error => detail |
