1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
# 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 File.join(File.dirname(__FILE__), "..", "mixin", "command")
class Chef
class Provider
class Package < Chef::Provider
include Chef::Mixin::Command
def initialize(node, new_resource)
super(node, new_resource)
@candidate_version = nil
end
def action_install
# First, select what version we should be using
install_version = @new_resource.version
install_version ||= @candidate_version
unless install_version
raise(Chef::Exception::Package, "No version specified, and no candidate version available!")
end
do_package = false
# If it's not installed at all, install it
if @current_resource.version == nil
do_package = true
# If we specified a version, and it's not the current version, move to the current version
elsif @new_resource.version != nil
if @new_resource.version != @current_resource.version
do_package = true
end
end
if do_package
Chef::Log.info("Installing #{@new_resource} version #{install_version} successfully")
status = install_package(@new_resource.package_name, install_version)
if status
@new_resource.updated = true
end
end
end
def action_upgrade
if @current_resource.version != @candidate_version
Chef::Log.info("Upgrading #{@new_resource} version from #{@current_resource.version} to #{@candidate_version} successfully")
status = install_package(@new_resource.package_name, @candidate_version)
if status
@new_resource.updated = true
end
end
end
def action_remove
if @current_resource.version != nil
Chef::Log.info("Removing #{@new_resource} successfully")
remove_package(@new_resource.package_name, @new_resource.version)
@new_resource.updated = true
end
end
def action_purge
if @current_resource.version != nil
Chef::Log.info("Purging #{@new_resource} successfully")
purge_package(@new_resource.package_name, @new_resource.version)
@new_resource.updated = true
end
end
def install_package(name, version)
raise Chef::Exception::UnsupportedAction, "#{self.to_s} does not support :install"
end
def upgrade_package(name, version)
raise Chef::Exception::UnsupportedAction, "#{self.to_s} does not support :upgrade"
end
def remove_package(name, version)
raise Chef::Exception::UnsupportedAction, "#{self.to_s} does not support :remove"
end
def purge_package(name, version)
raise Chef::Exception::UnsupportedAction, "#{self.to_s} does not support :purge"
end
end
end
end
|