diff options
author | Luke Kanies <luke@madstop.com> | 2007-10-04 16:38:56 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2007-10-04 16:38:56 -0500 |
commit | 6acde71f7687c6ed6d5fce37cf2346cf3162cefe (patch) | |
tree | d7c456cd6e8a6de649c54992c63fd6420ae0ce0c /lib/puppet | |
parent | 9236179fadf5d0ee68abab395ba1102cd04f3471 (diff) | |
download | puppet-6acde71f7687c6ed6d5fce37cf2346cf3162cefe.tar.gz puppet-6acde71f7687c6ed6d5fce37cf2346cf3162cefe.tar.xz puppet-6acde71f7687c6ed6d5fce37cf2346cf3162cefe.zip |
Switching the indirection from using settings for configuration
to requiring explicit configuration. This means that if
you as an application developer want to use a different indirection
terminus then you have to specify it; something like:
Puppet::Node.terminus_class = :ldap
Caches use the same kind of configuration:
Puppet::Node.cache_class = :memory
Accordingly, I've removed the existing setting definitions
from the defaults.rb.
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/defaults.rb | 9 | ||||
-rw-r--r-- | lib/puppet/indirector/indirection.rb | 67 |
2 files changed, 34 insertions, 42 deletions
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb index 1b0b402ec..6ea4eef4c 100644 --- a/lib/puppet/defaults.rb +++ b/lib/puppet/defaults.rb @@ -500,15 +500,6 @@ module Puppet "The server through which to send email reports."] ) - # This needs to be in main because it's used too early in the system, such that - # we get an infinite loop otherwise. - self.setdefaults(:main, - :facts_terminus => ["yaml", - "The backend store to use for client facts."], - :checksum_terminus => ["file", - "The backend store to use for storing files by checksum (i.e., filebuckets)."] - ) - self.setdefaults(:rails, :dblocation => { :default => "$statedir/clientconfigs.sqlite3", :mode => 0660, diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb index 9cc116e40..3a6284877 100644 --- a/lib/puppet/indirector/indirection.rb +++ b/lib/puppet/indirector/indirection.rb @@ -17,34 +17,26 @@ class Puppet::Indirector::Indirection # Create and return our cache terminus. def cache - terminus(cache_name) + raise(Puppet::DevError, "Tried to cache when no cache class was set") unless cache_class + terminus(cache_class) end # Should we use a cache? def cache? - cache_name ? true : false - end - - # Figure out the cache name, if there is one. If there's no name, then - # caching is disabled. - def cache_name - unless @cache_name - setting_name = "%s_cache" % self.name - if ! Puppet.settings.valid?(setting_name) or (value = Puppet.settings[setting_name] and value == "none") - @cache_name = nil - else - @cache_name = value - @cache_name = @cache_name.intern if @cache_name.is_a?(String) - end - end - @cache_name + cache_class ? true : false + end + + attr_reader :cache_class + # Define a terminus class to be used for caching. + def cache_class=(class_name) + validate_terminus_class(class_name) + @cache_class = class_name end # Clear our cached list of termini, and reset the cache name # so it's looked up again. # This is only used for testing. def clear_cache - @cache_name = nil @termini.clear end @@ -65,7 +57,7 @@ class Puppet::Indirector::Indirection end @termini = {} @terminus_types = {} - @cache_name = nil + @cache_class = nil raise(ArgumentError, "Indirection %s is already defined" % @name) if @@indirections.find { |i| i.name == @name } @@indirections << self end @@ -73,22 +65,31 @@ class Puppet::Indirector::Indirection # Return the singleton terminus for this indirection. def terminus(terminus_name = nil) # Get the name of the terminus. - unless terminus_name - param_name = "%s_terminus" % self.name - if Puppet.settings.valid?(param_name) - terminus_name = Puppet.settings[param_name] - else - terminus_name = Puppet[:default_terminus] - end - unless terminus_name and terminus_name.to_s != "" - raise ArgumentError, "Invalid terminus name %s" % terminus_name.inspect - end - terminus_name = terminus_name.intern if terminus_name.is_a?(String) + unless terminus_name ||= terminus_class + raise Puppet::DevError, "No terminus specified for %s; cannot redirect" % self.name end return @termini[terminus_name] ||= make_terminus(terminus_name) end + attr_reader :terminus_class + + # Specify the terminus class to use. + def terminus_class=(terminus_class) + validate_terminus_class(terminus_class) + @terminus_class = terminus_class + end + + # This is used by terminus_class= and cache=. + def validate_terminus_class(terminus_class) + unless terminus_class and terminus_class.to_s != "" + raise ArgumentError, "Invalid terminus name %s" % terminus_class.inspect + end + unless Puppet::Indirector::Terminus.terminus_class(terminus_class, self.name) + raise ArgumentError, "Could not find terminus %s for indirection %s" % [terminus_class, self.name] + end + end + def find(*args) terminus.find(*args) end @@ -111,10 +112,10 @@ class Puppet::Indirector::Indirection private # Create a new terminus instance. - def make_terminus(name) + def make_terminus(terminus_class) # Load our terminus class. - unless klass = Puppet::Indirector::Terminus.terminus_class(name, self.name) - raise ArgumentError, "Could not find terminus %s for indirection %s" % [name, self.name] + unless klass = Puppet::Indirector::Terminus.terminus_class(terminus_class, self.name) + raise ArgumentError, "Could not find terminus %s for indirection %s" % [terminus_class, self.name] end return klass.new end |