Add a type/provider to handle enman repos

This commit is contained in:
2016-10-08 20:22:10 +01:00
parent 11c2b54be2
commit 7b5f189acf
2 changed files with 71 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
require 'open3'
Puppet::Type.type(:enman_repo).provide(:enman) do
desc "Enman provider for Enman Repositories"
defaultfor :operatingsystem => :sabayon
commands({:enman => "enman"})
mk_resource_methods
def initialize(value={})
super(value)
end
def create
enman("add", resource[:name])
@property_hash[:ensure] = :present
end
def destroy
enman("remove", resource[:name])
@property_hash[:ensure] = :absent
end
def exists?
@property_hash[:ensure] == :present
end
def self.instances
all_installed = enman("list", "--quiet", "--installed").chomp.split
all_available = enman("list", "--quiet", "--available").chomp.split
all_available.collect do |available_repo|
repo = {
:name => available_repo,
:ensure => all_installed.include?(available_repo) ? :present : :absent,
:provider => :enman_repo,
}
Puppet.debug(repo)
new(repo)
end
end
def self.prefetch(resources)
available_repos = self.instances()
resources.each do |name, resource|
if provider = available_repos.find { |r| r.name == name }
resources[name].provider = provider
end
end
end
end
# vim: set ts=2 shiftwidth=2 expandtab :