summaryrefslogtreecommitdiffstats
path: root/lib/puppet/client
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/client
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/client')
-rw-r--r--lib/puppet/client/dipper.rb2
-rw-r--r--lib/puppet/client/master.rb158
2 files changed, 93 insertions, 67 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$