summaryrefslogtreecommitdiffstats
path: root/lib/puppet/provider.rb
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-06-04 20:37:14 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-06-04 20:37:14 +0000
commitc35d07b4183be141fa606de665c52740f5cc6510 (patch)
tree6597bb7385d64ed1546541a221edb2d02585e5d2 /lib/puppet/provider.rb
parenta7b057de317ffc60e50405ea1ebb109ba4003b4f (diff)
downloadpuppet-c35d07b4183be141fa606de665c52740f5cc6510.tar.gz
puppet-c35d07b4183be141fa606de665c52740f5cc6510.tar.xz
puppet-c35d07b4183be141fa606de665c52740f5cc6510.zip
Significantly reworked the type => provider interface with respect to
listing existing provider instances. The class method on both class heirarchies has been renamed to 'instances', to start. Providers are now expected to return provider instances, instead of creating resources, and the resource's 'instances' method is expected to find the matching resource, if any, and set the resource's provider appropriately. This *significantly* reduces the reliance on effectively global state (resource references in the resource classes). This global state will go away soon. Along with this change, the 'prefetch' class method on providers now accepts the list of resources for prefetching. This again reduces reliance on global state, and makes the execution path much easier to follow. git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2551 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/provider.rb')
-rw-r--r--lib/puppet/provider.rb38
1 files changed, 31 insertions, 7 deletions
diff --git a/lib/puppet/provider.rb b/lib/puppet/provider.rb
index 1f18ae730..a725611d0 100644
--- a/lib/puppet/provider.rb
+++ b/lib/puppet/provider.rb
@@ -109,6 +109,12 @@ class Puppet::Provider
end
end
+ # The method for returning a list of provider instances. Note that it returns providers, preferably with values already
+ # filled in, not resources.
+ def self.instances
+ raise Puppet::DevError, "Provider %s has not defined the 'instances' class method" % self.name
+ end
+
# Create the methods for a given command.
def self.make_command_methods(name)
# Now define a method for that command
@@ -323,16 +329,34 @@ class Puppet::Provider
self.class.command(name)
end
- def initialize(resource)
- @resource = resource
-
- # LAK 2007-05-09: Keep the model stuff around for backward compatibility
- @model = resource
- @property_hash = {}
+ def initialize(resource = nil)
+ if resource.is_a?(Hash)
+ @property_hash = resource.dup
+ elsif resource
+ @resource = resource if resource
+ # LAK 2007-05-09: Keep the model stuff around for backward compatibility
+ @model = resource
+ @property_hash = {}
+ else
+ @property_hash = {}
+ end
end
def name
- @resource.name
+ if n = @property_hash[:name]
+ return n
+ elsif self.resource
+ resource.name
+ else
+ raise Puppet::DevError, "No resource and no name in property hash"
+ end
+ end
+
+ # Set passed params as the current values.
+ def set(params)
+ params.each do |param, value|
+ @property_hash[symbolize(param)] = value
+ end
end
def to_s