Class: Puppet::Provider::Ipa
- Inherits:
-
Puppet::Provider
- Object
- Puppet::Provider
- Puppet::Provider::Ipa
- Defined in:
- lib/puppet/provider/ipa.rb
Overview
This class is a “base” provider to use to implement your own custom providers here at Encore.
Instance Method Summary collapse
-
#cached_instance ⇒ Object
private methods.
-
#create ⇒ Object
this method is called if exists? returns false and :ensure == :present, so that the resource is created you have two options: 1) implement your “creation” API call here 2) defer the creation to the “flush” method so that “create” and “update” can be handled in the exact same way.
-
#destroy ⇒ Object
this method is called if exists? returns false and :ensure == :absent, so that the resource is deleted 1) implement your “deletion” API call here 2) defer the deletion to the “flush” method so we are consistent with what we’re doing above.
-
#exists? ⇒ Boolean
the exists method should return true if the current named resource exists or not in this method we also get the instance of this resource from the API and save it to our @property_hash, this initializes @property_hash and allows it to be used by the mk_resource_methods getter and setters above.
-
#flush ⇒ Object
the flush method is called at the end of the “transaction” once all setter methods above have been called along with exists? and potentially create or delete.
- #flush_instance ⇒ Object
-
#read_instance ⇒ Object
this method should retrieve an instance and return it as a hash note: we explicitly do NOT cache within this method because we want to be able to call it both in initialize() and in flush() and return the current state of the resource from the API each time.
Instance Method Details
#cached_instance ⇒ Object
private methods
You as an implementer need to define 3x methods below
-
cached_instance : This is just a cache of read_instance, we’ve provided a default
implementation so implementers of sub-classes don't have to worry
-
read_instance : this should return a hash that has the same properties (as symbols)
and values of what the resource currently looks like
-
flush_instance : this should read from resource and either create/update or
delete the instance based on the value of @property_hash[:ensure]
86 87 88 |
# File 'lib/puppet/provider/ipa.rb', line 86 def cached_instance @cached_instance ||= read_instance end |
#create ⇒ Object
this method is called if exists? returns false and :ensure == :present,
so that the resource is created
you have two options: 1) implement your “creation” API call here 2) defer the creation to the “flush” method so that “create” and “update” can be
handled in the exact same way
44 45 46 |
# File 'lib/puppet/provider/ipa.rb', line 44 def create @property_hash[:ensure] = :present end |
#destroy ⇒ Object
this method is called if exists? returns false and :ensure == :absent,
so that the resource is deleted
1) implement your “deletion” API call here 2) defer the deletion to the “flush” method so we are consistent with what
we're doing above
53 54 55 |
# File 'lib/puppet/provider/ipa.rb', line 53 def destroy @property_hash[:ensure] = :absent end |
#exists? ⇒ Boolean
the exists method should return true if the current named resource exists or not in this method we also get the instance of this resource from the API and save it to our @property_hash, this initializes @property_hash and allows it to be used by the mk_resource_methods getter and setters above.
32 33 34 35 36 |
# File 'lib/puppet/provider/ipa.rb', line 32 def exists? # use cloned cached_instance here so we can compare before/after in flush() if needed @property_hash = cached_instance.clone @property_hash[:ensure] == :present end |
#flush ⇒ Object
the flush method is called at the end of the “transaction” once all setter methods above have been called along with exists? and potentially create or delete. this method should take all changes that need to happen to this resource and make the necessary API calls to make them happen. In our case we’re going to do one “bulk” API call for all of our properties to either create or update the user. If the resource was requested to be destroyed we will delete the resource using the API.
This allows us to be super efficiently and basically make one “write” call for each resource instance.
68 69 70 71 72 73 74 |
# File 'lib/puppet/provider/ipa.rb', line 68 def flush flush_instance # Collect the resources again once they've been changed (that way `puppet # resource` will show the correct values after changes have been made). @property_hash = read_instance end |
#flush_instance ⇒ Object
this method should check resource
if it is :present this method should create/update the instance using the values
in resource[:xxx] (these are the desired state values)
else if it is :absent this method should delete the instance
if you want to have access to the values before they were changed you can use
cached_instance[:xxx] to compare against (that's why it exists)
105 106 107 |
# File 'lib/puppet/provider/ipa.rb', line 105 def flush_instance raise NotImplementedError, 'flush_instance needs to be implemented by child providers' end |
#read_instance ⇒ Object
this method should retrieve an instance and return it as a hash note: we explicitly do NOT cache within this method because we want to be
able to call it both in initialize() and in flush() and return the current
state of the resource from the API each time
94 95 96 |
# File 'lib/puppet/provider/ipa.rb', line 94 def read_instance raise NotImplementedError, 'read_instance needs to be implemented by child providers' end |