Class: Puppet::Package
- Inherits:
-
Object
- Object
- Puppet::Package
- Extended by:
- Indirector
- Defined in:
- lib/puppet/package.rb
Class Method Summary collapse
- .[](name) ⇒ Object
- .add_update_options(action) ⇒ Object
-
.apply_updates(packages) ⇒ Object
Takes a hash in the form package_name = { :update => <update_version> :provider => <provider> }.
- .find_updates ⇒ Object
- .system_packages ⇒ Object
- .update_package(package, options) ⇒ Object
Class Method Details
.[](name) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/puppet/package.rb', line 11 def self.[](name) system_packages.each do |package| if package.name == name return package end end end |
.add_update_options(action) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/puppet/package.rb', line 19 def self.(action) action.option '--level=', '-l=' do summary "The version level to patch to. Default is latest" end action.option '--provider=', '-p=' do summary "The provider for the package. Defaults to system default provider" end end |
.apply_updates(packages) ⇒ Object
Takes a hash in the form
package_name = {
:update => <update_version>
:provider => <provider>
}
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/puppet/package.rb', line 41 def self.apply_updates(packages) packages.each do |name, package| unless system_packages.map{ |p| p.name }.include? name raise "#{name} is not installed on the system" end package_resource = Puppet::Resource.new( :package, "Package[#{name}]", :parameters => {:ensure => package[:update], :provider => package[:provider]} ) #Apply the update begin Puppet::Face[:resource,'0.0.1'].save package_resource rescue => e raise "Could not update \033[31m#{name}\033[0m: #{e}" end end end |
.find_updates ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/puppet/package.rb', line 73 def self.find_updates packages = system_packages package_updates = Hash.new prefetch_updates(packages) packages.each do |p| provider = String(p[:provider]) unless package_updates[provider] package_updates[provider] = Hash.new end # Some providers can't determine latest versions next unless p.provider.class.method_defined?(:latest) # Need to access with Array because sometimes puppet hands back # strings, sometimes it hands back arrays containing a string. Oy. # Using confusing [*] syntax for speed. latest = [*p.provider.latest][0] current = [*p.provider.properties[:ensure]][0] # filter out packages that apt reports as "installed" but not "purged" # as well as packages with no upgrade next unless latest && (current != "absent") if latest != current package_updates[p.title] = { 'current' => current, 'update' => latest, 'provider' => String(p[:provider]) } end end {'package_updates' => package_updates } end |
.system_packages ⇒ Object
29 30 31 32 33 |
# File 'lib/puppet/package.rb', line 29 def self.system_packages #Can't use Puppet::Resource face here #Since it doesn't return package objects Puppet::Type.type(:package).instances end |
.update_package(package, options) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/puppet/package.rb', line 60 def self.update_package(package, ) #The other methods expect the package name to be in the following format level = .has_key?(:level) ? [:level] : :latest provider = .has_key?(:provider) ? [:provider] : Puppet::Type.type(:package).defaultprovider.name #unless system_packages.map{ |p| p.name }.include? package #raise ArgumentError, "#{package} is not installed on the system" #end #Perform the update apply_updates package => { :update => level, :provider => provider } end |