Hello -dev list, This is my first patch for puppet (\o/). It aims to close the ticket #3304.
Regards, Nico.
From 9a0b4e3daf41dcd08dd2c6034b63534978c70e5b Mon Sep 17 00:00:00 2001 From: Nicolas Szalay <[email protected]> Date: Fri, 26 Mar 2010 10:20:18 +0100 Subject: [PATCH 4838/4838] Added support for the pkgin provider Signed-off-by: Nicolas Szalay <[email protected]> --- lib/puppet/provider/package/pkgin.rb | 76 ++++++++++++++++++++++++++++++++++ 1 files changed, 76 insertions(+), 0 deletions(-) create mode 100644 lib/puppet/provider/package/pkgin.rb diff --git a/lib/puppet/provider/package/pkgin.rb b/lib/puppet/provider/package/pkgin.rb new file mode 100644 index 0000000..159d3cf --- /dev/null +++ b/lib/puppet/provider/package/pkgin.rb @@ -0,0 +1,76 @@ +require 'puppet/provider/package' + +# Puppet provider for iMil's pkgin (binary pkgsrc). Based on openbsd provider +# This is not bug free, feel free to improve +# +# Nicolas Szalay <[email protected]> +# +Puppet::Type.type(:package).provide :pkgin, :parent => Puppet::Provider::Package do + include Puppet::Util::Execution + desc "pkgin provider" + + # add typical pkgsrc dirs to the PATH + ENV["PATH"] = ENV["PATH"]+":/opt/pkg/bin:/usr/pkg/bin/opt/pkg/sbin:/usr/pkg/sbin" + + commands :pkgin => "pkgin" + + def self.instances + packages = [] + regex = %r{(\S+)(-)(.*?)(\s+)(.*)} + # we rely on pkg_info to know which packages are installed + cmd="pkg_info -a" + + begin + Puppet.debug "Running '%s'" % cmd + execpipe(cmd) { |pkglist| + hash={} + pkglist.each { |line| + if (match=regex.match(line)) then + hash[:name]=match[1] + hash[:version]=match[3] + hash[:description]=match[5] + + packages << new(hash) + hash={} + end + } + } + rescue Puppet::ExecutionFailure + return nil + end + + return packages + end + + def install + should = @resource[:ensure] + pkgin ["-y", "in", @resource[:name] ] + end + + def uninstall + pkgin ["-y", "rm", @resource[:name] ] + end + + def query + hash = {} + hash[:ensure] = :absent + regex=%r{(\S+)(-)(.*?)(\s+)(.*)} + + begin + cmd = "pkgin ls" + execpipe(cmd) { |process| + process.each { |line| + if match = regex.match(line) + if match[1] == @resource[:name] + Puppet.debug " %s is present" % @resource[:name] + hash[:ensure] = :present + end + end + } + } + end + + return hash + end + +end -- 1.7.0
signature.asc
Description: Ceci est une partie de message numériquement signée
