Class: Chef::Provider::Package::Zypper

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

Constant Summary

Constants included from Mixin::ShellOut

Mixin::ShellOut::DEPRECATED_OPTIONS

Instance Attribute Summary

Attributes inherited from Chef::Provider::Package

#candidate_version

Attributes inherited from Chef::Provider

#action, #cookbook_name, #current_resource, #new_resource, #recipe_name, #run_context

Instance Method Summary collapse

Methods inherited from Chef::Provider::Package

#action_install, #action_purge, #action_reconfig, #action_remove, #action_upgrade, #as_array, #define_resource_requirements, #expand_options, #get_preseed_file, #have_any_matching_version?, #initialize, #preseed_package, #preseed_resource, #reconfig_package, #removing_package?, #target_version_already_installed?, #whyrun_supported?

Methods included from Mixin::ShellOut

#run_command_compatible_options, #shell_out, #shell_out!, #shell_out_with_systems_locale, #shell_out_with_systems_locale!

Methods included from Mixin::Command

#chdir_or_tmpdir, #handle_command_failures, #output_of_command, #run_command, #run_command_and_return_stdout_stderr, #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, #cleanup_after_converge, #converge_by, #define_resource_requirements, #events, #initialize, #node, node_map, #process_resource_requirements, provides, provides?, #requirements, #resource_collection, #resource_updated?, #run_action, #set_updated_status, supports?, #whyrun_mode?, #whyrun_supported?

Methods included from Mixin::DescendantsTracker

#descendants, descendants, direct_descendants, #direct_descendants, find_descendants_by_name, #find_descendants_by_name, #inherited, store_inherited

Constructor Details

This class inherits a constructor from Chef::Provider::Package

Instance Method Details

#install_package(name, version) ⇒ Object



87
88
89
# File 'lib/chef/provider/package/zypper.rb', line 87

def install_package(name, version)
  zypper_package("install --auto-agree-with-licenses", name, version)
end

#load_current_resourceObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/chef/provider/package/zypper.rb', line 32

def load_current_resource
  @current_resource = Chef::Resource::Package.new(@new_resource.name)
  @current_resource.package_name(@new_resource.package_name)

  is_installed=false
  is_out_of_date=false
  version=''
  oud_version=''
  Chef::Log.debug("#{@new_resource} checking zypper")
  status = shell_out("zypper --non-interactive info #{@new_resource.package_name}")
  status.stdout.each_line do |line|
    case line
    when /^Version: (.+)$/
      version = $1
      Chef::Log.debug("#{@new_resource} version #{$1}")
    when /^Installed: Yes$/
      is_installed=true
      Chef::Log.debug("#{@new_resource} is installed")

    when /^Installed: No$/
      is_installed=false
      Chef::Log.debug("#{@new_resource} is not installed")
    when /^Status: out-of-date \(version (.+) installed\)$/
      is_out_of_date=true
      oud_version=$1
      Chef::Log.debug("#{@new_resource} out of date version #{$1}")
    end
  end

  if is_installed==false
    @candidate_version=version
    @current_resource.version(nil)
  end

  if is_installed==true
    if is_out_of_date==true
      @current_resource.version(oud_version)
      @candidate_version=version
    else
      @current_resource.version(version)
      @candidate_version=version
    end
  end

  unless status.exitstatus == 0
    raise Chef::Exceptions::Package, "zypper failed - #{status.inspect}!"
  end

  @current_resource
end

#purge_package(name, version) ⇒ Object



99
100
101
# File 'lib/chef/provider/package/zypper.rb', line 99

def purge_package(name, version)
  zypper_package("remove --clean-deps", name, version)
end

#remove_package(name, version) ⇒ Object



95
96
97
# File 'lib/chef/provider/package/zypper.rb', line 95

def remove_package(name, version)
  zypper_package("remove", name, version)
end

#upgrade_package(name, version) ⇒ Object



91
92
93
# File 'lib/chef/provider/package/zypper.rb', line 91

def upgrade_package(name, version)
  install_package(name, version)
end

#zypper_versionObject



83
84
85
# File 'lib/chef/provider/package/zypper.rb', line 83

def zypper_version()
  `zypper -V 2>&1`.scan(/\d+/).join(".").to_f
end