Created
January 19, 2010 15:40
-
-
Save redivy/281009 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -urN lib/chef/platform.rb lib/chef/platform.rb | |
--- lib/chef/platform.rb 2010-01-19 18:28:41.000000000 +0300 | |
+++ lib/chef/platform.rb 2010-01-19 18:24:31.000000000 +0300 | |
@@ -75,6 +75,13 @@ | |
:cron => Chef::Provider::Cron, | |
} | |
}, | |
+ :suse => { | |
+ :default => { | |
+ :service => Chef::Provider::Service::Redhat, | |
+ :cron => Chef::Provider::Cron, | |
+ :package => Chef::Provider::Package::Zypper | |
+ } | |
+ }, | |
:solaris => {}, | |
:default => { | |
:file => Chef::Provider::File, | |
diff -urN lib/chef/provider/package/zypper.rb lib/chef/provider/package/zypper.rb | |
--- lib/chef/provider/package/zypper.rb 1970-01-01 03:00:00.000000000 +0300 | |
+++ lib/chef/provider/package/zypper.rb 2010-01-19 18:24:31.000000000 +0300 | |
@@ -0,0 +1,88 @@ | |
+# | |
+# Author:: Adam Jacob (<[email protected]>) | |
+# Copyright:: Copyright (c) 2008 Opscode, Inc. | |
+# License:: Apache License, Version 2.0 | |
+# | |
+# Licensed under the Apache License, Version 2.0 (the "License"); | |
+# you may not use this file except in compliance with the License. | |
+# You may obtain a copy of the License at | |
+# | |
+# http://www.apache.org/licenses/LICENSE-2.0 | |
+# | |
+# Unless required by applicable law or agreed to in writing, software | |
+# distributed under the License is distributed on an "AS IS" BASIS, | |
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
+# See the License for the specific language governing permissions and | |
+# limitations under the License. | |
+# | |
+ | |
+require 'chef/provider/package' | |
+require 'chef/mixin/command' | |
+require 'chef/resource/package' | |
+ | |
+class Chef | |
+ class Provider | |
+ class Package | |
+ class Zypper < Chef::Provider::Package | |
+ | |
+ def load_current_resource | |
+ @current_resource = Chef::Resource::Package.new(@new_resource.name) | |
+ @current_resource.package_name(@new_resource.package_name) | |
+ @candidate_version = nil | |
+ | |
+ Chef::Log.debug("Checking zypper info for #{@new_resource.package_name}") | |
+ status = popen4("zypper info #{@new_resource.package_name}") do |pid, stdin, stdout, stderr| | |
+ stdout.each do |line| | |
+ case line | |
+ when /^Version: (.+)$/ | |
+ @candidate_version = $1 | |
+ when /^Installed: (.+)$/ | |
+ if $1 == 'No' | |
+ Chef::Log.debug("Current version is nil") | |
+ @current_resource.version(nil) | |
+ else | |
+ Chef::Log.debug("Current version is #{@candidate_version}") | |
+ @current_resource.version(@candidate_version) | |
+ end | |
+ end | |
+ end | |
+ end | |
+ | |
+ unless status.exitstatus == 0 | |
+ raise Chef::Exceptions::Package, "zypper info failed - #{status.inspect}!" | |
+ end | |
+ | |
+ if @candidate_version.nil? | |
+ raise Chef::Exceptions::Package, "zypper does not have a version of package #{@new_resource.package_name}" | |
+ end | |
+ | |
+ @current_resource | |
+ end | |
+ | |
+ def install_package(name, version) | |
+ run_command_with_systems_locale( | |
+ :command => "zypper -q -n #{expand_options(@new_resource.options)} install -y #{name}=#{version}" | |
+ ) | |
+ end | |
+ | |
+ def upgrade_package(name, version) | |
+ install_package(name, version) | |
+ run_command_with_systems_locale( | |
+ :command => "zypper -q -n #{expand_options(@new_resource.options)} update -y #{@new_resource.package_name}" | |
+ ) | |
+ end | |
+ | |
+ def remove_package(name, version) | |
+ run_command_with_systems_locale( | |
+ :command => "zypper -q -n #{expand_options(@new_resource.options)} remove -y #{@new_resource.package_name}" | |
+ ) | |
+ end | |
+ | |
+ def purge_package(name, version) | |
+ remove_package(name, version) | |
+ end | |
+ | |
+ end | |
+ end | |
+ end | |
+end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment