Last active
August 29, 2015 14:18
-
-
Save raphink/6428d9f53c167eefef68 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Puppet::Type.type(:foo).provide(:olc) do | |
mk_resource_methods | |
def self.instances | |
['a', 'b', 'c'].map do |i| | |
new ({ | |
:ensure => :present, | |
:name => "bar#{i}", | |
}) | |
end | |
end | |
def self.prefetch(resources) | |
# prefetch from instances | |
existing = instances | |
resources.keys.each do |name| | |
if provider = existing.find { |r| r.name == name } | |
# this is used to generate @property_hash so we know if there is a need to create resources | |
resources[name].provider = provider | |
end | |
end | |
# Instantiate @modified, no resources are planned to be modified | |
@modified = false | |
# Get the names of all resources, existing or in the catalog | |
@all_names = (existing.map { |r| r.name } + resources.keys).uniq | |
end | |
def self.post_resource_eval | |
# If any resource needed to be created | |
if @modified | |
# Here you can call slaptest() to create all the resources using @all_names | |
p @all_names | |
end | |
end | |
# This class method updates @modified | |
def self.modified! | |
@modified = true | |
end | |
def exists? | |
# A resource exists if it was found in instances | |
@property_hash[:ensure] == :present | |
end | |
def create | |
# We don't do anything here, we just indicate that resources need to be modified | |
self.class.modified! | |
end | |
def destroy | |
# How do we destroy? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment