[PATCH/puppet 1/1] Fixed #2805 - Added support for AIX package management

3 views
Skip to first unread message

James Turnbull

unread,
Nov 14, 2009, 7:55:39 AM11/14/09
to puppe...@googlegroups.com

Signed-off-by: James Turnbull <ja...@lovedthanlost.net>
---
lib/puppet/provider/package/aix.rb | 110 ++++++++++++++++++++++++++++++++++++
lib/puppet/provider/package/nim.rb | 53 +++++++++++++++++
2 files changed, 163 insertions(+), 0 deletions(-)
create mode 100644 lib/puppet/provider/package/aix.rb
create mode 100644 lib/puppet/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
--
1.6.0.6

Luke Kanies

unread,
Nov 16, 2009, 10:29:35 AM11/16/09
to puppe...@googlegroups.com
+1 other than the lack of tests.

Who do we need to work with to get the tests written?
--
I take my children everywhere, but they always find their way
back home. --Robert Orben
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com

James Turnbull

unread,
Nov 16, 2009, 3:43:24 PM11/16/09
to puppe...@googlegroups.com, andrew...@gmail.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Luke Kanies wrote:
> +1 other than the lack of tests.
>
> Who do we need to work with to get the tests written?
>

I've cc'ed in the patch's originator - Andrew.

Regards

James Turnbull

- --
Author of:
* Pro Linux System Administration (http://tinyurl.com/linuxadmin)
* Pulling Strings with Puppet (http://tinyurl.com/pupbook)
* Pro Nagios 2.0 (http://tinyurl.com/pronagios)
* Hardening Linux (http://tinyurl.com/hardeninglinux)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEVAwUBSwG5bCFa/lDkFHAyAQLJAQf+KC6rRJht7k7c2ixwWYwdI3GM6lXtVtcX
gbam2RdihjdYHVXMomuF7suUcZmUAfZgTaTA1541JgmM+8Rqu1Wyo91ek+VTuAD5
J8fK1ZmM69gzLe3Q+9GvLt3SjWWf8p6lZNtOmjUL9S+OqYY+uugbK14baWuKTZQi
fGRZ/XILK9c11eEILuNFykWSpEoREVOvuP7e4clLKSLDsTDoBVWr+YPjqaj1e8gs
mYRnoCnI6FuM3laCyHLG6516N4cWLl1lmVkCjfjxt9hP2MI3xs7n0hWc3CEaf3hK
QLz5TqBpgXzVZRGMiLmdHl929gNItQTxymRZQOIOHQBV1ke3+DL6Tw==
=xrBz
-----END PGP SIGNATURE-----

Andrew Forgue

unread,
Nov 16, 2009, 11:08:31 PM11/16/09
to Puppet Developers
On Nov 16, 3:43 pm, James Turnbull <ja...@lovedthanlost.net> wrote:
> Luke Kanies wrote:
> > +1 other than the lack of tests.
>
> > Who do we need to work with to get the tests written?
>
> I've cc'ed in the patch's originator - Andrew.
>

I'll try to get some tests written for this...

Andrew
Reply all
Reply to author
Forward
0 new messages