Class: Chef::Provider::Package::Yum

Inherits:
Chef::Provider::Package show all
Defined in:
lib/chef/provider/package/yum.rb

Defined Under Namespace

Classes: YumCache

Instance Attribute Summary

Attributes inherited from Chef::Provider::Package

#candidate_version

Attributes inherited from Chef::Provider

#current_resource, #new_resource, #run_context

Instance Method Summary collapse

Methods inherited from Chef::Provider::Package

#action_install, #action_purge, #action_remove, #action_upgrade, #expand_options, #get_preseed_file, #preseed_package, #preseed_resource, #removing_package?

Methods included from Mixin::Command

#chdir_or_tmpdir, #handle_command_failures, #not_if, #only_if, #output_of_command, #run_command, #run_command_with_systems_locale

Methods included from Mixin::Command::Windows

#popen4

Methods included from Mixin::Command::Unix

#popen4

Methods inherited from Chef::Provider

#action_nothing, build_from_file, #cookbook_name, #node, #resource_collection

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

#method_missing

Methods included from Mixin::Language

#data_bag, #data_bag_item, #platform?, #search, #value_for_platform

Constructor Details

#initialize(new_resource, run_context) ⇒ Yum

Returns a new instance of Yum.



120
121
122
123
# File 'lib/chef/provider/package/yum.rb', line 120

def initialize(new_resource, run_context)
  super
  @yum = YumCache.instance
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Chef::Mixin::RecipeDefinitionDSLCore

Instance Method Details

#archObject



125
126
127
128
129
130
131
# File 'lib/chef/provider/package/yum.rb', line 125

def arch
  if @new_resource.respond_to?("arch")
    @new_resource.arch 
  else
    nil
  end
end

#install_package(name, version) ⇒ Object



175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/chef/provider/package/yum.rb', line 175

def install_package(name, version)
  if @new_resource.source 
    run_command_with_systems_locale(
      :command => "yum -d0 -e0 -y #{@new_resource.options} localinstall #{@new_resource.source}"
    )
  else
    run_command_with_systems_locale(
      :command => "yum -d0 -e0 -y #{@new_resource.options} install #{name}-#{version}#{yum_arch}"
    )
  end
  @yum.flush
end

#load_current_resourceObject



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/chef/provider/package/yum.rb', line 137

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_arch}")

  @yum.refresh

  installed_version = @yum.installed_version(@new_resource.package_name, arch)
  @candidate_version = @yum.candidate_version(@new_resource.package_name, arch)

  @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



215
216
217
# File 'lib/chef/provider/package/yum.rb', line 215

def purge_package(name, version)
  remove_package(name, version)
end

#remove_package(name, version) ⇒ Object



201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/chef/provider/package/yum.rb', line 201

def remove_package(name, version)
  if version
    run_command_with_systems_locale(
     :command => "yum -d0 -e0 -y #{@new_resource.options} remove #{name}-#{version}#{yum_arch}"
    )
  else
    run_command_with_systems_locale(
     :command => "yum -d0 -e0 -y #{@new_resource.options} remove #{name}#{yum_arch}"
    )
  end
    
  @yum.flush
end

#upgrade_package(name, version) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/chef/provider/package/yum.rb', line 188

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 #{@new_resource.options} update #{name}#{yum_arch}"
    )   
    @yum.flush
  else
    install_package(name, version)
  end
end

#yum_archObject



133
134
135
# File 'lib/chef/provider/package/yum.rb', line 133

def yum_arch
  arch ? ".#{arch}" : nil
end