diff options
author | Brice Figureau <brice-puppet@daysofwonder.com> | 2011-01-03 19:45:51 +0100 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2011-04-08 18:19:53 +1000 |
commit | 596571fd2b03957e7ed185856ee649c1e610716c (patch) | |
tree | bd483ba28d9380d82d1de8c9cb9e5976e5e0aa4a /lib | |
parent | 6560da52674dfce10a622b633a9ed511f75b0a89 (diff) | |
download | puppet-596571fd2b03957e7ed185856ee649c1e610716c.tar.gz puppet-596571fd2b03957e7ed185856ee649c1e610716c.tar.xz puppet-596571fd2b03957e7ed185856ee649c1e610716c.zip |
Base class for network device based providers
This is the common bits of all future network device providers
that are using prefetching/flushing to limit the number of
calls to the remote network device.
The idea is that we need one transaction to prefetch and one
to flush each instance.
Implementors needs to implement lookup which returns a hash
of the found entity, and flush to update the remote device.
Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/provider/network_device.rb | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/puppet/provider/network_device.rb b/lib/puppet/provider/network_device.rb new file mode 100644 index 000000000..58865fddc --- /dev/null +++ b/lib/puppet/provider/network_device.rb @@ -0,0 +1,59 @@ + +# This is the base class of all prefetched network device provider +class Puppet::Provider::NetworkDevice < Puppet::Provider + + def self.lookup(url, name) + raise "This provider doesn't implement the necessary lookup method" + end + + def self.prefetch(resources) + resources.each do |name, resource| + if result = lookup(resource[:device_url], name) + result[:ensure] = :present + resource.provider = new(result) + else + resource.provider = new(:ensure => :absent) + end + end + end + + def exists? + @property_hash[:ensure] != :absent + end + + def initialize(*args) + super + + # Make a duplicate, so that we have a copy for comparison + # at the end. + @properties = @property_hash.dup + end + + def create + @property_hash[:ensure] = :present + self.class.resource_type.validproperties.each do |property| + if val = resource.should(property) + @property_hash[property] = val + end + end + end + + def destroy + @property_hash[:ensure] = :absent + end + + def flush + @property_hash.clear + end + + def self.instances + end + + def former_properties + @properties.dup + end + + def properties + @property_hash.dup + end +end
\ No newline at end of file |