Code from Andrew Forgue
Signed-off-by: James Turnbull <
ja...@lovedthanlost.net>
---
lib/puppet/provider/package/aix.rb | 110 ++++++++++++++++++++++++++++++++++++
lib/puppet/provider/package/nim.rb | 53 +++++++++++++++++
spec/unit/provider/package/aix.rb | 48 ++++++++++++++++
spec/unit/provider/package/nim.rb | 33 +++++++++++
4 files changed, 244 insertions(+), 0 deletions(-)
create mode 100644 lib/puppet/provider/package/aix.rb
create mode 100644 lib/puppet/provider/package/nim.rb
create mode 100755 spec/unit/provider/package/aix.rb
create mode 100755 spec/unit/provider/package/nim.rb
diff --git a/lib/puppet/provider/package/aix.rb b/lib/puppet/provider/package/aix.rb
new file mode 100644
index 0000000..580c6c7
--- /dev/null
+++ b/lib/puppet/provider/package/aix.rb
@@ -0,0 +1,110 @@
+require 'puppet/provider/package'
+require 'puppet/util/package'
+
+Puppet::Type.type(:package).provide :aix, :parent => Puppet::Provider::Package do
+ desc "Installation from AIX Software directory"
+
+ # The commands we are using on an AIX box are installed standard
+ # (except nimclient) nimclient needs the bos.sysmgt.nim.client fileset.
+ commands :lslpp => "/usr/bin/lslpp",
+ :installp => "/usr/sbin/installp",
+ :inutoc => "/usr/sbin/inutoc"
+
+ # AIX supports versionable packages with and without a NIM server
+ has_feature :versionable
+
+ confine :operatingsystem => [ :aix ]
+ defaultfor :operatingsystem => :aix
+
+ def uninstall
+ # Automatically process dependencies when installing/uninstalling
+ # with the -g option to installp.
+ installp "-gu", @resource[:name]
+ end
+
+ def install(useversion = true)
+ unless source = @resource[:source]
+ self.fail "A directory is required which will be used to find packages"
+ end
+
+ pkg = @resource[:name]
+
+ if (! @resource.should(:ensure).is_a? Symbol) and useversion
+ pkg << @resource.should(:ensure)
+ end
+
+ # run inutoc to create a table of contents for the installer.
+ inutoc source
+
+ installp "-acgwXY", "-d", source, pkg
+ end
+
+ def self.pkglist(hash = {})
+ cmd = [command(:lslpp), "-qLc"]
+
+ if name = hash[:pkgname]
+ cmd << name
+ end
+
+ begin
+ list = execute(cmd).split("\n").collect do |set|
+ pkg_info = set.split(":")
+ pkg = {}
+ pkg[:name] = pkg_info[1]
+ pkg[:ensure] = pkg_info[2]
+ pkg[:provider] =
self.name
+ pkg
+ end.compact
+ rescue Puppet::ExecutionFailure => detail
+ if hash[:pkgname]
+ return nil
+ else
+ raise Puppet::Error, "Could not list installed Packages: %s" % detail
+ end
+ end
+
+ if hash[:pkgname]
+ return list.shift
+ else
+ return list
+ end
+ end
+
+ def self.instances
+ pkglist.collect do |hash|
+ new(hash)
+ end
+ end
+
+ def latest
+ unless source = @resource[:source]
+ self.fail "A directory is required which will be used to find packages"
+ end
+
+ inutoc source
+ cmd = [ command(:installp), "-L", "-d", source ]
+
+ pkg_latest = "-1"
+ execute(cmd).split("\n").each do |set|
+ pkg_info = set.split(":")
+ if pkg_info[1] == resource[:name]
+ unless Puppet::Util::Package.versioncmp(pkg_latest, pkg_info[2]) == 1
+ pkg_latest = pkg_info[2]
+ end
+ end
+ end
+
+ unless pkg_latest == "-1"
+ return pkg_latest
+ end
+ return nil
+ end
+
+ def query
+ return self.class.pkglist(:pkgname => @resource[:name])
+ end
+
+ def update
+ self.install(false)
+ end
+end
diff --git a/lib/puppet/provider/package/nim.rb b/lib/puppet/provider/package/nim.rb
new file mode 100644
index 0000000..bbeded6
--- /dev/null
+++ b/lib/puppet/provider/package/nim.rb
@@ -0,0 +1,53 @@
+require 'puppet/provider/package'
+require 'puppet/util/package'
+
+Puppet::Type.type(:package).provide :nim, :parent => :aix, :source => :aix do
+ desc "Installation from NIM LPP source"
+
+ # The commands we are using on an AIX box are installed standard
+ # (except nimclient) nimclient needs the bos.sysmgt.nim.client fileset.
+ commands :nimclient => "/usr/sbin/nimclient"
+
+ # If NIM has not been configured, /etc/niminfo will not be present.
+ # However, we have no way of knowing if the NIM server is not configured
+ # properly.
+ confine :exists => "/etc/niminfo"
+
+ def install(useversion = true)
+ unless source = @resource[:source]
+ self.fail "An LPP source location is required in 'source'"
+ end
+
+ pkg = @resource[:name]
+
+ if (! @resource.should(:ensure).is_a? Symbol) and useversion
+ pkg << @resource.should(:ensure)
+ end
+
+ nimclient "-Fo", "reset"
+ nimclient "-o", "cust", "-a", "installp_flags=acgwXY", "-a", "lpp_source=#{source}", "-a", "filesets=#{pkg}"
+ end
+
+ def latest
+ unless source = @resource[:source]
+ self.fail "An LPP source location is required in 'source'"
+ end
+
+ cmd = [ command(:nimclient), "-o", "showres", "-a", "installp_flags=L", "-a", "resource=#{resource[:source]}" ]
+
+ pkg_latest = "-1"
+ execute(cmd).split("\n").each do |set|
+ pkg_info = set.split(":")
+ if pkg_info[1] == resource[:name]
+ unless Puppet::Util::Package.versioncmp(pkg_latest, pkg_info[2]) == 1
+ pkg_latest = pkg_info[2]
+ end
+ end
+ end
+
+ unless pkg_latest == "-1"
+ return pkg_latest
+ end
+ return nil
+ end
+end
diff --git a/spec/unit/provider/package/aix.rb b/spec/unit/provider/package/aix.rb
new file mode 100755
index 0000000..9d5c1f4
--- /dev/null
+++ b/spec/unit/provider/package/aix.rb
@@ -0,0 +1,48 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+provider_class = Puppet::Type.type(:package).provider(:aix)
+
+describe provider_class do
+ before(:each) do
+ # Create a mock resource
+ @resource = stub 'resource'
+
+ # A catch all; no parameters set
+ @resource.stubs(:[]).returns(nil)
+
+ # But set name and source
+ @resource.stubs(:[]).with(:name).returns "mypackage"
+ @resource.stubs(:[]).with(:source).returns "mysource"
+ @resource.stubs(:[]).with(:ensure).returns :installed
+
+ @provider =
provider_class.new
+ @provider.stubs(:resource).returns @resource
+ end
+
+ it "should have an install method" do
+ @provider =
provider_class.new
+ @provider.should respond_to(:install)
+ end
+
+ it "should have an uninstall method" do
+ @provider =
provider_class.new
+ @provider.should respond_to(:uninstall)
+ end
+
+ it "should have an latest method" do
+ @provider =
provider_class.new
+ @provider.should respond_to(:latest)
+ end
+
+ it "should have a query method" do
+ @provider =
provider_class.new
+ @provider.should respond_to(:query)
+ end
+
+ it "should have an update method" do
+ @provider =
provider_class.new
+ @provider.should respond_to(:update)
+ end
+ end
diff --git a/spec/unit/provider/package/nim.rb b/spec/unit/provider/package/nim.rb
new file mode 100755
index 0000000..a3e65b2
--- /dev/null
+++ b/spec/unit/provider/package/nim.rb
@@ -0,0 +1,33 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+provider_class = Puppet::Type.type(:package).provider(:aix)
+
+describe provider_class do
+ before(:each) do
+ # Create a mock resource
+ @resource = stub 'resource'
+
+ # A catch all; no parameters set
+ @resource.stubs(:[]).returns(nil)
+
+ # But set name and source
+ @resource.stubs(:[]).with(:name).returns "mypackage"
+ @resource.stubs(:[]).with(:source).returns "mysource"
+ @resource.stubs(:[]).with(:ensure).returns :installed
+
+ @provider =
provider_class.new
+ @provider.stubs(:resource).returns @resource
+ end
+
+ it "should have an install method" do
+ @provider =
provider_class.new
+ @provider.should respond_to(:install)
+ end
+
+ it "should have a latest method" do
+ @provider =
provider_class.new
+ @provider.should respond_to(:latest)
+ end
+ end
--
1.6.2.5