diff options
author | Martin Englund <martin.englund@sun.com> | 2009-10-07 15:06:45 +0100 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2010-01-27 18:41:28 +1100 |
commit | fcce2222b385e11992406bb4313676ba080c7ea8 (patch) | |
tree | bf2c8f10634d1124d8b8461b998adbdf2e331988 /lib/puppet | |
parent | 3e9677f00a09d0249713ed2fa503e42b07f6d978 (diff) | |
download | puppet-fcce2222b385e11992406bb4313676ba080c7ea8.tar.gz puppet-fcce2222b385e11992406bb4313676ba080c7ea8.tar.xz puppet-fcce2222b385e11992406bb4313676ba080c7ea8.zip |
First shot at the OpenSolaris pkg(5) provider
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/provider/package/pkg.rb | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/lib/puppet/provider/package/pkg.rb b/lib/puppet/provider/package/pkg.rb new file mode 100644 index 000000000..978042d42 --- /dev/null +++ b/lib/puppet/provider/package/pkg.rb @@ -0,0 +1,114 @@ +require 'puppet/provider/package' + +Puppet::Type.type(:package).provide :pkg, :parent => Puppet::Provider::Package do + desc "OpenSolaris image packaging system. See pkg(5) for more information" + + commands :pkg => "/usr/bin/pkg" + + confine :operatingsystem => :solaris + + #defaultfor [:operatingsystem => :solaris, :kernelrelease => "5.11"] + + def self.instances + packages = [] + + cmd = "#{command(:pkg)} list -H" + execpipe(cmd) do |process| + hash = {} + + # now turn each returned line into a package object + process.each { |line| + if hash = parse_line(line) + packages << new(hash) + end + } + end + + packages + end + + REGEX = %r{^(\S+)\s+(\S+)\s+(\S+)\s+} + FIELDS = [:name, :version, :status] + + def self.parse_line(line) + hash = {} + if match = REGEX.match(line) + + FIELDS.zip(match.captures) { |field,value| + hash[field] = value + } + + hash[:provider] = self.name + hash[:error] = "ok" + + if hash[:status] == "installed" + hash[:ensure] = :present + else + hash[:ensure] = :absent + end + else + Puppet.warning "Failed to match 'pkg list' line %s" % line.inspect + return nil + end + + return hash + end + + # return the version of the package + # TODO deal with multiple publishers + def latest + version = nil + pkg(:list, "-Ha", @resource[:name]).split("\n").each do |line| + v = line.split[2] + case v + when "known" + return v + when "installed" + version = v + else + Puppet.warn "unknown package state for %s: %s" % + [@resource[:name], v] + end + end + version + end + + # install the package + def install + pkg :install, @resource[:name] + end + + # uninstall the package + def uninstall + pkg :uninstall, '-r', @resource[:name] + end + + # update the package to the latest version available + def update + self.install + end + + # list a specific package + def query + begin + output = pkg(:list, "-H", @resource[:name]) + rescue Puppet::ExecutionFailure + # pkg returns 1 if the package is not found. + return {:ensure => :absent, :status => 'missing', + :name => @resource[:name], :error => 'ok'} + end + + hash = self.class.parse_line(output) || + {:ensure => :absent, :status => 'missing', + :name => @resource[:name], :error => 'ok'} + + if hash[:error] != "ok" + raise Puppet::Error.new( + "Package %s, version %s is in error state: %s" % + [hash[:name], hash[:version], hash[:error]]) + end + + return hash + end + +end |