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

#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, #initialize, #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, #initialize, #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

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

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



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/chef/provider/package/zypper.rb', line 87

def install_package(name, version)
  if zypper_version < 1.0
    run_command(
      :command => "zypper install -y #{name}"
    )
  elsif version
    run_command(
      :command => "zypper -n --no-gpg-checks install -l  #{name}=#{version}"
    )
  else
    run_command(
      :command => "zypper -n --no-gpg-checks install -l  #{name}"
    )
  end
end

#load_current_resourceObject



30
31
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
# File 'lib/chef/provider/package/zypper.rb', line 30

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 = popen4("zypper info #{@new_resource.package_name}") do |pid, stdin, stdout, stderr|
    stdout.each 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
  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



137
138
139
# File 'lib/chef/provider/package/zypper.rb', line 137

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

#remove_package(name, version) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/chef/provider/package/zypper.rb', line 119

def remove_package(name, version)
  if zypper_version < 1.0
    run_command(
      :command => "zypper remove -y #{name}"
    )
  elsif version
    run_command(
      :command => "zypper -n --no-gpg-checks remove  #{name}=#{version}"
    )
  else
    run_command(
      :command => "zypper -n --no-gpg-checks remove  #{name}"
    )
  end
    
 
end

#upgrade_package(name, version) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/chef/provider/package/zypper.rb', line 103

def upgrade_package(name, version)
  if zypper_version < 1.0
    run_command(
      :command => "zypper install -y #{name}"
    )
  elsif version
    run_command(
      :command => "zypper -n --no-gpg-checks install -l #{name}=#{version}"
    )
  else
    run_command(
      :command => "zypper -n --no-gpg-checks install -l #{name}"
    )
  end
end

#zypper_versionObject

Gets the zypper Version from command output (Returns Floating Point number)



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