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

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

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_lock, #action_unlock, #as_array, #check_resource_semantics!, #define_resource_requirements, #expand_options, #get_preseed_file, #have_any_matching_version?, #initialize, #multipackage_api_adapter, #options, #preseed_package, #preseed_resource, #reconfig_package, #removing_package?, #target_version_already_installed?, #version_requirement_satisfied?

Methods included from Mixin::SubclassDirective

#subclass_directive

Methods included from Mixin::ShellOut

#a_to_s, #clean_array, #shell_out, #shell_out!, #shell_out_compact, #shell_out_compact!, #shell_out_compact_timeout, #shell_out_compact_timeout!, #shell_out_with_systems_locale, #shell_out_with_systems_locale!

Methods included from Mixin::PathSanity

#enforce_path_sanity, #sanitized_path

Methods inherited from Chef::Provider

action, #action_nothing, #check_resource_semantics!, #cleanup_after_converge, #compile_and_converge_action, #converge_by, #converge_if_changed, #define_resource_requirements, #events, include_resource_dsl?, include_resource_dsl_module, #initialize, #node, #process_resource_requirements, provides, provides?, #requirements, #resource_collection, #resource_updated?, #run_action, #set_updated_status, supports?, use_inline_resources, #whyrun_mode?, #whyrun_supported?

Methods included from Mixin::Provides

#provided_as, #provides, #provides?

Methods included from Mixin::DescendantsTracker

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

Methods included from Mixin::LazyModuleInclude

#descendants, #include, #included

Methods included from Mixin::NotifyingBlock

#notifying_block, #subcontext_block

Methods included from DSL::DeclareResource

#build_resource, #declare_resource, #delete_resource, #delete_resource!, #edit_resource, #edit_resource!, #find_resource, #find_resource!, #with_run_context

Methods included from Mixin::PowershellOut

#powershell_out, #powershell_out!

Methods included from Mixin::WindowsArchitectureHelper

#assert_valid_windows_architecture!, #disable_wow64_file_redirection, #forced_32bit_override_required?, #is_i386_process_on_x86_64_windows?, #node_supports_windows_architecture?, #node_windows_architecture, #restore_wow64_file_redirection, #valid_windows_architecture?, #with_os_architecture, #wow64_architecture_override_required?, #wow64_directory

Methods included from DSL::PlatformIntrospection

#docker?, #platform?, #platform_family?, #value_for_platform, #value_for_platform_family

Constructor Details

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

Instance Method Details

#get_candidate_versionsObject


66
67
68
69
70
# File 'lib/chef/provider/package/zypper.rb', line 66

def get_candidate_versions
  package_name_array.map do |package_name|
    versions[package_name][:candidate_version]
  end
end

#get_current_versionsObject


72
73
74
75
76
# File 'lib/chef/provider/package/zypper.rb', line 72

def get_current_versions
  package_name_array.map do |package_name|
    versions[package_name][:current_version]
  end
end

#get_versions(package_name) ⇒ Object


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/chef/provider/package/zypper.rb', line 34

def get_versions(package_name)
  candidate_version = current_version = nil
  is_installed = false
  Chef::Log.debug("#{new_resource} checking zypper")
  status = shell_out_compact_timeout!("zypper", "--non-interactive", "info", package_name)
  status.stdout.each_line do |line|
    case line
    when /^Version *: (.+) *$/
      candidate_version = $1.strip
      Chef::Log.debug("#{new_resource} version #{candidate_version}")
    when /^Installed *: Yes *$/
      is_installed = true
      Chef::Log.debug("#{new_resource} is installed")
    when /^Status *: out-of-date \(version (.+) installed\) *$/
      current_version = $1.strip
      Chef::Log.debug("#{new_resource} out of date version #{current_version}")
    end
  end
  current_version = candidate_version if is_installed
  { current_version: current_version, candidate_version: candidate_version }
end

#install_package(name, version) ⇒ Object


105
106
107
# File 'lib/chef/provider/package/zypper.rb', line 105

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

#load_current_resourceObject


90
91
92
93
94
95
96
97
98
# File 'lib/chef/provider/package/zypper.rb', line 90

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

  @candidate_version = get_candidate_versions
  current_resource.version(get_current_versions)

  current_resource
end

#lock_package(name, version) ⇒ Object


122
123
124
# File 'lib/chef/provider/package/zypper.rb', line 122

def lock_package(name, version)
  zypper_package("addlock", name, version)
end

#package_locked(name, version) ⇒ Object


78
79
80
81
82
83
84
85
86
87
88
# File 'lib/chef/provider/package/zypper.rb', line 78

def package_locked(name, version)
  islocked = false
  locked = shell_out_compact_timeout!("zypper", "locks")
  locked.stdout.each_line do |line|
    line_package = line.split("|").shift(2).last.strip
    if line_package == name
      islocked = true
    end
  end
  islocked
end

#purge_package(name, version) ⇒ Object


118
119
120
# File 'lib/chef/provider/package/zypper.rb', line 118

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

#remove_package(name, version) ⇒ Object


114
115
116
# File 'lib/chef/provider/package/zypper.rb', line 114

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

#unlock_package(name, version) ⇒ Object


126
127
128
# File 'lib/chef/provider/package/zypper.rb', line 126

def unlock_package(name, version)
  zypper_package("removelock", name, version)
end

#upgrade_package(name, version) ⇒ Object


109
110
111
112
# File 'lib/chef/provider/package/zypper.rb', line 109

def upgrade_package(name, version)
  # `zypper install` upgrades packages, we rely on the idempotency checks to get action :install behavior
  install_package(name, version)
end

#versionsObject


56
57
58
59
60
61
62
63
64
# File 'lib/chef/provider/package/zypper.rb', line 56

def versions
  @versions ||=
    begin
      raw_versions = package_name_array.map do |package_name|
        get_versions(package_name)
      end
      Hash[*package_name_array.zip(raw_versions).flatten]
    end
end

#zypper_versionObject


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

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