diff options
| author | Rick Bradley <rick@rickbradley.com> | 2007-10-05 10:42:14 -0500 |
|---|---|---|
| committer | Rick Bradley <rick@rickbradley.com> | 2007-10-05 10:42:14 -0500 |
| commit | 7086ce17d14274f93ef0c03fba531bdb6710e5f7 (patch) | |
| tree | 55dc390fd3d75f4579bccd645a1ae21fc79ba357 /lib | |
| parent | 29accba1b9343f4967c15d36506b3bf60d5f0f9c (diff) | |
| parent | 95b2b93290f619c20a1c2dca11dd9909477857f8 (diff) | |
| download | puppet-7086ce17d14274f93ef0c03fba531bdb6710e5f7.tar.gz puppet-7086ce17d14274f93ef0c03fba531bdb6710e5f7.tar.xz puppet-7086ce17d14274f93ef0c03fba531bdb6710e5f7.zip | |
Merge branch 'master' of git://reductivelabs.com/puppet into routing
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/puppet/defaults.rb | 9 | ||||
| -rw-r--r-- | lib/puppet/indirector/indirection.rb | 67 | ||||
| -rw-r--r-- | lib/puppet/indirector/ldap/node.rb | 7 | ||||
| -rw-r--r-- | lib/puppet/property.rb | 3 | ||||
| -rwxr-xr-x | lib/puppet/provider/package/dpkg.rb | 9 | ||||
| -rwxr-xr-x | lib/puppet/provider/package/sun.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/provider/service/freebsd.rb | 46 |
7 files changed, 95 insertions, 48 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 diff --git a/lib/puppet/indirector/ldap/node.rb b/lib/puppet/indirector/ldap/node.rb index 6f35b575c..2e800abbe 100644 --- a/lib/puppet/indirector/ldap/node.rb +++ b/lib/puppet/indirector/ldap/node.rb @@ -21,8 +21,11 @@ class Puppet::Indirector::Ldap::Node < Puppet::Indirector::Ldap raise ArgumentError, "Found loop in LDAP node parents; %s appears twice" % parent end parents << parent - ldapsearch(parent) do |entry| - parent_info = process(parent, entry) + + ldapsearch(parent) { |entry| parent_info = process(parent, entry) } + + unless parent_info + raise Puppet::Error.new("Could not find parent node '%s'" % parent) end information[:classes] += parent_info[:classes] parent_info[:parameters].each do |param, value| diff --git a/lib/puppet/property.rb b/lib/puppet/property.rb index cd3c35b38..84620bfb6 100644 --- a/lib/puppet/property.rb +++ b/lib/puppet/property.rb @@ -56,8 +56,7 @@ class Property < Puppet::Parameter # Look up a value's name, so we can find options and such. def self.value_name(value) - name = symbolize(value) - if @parametervalues[name] + if value != '' and name = symbolize(value) and @parametervalues.include?(name) return name elsif ary = self.match?(value) return ary[0] diff --git a/lib/puppet/provider/package/dpkg.rb b/lib/puppet/provider/package/dpkg.rb index 44e6a985c..512170a73 100755 --- a/lib/puppet/provider/package/dpkg.rb +++ b/lib/puppet/provider/package/dpkg.rb @@ -56,9 +56,18 @@ Puppet::Type.type(:package).provide :dpkg, :parent => Puppet::Provider::Package dpkg "-i", file end + def update + self.install + end + # Return the version from the package. def latest output = dpkg_deb "--show", @resource[:source] + matches = /^(\S+)\t(\S+)$/.match(output).captures + unless matches[0].match(@resource[:name]) + Puppet.warning "source doesn't contain named package, but %s" % matches[0] + end + matches[1] end def query diff --git a/lib/puppet/provider/package/sun.rb b/lib/puppet/provider/package/sun.rb index e204e6d58..927596df2 100755 --- a/lib/puppet/provider/package/sun.rb +++ b/lib/puppet/provider/package/sun.rb @@ -51,8 +51,6 @@ Puppet::Type.type(:package).provide :sun, :parent => Puppet::Provider::Package d unless names[name].nil? hash[names[name]] = value end - else - raise "Could not find %s" % name end when /\s+\d+.+/: # nothing; we're ignoring the FILES info diff --git a/lib/puppet/provider/service/freebsd.rb b/lib/puppet/provider/service/freebsd.rb new file mode 100644 index 000000000..31fdacb86 --- /dev/null +++ b/lib/puppet/provider/service/freebsd.rb @@ -0,0 +1,46 @@ +# Manage FreeBSD services. +Puppet::Type.type(:service).provide :freebsd, :parent => :init do + desc "FreeBSD's (and probably NetBSD?) form of ``init``-style service + management; uses ``rc-update`` for service enabling and disabling." + + commands :rcupdate => "/usr/local/sbin/rc-update" + + defaultfor :operatingsystem => :freebsd + + def self.defpath + superclass.defpath + end + + def disable + begin + output = rcupdate("disable", @model[:name]) + rescue Puppet::ExecutionFailure + raise Puppet::Error, "Could not disable %s: %s" % + [self.name, output] + end + end + + def enabled? + begin + output = rcupdate("enabled", @model[:name]) + rescue Puppet::ExecutionFailure + return :false + end + + # If it's enabled, output is 0 + if output =~ /^0$/ + return :true + end + + return :false + end + + def enable + begin + output = rcupdate("enable", @model[:name]) + rescue Puppet::ExecutionFailure => detail + raise Puppet::Error, "Could not enable %s: %s" % + [self.name, detail] + end + end +end |
