Class: Chef::Provider::Package::Yum
- Inherits:
-
Chef::Provider::Package
- Object
- Chef::Provider
- Chef::Provider::Package
- Chef::Provider::Package::Yum
- Defined in:
- lib/chef/provider/package/yum.rb
Defined Under Namespace
Classes: YumCache
Instance Attribute Summary
Attributes inherited from Chef::Provider::Package
Attributes inherited from Chef::Provider
#current_resource, #new_resource, #node
Instance Method Summary collapse
-
#initialize(node, new_resource, collection = nil, definitions = nil, cookbook_loader = nil) ⇒ Yum
constructor
A new instance of Yum.
- #install_package(name, version) ⇒ Object
- #load_current_resource ⇒ Object
- #purge_package(name, version) ⇒ Object
- #remove_package(name, version) ⇒ Object
- #upgrade_package(name, version) ⇒ Object
Methods inherited from Chef::Provider::Package
#action_install, #action_purge, #action_remove, #action_upgrade, #expand_options, #get_preseed_file, #preseed_package, #should_remove_package
Methods included from Mixin::Command
chdir_or_tmpdir, handle_command_failures, not_if, only_if, output_of_command, popen4, run_command, run_command_with_systems_locale
Methods inherited from Chef::Provider
#action_nothing, build_from_file
Methods included from Mixin::ConvertToClassName
#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename
Methods included from Mixin::RecipeDefinitionDSLCore
Methods included from Mixin::Language
#data_bag, #data_bag_item, #platform?, #search, #value_for_platform
Constructor Details
#initialize(node, new_resource, collection = nil, definitions = nil, cookbook_loader = nil) ⇒ Yum
Returns a new instance of Yum.
109 110 111 112 |
# File 'lib/chef/provider/package/yum.rb', line 109 def initialize(node, new_resource, collection=nil, definitions=nil, cookbook_loader=nil) @yum = YumCache.instance super(node, new_resource, collection, definitions, cookbook_loader) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Chef::Mixin::RecipeDefinitionDSLCore
Instance Method Details
#install_package(name, version) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/chef/provider/package/yum.rb', line 152 def install_package(name, version) if @new_resource.source run_command_with_systems_locale( :command => "yum -d0 -e0 -y localinstall #{@new_resource.source}" ) else run_command_with_systems_locale( :command => "yum -d0 -e0 -y install #{name}-#{version}" ) end @yum.flush end |
#load_current_resource ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/chef/provider/package/yum.rb', line 114 def load_current_resource @current_resource = Chef::Resource::Package.new(@new_resource.name) @current_resource.package_name(@new_resource.package_name) if @new_resource.source unless ::File.exists?(@new_resource.source) raise Chef::Exceptions::Package, "Package #{@new_resource.name} not found: #{@new_resource.source}" end Chef::Log.debug("Checking rpm status for #{@new_resource.package_name}") status = popen4("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' #{@new_resource.source}") do |pid, stdin, stdout, stderr| stdout.each do |line| case line when /([\w\d_.-]+)\s([\w\d_.-]+)/ @current_resource.package_name($1) @new_resource.version($2) end end end end Chef::Log.debug("Checking yum info for #{@new_resource.package_name}") @yum.refresh installed_version = @yum.installed_version(@new_resource.package_name) @candidate_version = @yum.candidate_version(@new_resource.package_name) @current_resource.version(installed_version) if candidate_version @candidate_version = candidate_version else @candidate_version = installed_version end @current_resource end |
#purge_package(name, version) ⇒ Object
192 193 194 |
# File 'lib/chef/provider/package/yum.rb', line 192 def purge_package(name, version) remove_package(name, version) end |
#remove_package(name, version) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/chef/provider/package/yum.rb', line 178 def remove_package(name, version) if version run_command_with_systems_locale( :command => "yum -d0 -e0 -y remove #{name}-#{version}" ) else run_command_with_systems_locale( :command => "yum -d0 -e0 -y remove #{name}" ) end @yum.flush end |
#upgrade_package(name, version) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/chef/provider/package/yum.rb', line 165 def upgrade_package(name, version) # If we're not given a version, running update is the correct # option. If we are, then running install_package is right. unless version run_command_with_systems_locale( :command => "yum -d0 -e0 -y update #{name}" ) @yum.flush else install_package(name, version) end end |