summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-12-27 19:37:57 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-12-27 19:37:57 +0000
commit1d057396de46eab64f757d79c7996d0ca0245043 (patch)
tree5da3202c60ee2deb02ea3a8ae22bc6fecb7e12fa /lib/puppet
parent92ff7121ec656b36815b14533fba5e92c165eb08 (diff)
downloadpuppet-1d057396de46eab64f757d79c7996d0ca0245043.tar.gz
puppet-1d057396de46eab64f757d79c7996d0ca0245043.tar.xz
puppet-1d057396de46eab64f757d79c7996d0ca0245043.zip
Switching files to use a filebucket named "puppet" by default. Also, set up MasterClient to create that default filebucket.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1973 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/client/dipper.rb2
-rw-r--r--lib/puppet/client/master.rb158
-rw-r--r--lib/puppet/config.rb5
-rwxr-xr-xlib/puppet/server/filebucket.rb2
-rw-r--r--lib/puppet/type/pfile.rb50
-rwxr-xr-xlib/puppet/type/pfilebucket.rb13
-rwxr-xr-xlib/puppet/type/schedule.rb24
7 files changed, 149 insertions, 105 deletions
diff --git a/lib/puppet/client/dipper.rb b/lib/puppet/client/dipper.rb
index a3a69ffa4..1422c24f2 100644
--- a/lib/puppet/client/dipper.rb
+++ b/lib/puppet/client/dipper.rb
@@ -47,7 +47,6 @@ module Puppet
end
if restore
- #puts "Restoring %s" % file
if newcontents = @driver.getfile(sum)
unless local?
newcontents = Base64.decode64(newcontents)
@@ -69,7 +68,6 @@ module Puppet
Puppet.err "Could not find file with checksum %s" % sum
return nil
end
- #puts "Done"
return newsum
else
return nil
diff --git a/lib/puppet/client/master.rb b/lib/puppet/client/master.rb
index e6e7c7835..66bdcd55b 100644
--- a/lib/puppet/client/master.rb
+++ b/lib/puppet/client/master.rb
@@ -243,7 +243,7 @@ class Puppet::Client::MasterClient < Puppet::Client
# Retrieve the plugins.
if Puppet[:pluginsync]
- self.class.getplugins()
+ getplugins()
end
facts = self.class.facts
@@ -254,68 +254,7 @@ class Puppet::Client::MasterClient < Puppet::Client
)
end
- objects = nil
- if @local
- # If we're local, we don't have to do any of the conversion
- # stuff.
- objects = @driver.getconfig(facts, "yaml")
- @configstamp = Time.now.to_i
-
- if objects == ""
- raise Puppet::Error, "Could not retrieve configuration"
- end
- else
- textobjects = ""
-
- textfacts = CGI.escape(YAML.dump(facts))
-
- benchmark(:debug, "Retrieved configuration") do
- # error handling for this is done in the network client
- begin
- textobjects = @driver.getconfig(textfacts, "yaml")
- rescue => detail
- Puppet.err "Could not retrieve configuration: %s" % detail
-
- unless Puppet[:usecacheonfailure]
- @objects = nil
- Puppet.warning "Not using cache on failed configuration"
- return
- end
- end
- end
-
- fromcache = false
- if textobjects == ""
- textobjects = self.retrievecache
- if textobjects == ""
- raise Puppet::Error.new(
- "Cannot connect to server and there is no cached configuration"
- )
- end
- Puppet.warning "Could not get config; using cached copy"
- fromcache = true
- else
- @configstamp = Time.now.to_i
- end
-
- begin
- textobjects = CGI.unescape(textobjects)
- rescue => detail
- raise Puppet::Error, "Could not CGI.unescape configuration"
- end
-
- if @cache and ! fromcache
- self.cache(textobjects)
- end
-
- begin
- objects = YAML.load(textobjects)
- rescue => detail
- raise Puppet::Error,
- "Could not understand configuration: %s" %
- detail.to_s
- end
- end
+ objects = get_actual_config(facts)
unless objects.is_a?(Puppet::TransBucket)
raise NetworkClientError,
@@ -334,7 +273,10 @@ class Puppet::Client::MasterClient < Puppet::Client
@objects = nil
# First create the default scheduling objects
- Puppet.type(:schedule).mkdefaultschedules
+ Puppet::Type.type(:schedule).mkdefaultschedules
+
+ # And filebuckets
+ Puppet::Type.type(:filebucket).mkdefaultbucket
# Now convert the objects to real Puppet objects
@objects = objects.to_type
@@ -348,7 +290,12 @@ class Puppet::Client::MasterClient < Puppet::Client
return @objects
end
-
+
+ # A simple proxy method, so it's easy to test.
+ def getplugins
+ self.class.getplugins
+ end
+
# Just so we can specify that we are "the" instance.
def initialize(*args)
super
@@ -640,6 +587,87 @@ class Puppet::Client::MasterClient < Puppet::Client
end
loadfacts()
+
+ private
+
+ # Actually retrieve the configuration, either from the server or from a local master.
+ def get_actual_config(facts)
+ if @local
+ return get_local_config(facts)
+ else
+ return get_remote_config(facts)
+ end
+ end
+
+ # Retrieve a configuration from a local master.
+ def get_local_config(facts)
+ # If we're local, we don't have to do any of the conversion
+ # stuff.
+ objects = @driver.getconfig(facts, "yaml")
+ @configstamp = Time.now.to_i
+
+ if objects == ""
+ raise Puppet::Error, "Could not retrieve configuration"
+ end
+
+ return objects
+ end
+
+ # Retrieve a config from a remote master.
+ def get_remote_config(facts)
+ textobjects = ""
+
+ textfacts = CGI.escape(YAML.dump(facts))
+
+ benchmark(:debug, "Retrieved configuration") do
+ # error handling for this is done in the network client
+ begin
+ textobjects = @driver.getconfig(textfacts, "yaml")
+ rescue => detail
+ Puppet.err "Could not retrieve configuration: %s" % detail
+
+ unless Puppet[:usecacheonfailure]
+ @objects = nil
+ Puppet.warning "Not using cache on failed configuration"
+ return
+ end
+ end
+ end
+
+ fromcache = false
+ if textobjects == ""
+ textobjects = self.retrievecache
+ if textobjects == ""
+ raise Puppet::Error.new(
+ "Cannot connect to server and there is no cached configuration"
+ )
+ end
+ Puppet.warning "Could not get config; using cached copy"
+ fromcache = true
+ else
+ @configstamp = Time.now.to_i
+ end
+
+ begin
+ textobjects = CGI.unescape(textobjects)
+ rescue => detail
+ raise Puppet::Error, "Could not CGI.unescape configuration"
+ end
+
+ if @cache and ! fromcache
+ self.cache(textobjects)
+ end
+
+ begin
+ objects = YAML.load(textobjects)
+ rescue => detail
+ raise Puppet::Error,
+ "Could not understand configuration: %s" %
+ detail.to_s
+ end
+
+ return objects
+ end
end
# $Id$
diff --git a/lib/puppet/config.rb b/lib/puppet/config.rb
index 91c348b51..10a2198f8 100644
--- a/lib/puppet/config.rb
+++ b/lib/puppet/config.rb
@@ -911,6 +911,11 @@ Generated on #{Time.now}.
# And set the loglevel to debug for everything
obj[:loglevel] = "debug"
+
+ # We're not actually modifying any files here, and if we allow a
+ # filebucket to get used here we get into an infinite recursion
+ # trying to set the filebucket up.
+ obj[:backup] = false
if self.section
obj.tags += ["puppet", "configuration", self.section, self.name]
diff --git a/lib/puppet/server/filebucket.rb b/lib/puppet/server/filebucket.rb
index fa86e970b..0aebf4386 100755
--- a/lib/puppet/server/filebucket.rb
+++ b/lib/puppet/server/filebucket.rb
@@ -60,7 +60,7 @@ class Server
Puppet.config.use(:filebucket)
- @name = "filebucket[#{@path}]"
+ @name = "Filebucket[#{@path}]"
end
# accept a file from a client
diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb
index c3206414e..e17a43b97 100644
--- a/lib/puppet/type/pfile.rb
+++ b/lib/puppet/type/pfile.rb
@@ -32,13 +32,17 @@ module Puppet
newparam(:backup) do
desc "Whether files should be backed up before
- being replaced. If a filebucket is specified, files will be
- backed up there; else, they will be backed up in the same directory
- with a ``.puppet-bak`` extension,, and no backups
- will be made if backup is ``false``.
+ being replaced. The preferred method of backing files up is via
+ a ``filebucket``, which stores files by their MD5 sums and allows
+ easy retrieval without littering directories with backups. You can
+ specify a local filebucket or a network-accessible server-based filebucket.
+ Alternatively, if you specify any value that begins with a ``.`` (e.g.,
+ ``.puppet-bak``), then Puppet will use copy the file in the same directory with that value as the
+ extension of the backup.
- To use filebuckets, you must first create a filebucket in your
- configuration:
+ Puppet automatically creates a local filebucket named ``puppet`` and
+ defaults to backing up there. To use a server-based filebucket,
+ you must specify one in your configuration:
filebucket { main:
server => puppet
@@ -56,7 +60,7 @@ module Puppet
This will back the file up to the central server.
- At this point, the only benefits to doing so are that you do not
+ At this point, the benefits of using a filebucket are that you do not
have backup files lying around on each of your machines, a given
version of a file is only backed up once, and you can restore
any given file manually, no matter how old. Eventually,
@@ -64,35 +68,31 @@ module Puppet
filebucketed files.
"
- attr_reader :bucket
- defaultto ".puppet-bak"
-
+ defaultto "puppet"
+
munge do |value|
case value
when false, "false", :false:
false
when true, "true", ".puppet-bak", :true:
".puppet-bak"
+ when /^\./
+ value
when String:
# We can't depend on looking this up right now,
# we have to do it after all of the objects
# have been instantiated.
if bucketobj = Puppet::Type.type(:filebucket)[value]
- @bucket = bucketobj.bucket
+ @parent.bucket = bucketobj.bucket
else
- @bucket = value
+ @parent.bucket = value
end
+ when Puppet::Client::Dipper: value
else
self.fail "Invalid backup type %s" %
value.inspect
end
end
-
- # Provide a straight-through hook for setting the bucket.
- def bucket=(bucket)
- @value = bucket
- @bucket = bucket
- end
end
newparam(:linkmaker) do
@@ -176,6 +176,8 @@ module Puppet
newvalues(:true, :false)
end
+
+ attr_accessor :bucket
# Autorequire any parent directories.
autorequire(:file) do
@@ -263,15 +265,19 @@ module Puppet
@@filebuckets ||= {}
# Look up our bucket, if there is one
- if @parameters.include?(:backup) and bucket = @parameters[:backup].bucket
+ if @parameters.include?(:backup) and bucket = self.bucket
case bucket
when String:
if obj = @@filebuckets[bucket]
# This sets the @value on :backup, too
- @parameters[:backup].bucket = obj
- elsif obj = Puppet.type(:filebucket).bucket(bucket)
+ self.bucket = obj
+ # elsif bucket == "puppet"
+ # obj = Puppet::Client::Dipper.new(
+ # :Path => Puppet[:puppetdir]
+ # )
+ elsif obj = Puppet::Type.type(:filebucket).bucket(bucket)
@@filebuckets[bucket] = obj
- @parameters[:backup].bucket = obj
+ self.bucket = obj
else
self.fail "Could not find filebucket %s" % bucket
end
diff --git a/lib/puppet/type/pfilebucket.rb b/lib/puppet/type/pfilebucket.rb
index d8c676114..3375f5615 100755
--- a/lib/puppet/type/pfilebucket.rb
+++ b/lib/puppet/type/pfilebucket.rb
@@ -29,8 +29,6 @@ module Puppet
work in a default configuration.
"
- @states = []
-
newparam(:name) do
desc "The name of the filebucket."
isnamevar
@@ -65,6 +63,13 @@ module Puppet
return nil
end
end
+
+ # Create a default filebucket.
+ def self.mkdefaultbucket
+ unless self["puppet"]
+ self.create :name => "puppet", :path => Puppet[:bucketdir]
+ end
+ end
def self.list
self.collect do |obj| obj.name end
@@ -91,14 +96,12 @@ module Puppet
)
end
else
- unless self[:path]
- self[:path] = Puppet[:bucketdir]
- end
begin
@bucket = Puppet::Client::Dipper.new(
:Path => self[:path]
)
rescue => detail
+ puts detail.backtrace
self.fail(
"Could not create local filebucket: %s" % detail
)
diff --git a/lib/puppet/type/schedule.rb b/lib/puppet/type/schedule.rb
index 8c89ab906..a329686ef 100755
--- a/lib/puppet/type/schedule.rb
+++ b/lib/puppet/type/schedule.rb
@@ -312,20 +312,24 @@ module Puppet
end
def self.mkdefaultschedules
- Puppet.debug "Creating default schedules"
# Create our default schedule
- self.create(
- :name => "puppet",
- :period => :hourly,
- :repeat => "2"
- )
+ unless self["puppet"]
+ Puppet.debug "Creating default schedules"
+ self.create(
+ :name => "puppet",
+ :period => :hourly,
+ :repeat => "2"
+ )
+ end
# And then one for every period
@parameters.find { |p| p.name == :period }.values.each { |value|
- self.create(
- :name => value.to_s,
- :period => value
- )
+ unless self[value.to_s]
+ self.create(
+ :name => value.to_s,
+ :period => value
+ )
+ end
}
end