diff options
Diffstat (limited to 'lib/puppet/provider.rb')
-rw-r--r-- | lib/puppet/provider.rb | 79 |
1 files changed, 11 insertions, 68 deletions
diff --git a/lib/puppet/provider.rb b/lib/puppet/provider.rb index e73bb0cb6..e0de9d61d 100644 --- a/lib/puppet/provider.rb +++ b/lib/puppet/provider.rb @@ -5,6 +5,8 @@ class Puppet::Provider include Puppet::Util::Warnings extend Puppet::Util::Warnings + require 'puppet/provider/confiner' + Puppet::Util.logmethods(self, true) class << self @@ -55,13 +57,14 @@ class Puppet::Provider end def self.confine(hash) - hash.each do |p,v| - if v.is_a? Array - @confines[p] += v - else - @confines[p] << v - end + confiner.confine(hash) + end + + def self.confiner + unless defined?(@confiner) + @confiner = Puppet::Provider::Confiner.new end + @confiner end # Is the provided feature a declared feature? @@ -109,9 +112,6 @@ class Puppet::Provider @defaults = {} @commands = {} @origcommands = {} - @confines = Hash.new do |hash, key| - hash[key] = [] - end end # The method for returning a list of provider instances. Note that it returns providers, preferably with values already @@ -210,65 +210,8 @@ class Puppet::Provider # Check whether this implementation is suitable for our platform. def self.suitable?(short = true) - # A single false result is sufficient to turn the whole thing down. - # We don't return 'true' until the very end, though, so that every - # confine is tested. - missing = {} - @confines.each do |check, values| - case check - when :exists: - values.each do |value| - unless value and FileTest.exists? value - debug "Not suitable: missing %s" % value - return false if short - missing[:exists] ||= [] - missing[:exists] << value - end - end - when :true: - values.each do |v| - debug "Not suitable: false value" - unless v - return false if short - missing[:true] ||= 0 - missing[:true] += 1 - end - end - when :false: - values.each do |v| - debug "Not suitable: true value" - if v and short - return false if short - missing[:false] ||= 0 - missing[:false] += 1 - end - end - else # Just delegate everything else to facter - if result = Facter.value(check) - result = result.to_s.downcase.intern - - found = values.find do |v| - result == v.to_s.downcase.intern - end - unless found - debug "Not suitable: %s not in %s" % [check, values] - return false if short - missing[:facter] ||= {} - missing[:facter][check] = values - end - else - return false if short - missing[:facter] ||= {} - missing[:facter][check] = values - end - end - end - - if short - return true - else - return missing - end + return confiner.valid? if short + return confiner.result end # Does this provider support the specified parameter? |