summaryrefslogtreecommitdiffstats
path: root/lib/puppet/provider.rb
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-08-14 06:21:03 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-08-14 06:21:03 +0000
commit12452ee9ca294563f2e2724ff36f179004f9846f (patch)
treebee6053e8164f4a8dbf214f1898fafecb1d61f2f /lib/puppet/provider.rb
parent4d6120a1f77cfe76fafbe32caa5d853449562376 (diff)
downloadpuppet-12452ee9ca294563f2e2724ff36f179004f9846f.tar.gz
puppet-12452ee9ca294563f2e2724ff36f179004f9846f.tar.xz
puppet-12452ee9ca294563f2e2724ff36f179004f9846f.zip
Merging r1468 from the implementations branch with r1438 from when the branch was first created.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1469 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/provider.rb')
-rw-r--r--lib/puppet/provider.rb134
1 files changed, 134 insertions, 0 deletions
diff --git a/lib/puppet/provider.rb b/lib/puppet/provider.rb
new file mode 100644
index 000000000..44851c16b
--- /dev/null
+++ b/lib/puppet/provider.rb
@@ -0,0 +1,134 @@
+# The container class for implementations.
+class Puppet::Provider
+ include Puppet::Util
+
+ Puppet::Util.logmethods(self, true)
+
+ class << self
+ # Include the util module so we have access to things like 'binary'
+ include Puppet::Util
+ attr_accessor :name, :model, :doc
+ end
+
+ attr_accessor :model
+
+ def self.command(name)
+ name = symbolize(name)
+
+ if command = @commands[name]
+ return command
+ elsif superclass.respond_to? :command and command = superclass.command(name)
+ return command
+ else
+ raise Puppet::DevError, "No command %s defined for provider %s" %
+ [name, self.name]
+ end
+ end
+
+ # Define one or more binaries we'll be using
+ def self.commands(hash)
+ hash.each do |name, path|
+ name = symbolize(name)
+ path = binary(path) unless path =~ /^\//
+ @commands[name] = path
+ confine :exists => path
+ end
+ end
+
+ def self.confine(hash)
+ hash.each do |p,v|
+ if v.is_a? Array
+ @confines[p] += v
+ else
+ @confines[p] << v
+ end
+ end
+ end
+
+ # Does this implementation match all of the default requirements?
+ def self.default?
+ if @defaults.find do |fact, value|
+ Facter[fact].value.to_s.downcase.intern != value.to_s.downcase.intern
+ end
+ return false
+ else
+ return true
+ end
+ end
+
+ # Store how to determine defaults.
+ def self.defaultfor(hash)
+ hash.each do |d,v|
+ @defaults[d] = v
+ end
+ end
+
+ def self.defaultnum
+ @defaults.length
+ end
+
+ # Specify a documentation string.
+ def self.desc(str)
+ @doc = str
+ end
+
+ def self.initvars
+ @defaults = {}
+ @commands = {}
+ @confines = Hash.new do |hash, key|
+ hash[key] = []
+ end
+ end
+
+ self.initvars
+
+ # Check whether this implementation is suitable for our platform.
+ def self.suitable?
+ # A single false result is sufficient to turn the whole thing down.
+ @confines.each do |check, values|
+ case check
+ when :exists:
+ values.each do |value|
+ unless value and FileTest.exists? value
+ return false
+ end
+ end
+ when :true:
+ values.each do |v|
+ return false unless v
+ end
+ when :false:
+ values.each do |v|
+ return false if v
+ end
+ else # Just delegate everything else to facter
+ result = Facter.send(check).to_s.downcase.intern
+
+ found = values.find do |v|
+ result == v.to_s.downcase.intern
+ end
+ return false unless found
+ end
+ end
+
+ return true
+ end
+
+ def command(name)
+ self.class.command(name)
+ end
+
+ def initialize(model)
+ @model = model
+ end
+
+ def name
+ @model.name
+ end
+
+ def to_s
+ "%s(provider=%s)" % [@model.to_s, self.class.name]
+ end
+end
+
+# $Id$