chef 0.7.10
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of chef might be problematic. Click here for more details.
- data/LICENSE +201 -0
- data/README.rdoc +135 -0
- data/bin/chef-client +26 -0
- data/bin/chef-solo +26 -0
- data/lib/chef.rb +49 -0
- data/lib/chef/application.rb +98 -0
- data/lib/chef/application/agent.rb +18 -0
- data/lib/chef/application/client.rb +209 -0
- data/lib/chef/application/indexer.rb +141 -0
- data/lib/chef/application/server.rb +18 -0
- data/lib/chef/application/solo.rb +214 -0
- data/lib/chef/client.rb +396 -0
- data/lib/chef/compile.rb +138 -0
- data/lib/chef/config.rb +141 -0
- data/lib/chef/cookbook.rb +144 -0
- data/lib/chef/cookbook/metadata.rb +407 -0
- data/lib/chef/cookbook/metadata/version.rb +87 -0
- data/lib/chef/cookbook_loader.rb +168 -0
- data/lib/chef/couchdb.rb +172 -0
- data/lib/chef/daemon.rb +170 -0
- data/lib/chef/exceptions.rb +36 -0
- data/lib/chef/file_cache.rb +205 -0
- data/lib/chef/log.rb +39 -0
- data/lib/chef/mixin/check_helper.rb +31 -0
- data/lib/chef/mixin/checksum.rb +37 -0
- data/lib/chef/mixin/command.rb +351 -0
- data/lib/chef/mixin/create_path.rb +56 -0
- data/lib/chef/mixin/deep_merge.rb +36 -0
- data/lib/chef/mixin/find_preferred_file.rb +99 -0
- data/lib/chef/mixin/from_file.rb +36 -0
- data/lib/chef/mixin/generate_url.rb +48 -0
- data/lib/chef/mixin/language.rb +79 -0
- data/lib/chef/mixin/params_validate.rb +197 -0
- data/lib/chef/mixin/template.rb +84 -0
- data/lib/chef/node.rb +406 -0
- data/lib/chef/node/attribute.rb +412 -0
- data/lib/chef/openid_registration.rb +181 -0
- data/lib/chef/platform.rb +253 -0
- data/lib/chef/provider.rb +40 -0
- data/lib/chef/provider/cron.rb +137 -0
- data/lib/chef/provider/directory.rb +72 -0
- data/lib/chef/provider/execute.rb +58 -0
- data/lib/chef/provider/file.rb +191 -0
- data/lib/chef/provider/group.rb +120 -0
- data/lib/chef/provider/group/groupadd.rb +92 -0
- data/lib/chef/provider/group/pw.rb +88 -0
- data/lib/chef/provider/http_request.rb +102 -0
- data/lib/chef/provider/ifconfig.rb +131 -0
- data/lib/chef/provider/link.rb +157 -0
- data/lib/chef/provider/mount.rb +121 -0
- data/lib/chef/provider/mount/mount.rb +208 -0
- data/lib/chef/provider/package.rb +160 -0
- data/lib/chef/provider/package/apt.rb +110 -0
- data/lib/chef/provider/package/dpkg.rb +113 -0
- data/lib/chef/provider/package/freebsd.rb +153 -0
- data/lib/chef/provider/package/macports.rb +105 -0
- data/lib/chef/provider/package/portage.rb +124 -0
- data/lib/chef/provider/package/rpm.rb +99 -0
- data/lib/chef/provider/package/rubygems.rb +130 -0
- data/lib/chef/provider/package/yum-dump.py +104 -0
- data/lib/chef/provider/package/yum.rb +175 -0
- data/lib/chef/provider/remote_directory.rb +126 -0
- data/lib/chef/provider/remote_file.rb +134 -0
- data/lib/chef/provider/route.rb +118 -0
- data/lib/chef/provider/ruby_block.rb +15 -0
- data/lib/chef/provider/script.rb +42 -0
- data/lib/chef/provider/service.rb +129 -0
- data/lib/chef/provider/service/debian.rb +64 -0
- data/lib/chef/provider/service/freebsd.rb +157 -0
- data/lib/chef/provider/service/gentoo.rb +54 -0
- data/lib/chef/provider/service/init.rb +126 -0
- data/lib/chef/provider/service/redhat.rb +62 -0
- data/lib/chef/provider/template.rb +141 -0
- data/lib/chef/provider/user.rb +170 -0
- data/lib/chef/provider/user/pw.rb +113 -0
- data/lib/chef/provider/user/useradd.rb +107 -0
- data/lib/chef/queue.rb +145 -0
- data/lib/chef/recipe.rb +210 -0
- data/lib/chef/resource.rb +256 -0
- data/lib/chef/resource/apt_package.rb +34 -0
- data/lib/chef/resource/bash.rb +33 -0
- data/lib/chef/resource/cron.rb +143 -0
- data/lib/chef/resource/csh.rb +33 -0
- data/lib/chef/resource/directory.rb +76 -0
- data/lib/chef/resource/dpkg_package.rb +34 -0
- data/lib/chef/resource/execute.rb +127 -0
- data/lib/chef/resource/file.rb +84 -0
- data/lib/chef/resource/gem_package.rb +41 -0
- data/lib/chef/resource/group.rb +68 -0
- data/lib/chef/resource/http_request.rb +52 -0
- data/lib/chef/resource/ifconfig.rb +134 -0
- data/lib/chef/resource/link.rb +78 -0
- data/lib/chef/resource/macports_package.rb +29 -0
- data/lib/chef/resource/mount.rb +135 -0
- data/lib/chef/resource/package.rb +80 -0
- data/lib/chef/resource/perl.rb +33 -0
- data/lib/chef/resource/portage_package.rb +33 -0
- data/lib/chef/resource/python.rb +33 -0
- data/lib/chef/resource/remote_directory.rb +91 -0
- data/lib/chef/resource/remote_file.rb +60 -0
- data/lib/chef/resource/route.rb +135 -0
- data/lib/chef/resource/ruby.rb +33 -0
- data/lib/chef/resource/ruby_block.rb +20 -0
- data/lib/chef/resource/script.rb +51 -0
- data/lib/chef/resource/service.rb +134 -0
- data/lib/chef/resource/template.rb +60 -0
- data/lib/chef/resource/user.rb +98 -0
- data/lib/chef/resource_collection.rb +176 -0
- data/lib/chef/resource_definition.rb +67 -0
- data/lib/chef/rest.rb +238 -0
- data/lib/chef/role.rb +231 -0
- data/lib/chef/run_list.rb +156 -0
- data/lib/chef/runner.rb +123 -0
- data/lib/chef/search.rb +88 -0
- data/lib/chef/search/result.rb +64 -0
- data/lib/chef/search_index.rb +77 -0
- data/lib/chef/tasks/chef_repo.rake +345 -0
- data/lib/chef/util/file_edit.rb +125 -0
- data/lib/chef/util/fileedit.rb +121 -0
- metadata +262 -0
@@ -0,0 +1,121 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Joshua Timberman (<joshua@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2009 Opscode, Inc
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/log'
|
20
|
+
require 'chef/mixin/command'
|
21
|
+
require 'chef/provider'
|
22
|
+
|
23
|
+
class Chef
|
24
|
+
class Provider
|
25
|
+
class Mount < Chef::Provider
|
26
|
+
|
27
|
+
include Chef::Mixin::Command
|
28
|
+
|
29
|
+
def initialize(node, new_resource)
|
30
|
+
super(node, new_resource)
|
31
|
+
end
|
32
|
+
|
33
|
+
def action_mount
|
34
|
+
unless @current_resource.mounted
|
35
|
+
Chef::Log.debug("#{@new_resource}: attempting to mount")
|
36
|
+
status = mount_fs()
|
37
|
+
if status
|
38
|
+
@new_resource.updated = true
|
39
|
+
Chef::Log.info("#{@new_resource}: mounted successfully")
|
40
|
+
end
|
41
|
+
else
|
42
|
+
Chef::Log.debug("#{@new_resource}: not mounting, already mounted")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def action_umount
|
47
|
+
if @current_resource.mounted
|
48
|
+
Chef::Log.debug("#{@new_resource}: attempting to unmount")
|
49
|
+
status = umount_fs()
|
50
|
+
if status
|
51
|
+
@new_resource.updated = true
|
52
|
+
Chef::Log.info("#{@new_resource}: unmounted successfully")
|
53
|
+
end
|
54
|
+
else
|
55
|
+
Chef::Log.debug("#{@new_resource}: not unmounting, already unmounted")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def action_remount
|
60
|
+
unless @new_resource.supports[:remount]
|
61
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :remount"
|
62
|
+
else
|
63
|
+
if @current_resource.mounted
|
64
|
+
Chef::Log.debug("#{@new_resource}: attempting to remount")
|
65
|
+
status = remount_fs()
|
66
|
+
if status
|
67
|
+
@new_resource.updated = true
|
68
|
+
Chef::Log.info("#{@new_resource}: remounted successfully")
|
69
|
+
end
|
70
|
+
else
|
71
|
+
Chef::Log.debug("#{@new_resource}: not mounted, not remounting")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def action_enable
|
77
|
+
unless @current_resource.enabled
|
78
|
+
status = enable_fs
|
79
|
+
if status
|
80
|
+
@new_resource.updated = true
|
81
|
+
Chef::Log.info("#{@new_resource}: enabled successfully")
|
82
|
+
else
|
83
|
+
Chef::Log.debug("#{@new_resource}: not enabling, already enabled")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def action_disable
|
89
|
+
if @current_resource.enabled
|
90
|
+
status = disable_fs
|
91
|
+
if status
|
92
|
+
@new_resource.updated = true
|
93
|
+
Chef::Log.info("#{@new_resource}: disabled successfully")
|
94
|
+
else
|
95
|
+
Chef::Log.debug("#{@new_resource}: not disabling, already disabled")
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def mount_fs
|
101
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :mount"
|
102
|
+
end
|
103
|
+
|
104
|
+
def umount_fs
|
105
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :umount"
|
106
|
+
end
|
107
|
+
|
108
|
+
def remount_fs
|
109
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :remount"
|
110
|
+
end
|
111
|
+
|
112
|
+
def enable_fs
|
113
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :enable"
|
114
|
+
end
|
115
|
+
|
116
|
+
def disable_fs
|
117
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :disable"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,208 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Joshua Timberman (<joshua@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2009 Opscode, Inc
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/provider/mount'
|
20
|
+
require 'chef/log'
|
21
|
+
require 'chef/mixin/command'
|
22
|
+
|
23
|
+
class Chef
|
24
|
+
class Provider
|
25
|
+
class Mount
|
26
|
+
class Mount < Chef::Provider::Mount
|
27
|
+
|
28
|
+
include Chef::Mixin::Command
|
29
|
+
|
30
|
+
def initialize(node, new_resource)
|
31
|
+
super(node, new_resource)
|
32
|
+
@real_device = nil
|
33
|
+
end
|
34
|
+
attr_accessor :real_device
|
35
|
+
|
36
|
+
def load_current_resource
|
37
|
+
@current_resource = Chef::Resource::Mount.new(@new_resource.name)
|
38
|
+
@current_resource.mount_point(@new_resource.mount_point)
|
39
|
+
@current_resource.device(@new_resource.device)
|
40
|
+
Chef::Log.debug("Checking for mount point #{@current_resource.mount_point}")
|
41
|
+
|
42
|
+
# only check for existence of non-remote devices
|
43
|
+
if(@new_resource.device !~ /:/ && !::File.exists?(@new_resource.device) )
|
44
|
+
raise Chef::Exceptions::Mount, "Device #{@new_resource.device} does not exist"
|
45
|
+
elsif( !::File.exists?(@new_resource.mount_point) )
|
46
|
+
raise Chef::Exceptions::Mount, "Mount point #{@new_resource.mount_point} does not exist"
|
47
|
+
end
|
48
|
+
|
49
|
+
# Check to see if the volume is mounted. Last volume entry wins.
|
50
|
+
mounted = false
|
51
|
+
popen4("mount") do |pid, stdin, stdout, stderr|
|
52
|
+
stdout.each do |line|
|
53
|
+
case line
|
54
|
+
when /^#{device_mount_regex}\s+on\s+#{@new_resource.mount_point}/
|
55
|
+
mounted = true
|
56
|
+
Chef::Log.debug("Special device #{device_logstring} mounted as #{@new_resource.mount_point}")
|
57
|
+
when /^([\/\w])+\son\s#{@new_resource.mount_point}\s+/
|
58
|
+
mounted = false
|
59
|
+
Chef::Log.debug("Special device #{$~[1]} mounted as #{@new_resource.mount_point}")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
@current_resource.mounted(mounted)
|
64
|
+
|
65
|
+
# Check to see if there is a entry in /etc/fstab. Last entry for a volume wins.
|
66
|
+
enabled = false
|
67
|
+
::File.read("/etc/fstab").each do |line|
|
68
|
+
case line
|
69
|
+
when /^[#\s]/
|
70
|
+
next
|
71
|
+
when /^#{device_fstab_regex}\s+#{@new_resource.mount_point}/
|
72
|
+
enabled = true
|
73
|
+
Chef::Log.debug("Found mount #{device_fstab} to #{@new_resource.mount_point} in /etc/fstab")
|
74
|
+
when /^[\/\w]+\s+#{@new_resource.mount_point}/
|
75
|
+
enabled = false
|
76
|
+
Chef::Log.debug("Found conflicting mount point #{@new_resource.mount_point} in /etc/fstab")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
@current_resource.enabled(enabled)
|
80
|
+
end
|
81
|
+
|
82
|
+
def mount_fs
|
83
|
+
unless @current_resource.mounted
|
84
|
+
command = "mount -t #{@new_resource.fstype}"
|
85
|
+
command << " -o #{@new_resource.options.join(',')}" unless @new_resource.options.nil? || @new_resource.options.empty?
|
86
|
+
command << " #{device_real}"
|
87
|
+
command << " #{@new_resource.mount_point}"
|
88
|
+
run_command(:command => command)
|
89
|
+
Chef::Log.info("Mounted #{@new_resource.mount_point}")
|
90
|
+
else
|
91
|
+
Chef::Log.debug("#{@new_resource.mount_point} is already mounted.")
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def umount_fs
|
96
|
+
if @current_resource.mounted
|
97
|
+
command = "umount #{@new_resource.mount_point}"
|
98
|
+
run_command(:command => command)
|
99
|
+
Chef::Log.info("Unmounted #{@new_resource.mount_point}")
|
100
|
+
else
|
101
|
+
Chef::Log.debug("#{@new_resource.mount_point} is not mounted.")
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def remount_fs
|
106
|
+
if @current_resource.mounted and @new_resource.supports[:remount]
|
107
|
+
command = "mount -o remount #{@new_resource.mount_point}"
|
108
|
+
run_command(:command => command)
|
109
|
+
|
110
|
+
@new_resource.updated = true
|
111
|
+
Chef::Log.info("Remounted #{@new_resource.mount_point}")
|
112
|
+
elsif @current_resource.mounted
|
113
|
+
umount_fs
|
114
|
+
sleep 1
|
115
|
+
mount_fs
|
116
|
+
else
|
117
|
+
Chef::Log.debug("#{@new_resource.mount_point} is not mounted.")
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def enable_fs
|
122
|
+
unless @current_resource.enabled
|
123
|
+
::File.open("/etc/fstab", "a") do |fstab|
|
124
|
+
fstab.puts("#{device_fstab} #{@new_resource.mount_point} #{@new_resource.fstype} #{@new_resource.options.nil? ? "defaults" : @new_resource.options.join(",")} #{@new_resource.dump} #{@new_resource.pass}")
|
125
|
+
Chef::Log.info("Enabled #{@new_resource.mount_point}")
|
126
|
+
end
|
127
|
+
else
|
128
|
+
Chef::Log.debug("#{@new_resource.mount_point} is already enabled.")
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def disable_fs
|
133
|
+
if @current_resource.enabled
|
134
|
+
contents = []
|
135
|
+
|
136
|
+
found = false
|
137
|
+
::File.readlines("/etc/fstab").reverse_each do |line|
|
138
|
+
if !found && line =~ /^#{device_fstab_regex}\s+#{@new_resource.mount_point}/
|
139
|
+
found = true
|
140
|
+
Chef::Log.debug("Removing #{@new_resource.mount_point} from fstab")
|
141
|
+
next
|
142
|
+
else
|
143
|
+
contents << line
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
::File.open("/etc/fstab", "w") do |fstab|
|
148
|
+
contents.reverse_each { |line| fstab.puts line}
|
149
|
+
end
|
150
|
+
else
|
151
|
+
Chef::Log.debug("#{@new_resource.mount_point} is not enabled")
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
private
|
156
|
+
def device_fstab
|
157
|
+
case @new_resource.device_type
|
158
|
+
when :device
|
159
|
+
@new_resource.device
|
160
|
+
when :label
|
161
|
+
"LABEL=#{@new_resource.device}"
|
162
|
+
when :uuid
|
163
|
+
"UUID=#{@new_resource.device}"
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def device_real
|
168
|
+
if @real_device == nil
|
169
|
+
if @new_resource.device_type == :device
|
170
|
+
@real_device = @new_resource.device
|
171
|
+
else
|
172
|
+
status = popen4("/sbin/findfs #{device_fstab}") do |pid, stdin, stdout, stderr|
|
173
|
+
@real_device = stdout.first.chomp
|
174
|
+
end
|
175
|
+
unless status.exitstatus == 0
|
176
|
+
@real_device = "/dev/null"
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
@real_device
|
181
|
+
end
|
182
|
+
|
183
|
+
def device_logstring
|
184
|
+
case @new_resource.device_type
|
185
|
+
when :device
|
186
|
+
"#{device_real}"
|
187
|
+
when :label
|
188
|
+
"#{device_real} with label #{@new_resource.device}"
|
189
|
+
when :uuid
|
190
|
+
"#{device_real} with uuid #{@new_resource.device}"
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def device_mount_regex
|
195
|
+
::File.symlink?(device_real) ? "(?:#{device_real})|(?:#{::File.readlink(device_real)})" : device_real
|
196
|
+
end
|
197
|
+
|
198
|
+
def device_fstab_regex
|
199
|
+
if @new_resource.device_type == :device
|
200
|
+
device_mount_regex
|
201
|
+
else
|
202
|
+
device_fstab
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/mixin/command'
|
20
|
+
require 'chef/log'
|
21
|
+
require 'chef/file_cache'
|
22
|
+
require 'chef/resource/remote_file'
|
23
|
+
require 'chef/platform'
|
24
|
+
|
25
|
+
class Chef
|
26
|
+
class Provider
|
27
|
+
class Package < Chef::Provider
|
28
|
+
|
29
|
+
include Chef::Mixin::Command
|
30
|
+
|
31
|
+
attr_accessor :candidate_version
|
32
|
+
|
33
|
+
def initialize(node, new_resource)
|
34
|
+
super(node, new_resource)
|
35
|
+
@candidate_version = nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def action_install
|
39
|
+
# If we specified a version, and it's not the current version, move to the specified version
|
40
|
+
if @new_resource.version != nil && @new_resource.version != @current_resource.version
|
41
|
+
install_version = @new_resource.version
|
42
|
+
# If it's not installed at all, install it
|
43
|
+
elsif @current_resource.version == nil
|
44
|
+
install_version = candidate_version
|
45
|
+
else
|
46
|
+
return
|
47
|
+
end
|
48
|
+
|
49
|
+
unless install_version
|
50
|
+
raise(Chef::Exceptions::Package, "No version specified, and no candidate version available!")
|
51
|
+
end
|
52
|
+
|
53
|
+
Chef::Log.info("Installing #{@new_resource} version #{install_version}")
|
54
|
+
|
55
|
+
# We need to make sure we handle the preseed file
|
56
|
+
if @new_resource.response_file
|
57
|
+
preseed_package(@new_resource.package_name, install_version)
|
58
|
+
end
|
59
|
+
|
60
|
+
status = install_package(@new_resource.package_name, install_version)
|
61
|
+
if status
|
62
|
+
@new_resource.updated = true
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def action_upgrade
|
67
|
+
if @current_resource.version != candidate_version
|
68
|
+
orig_version = @current_resource.version || "uninstalled"
|
69
|
+
Chef::Log.info("Upgrading #{@new_resource} version from #{orig_version} to #{candidate_version}")
|
70
|
+
status = upgrade_package(@new_resource.package_name, candidate_version)
|
71
|
+
if status
|
72
|
+
@new_resource.updated = true
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def action_remove
|
78
|
+
if should_remove_package(@current_resource.version, @new_resource.version)
|
79
|
+
Chef::Log.info("Removing #{@new_resource}")
|
80
|
+
remove_package(@current_resource.package_name, @new_resource.version)
|
81
|
+
@new_resource.updated = true
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def should_remove_package(current_version, new_version)
|
86
|
+
to_remove_package = false
|
87
|
+
if current_version != nil
|
88
|
+
if new_version != nil
|
89
|
+
if new_version == current_version
|
90
|
+
to_remove_package = true
|
91
|
+
end
|
92
|
+
else
|
93
|
+
to_remove_package = true
|
94
|
+
end
|
95
|
+
end
|
96
|
+
to_remove_package
|
97
|
+
end
|
98
|
+
|
99
|
+
def action_purge
|
100
|
+
if should_remove_package(@current_resource.version, @new_resource.version)
|
101
|
+
Chef::Log.info("Purging #{@new_resource}")
|
102
|
+
purge_package(@current_resource.package_name, @new_resource.version)
|
103
|
+
@new_resource.updated = true
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def install_package(name, version)
|
108
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :install"
|
109
|
+
end
|
110
|
+
|
111
|
+
def upgrade_package(name, version)
|
112
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :upgrade"
|
113
|
+
end
|
114
|
+
|
115
|
+
def remove_package(name, version)
|
116
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :remove"
|
117
|
+
end
|
118
|
+
|
119
|
+
def purge_package(name, version)
|
120
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :purge"
|
121
|
+
end
|
122
|
+
|
123
|
+
def preseed_package(name, version, preseed)
|
124
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support pre-seeding package install/upgrade instructions - don't ask it to!"
|
125
|
+
end
|
126
|
+
|
127
|
+
def get_preseed_file(name, version)
|
128
|
+
full_cache_dir = Chef::FileCache.create_cache_path("preseed/#{@new_resource.cookbook_name}")
|
129
|
+
full_cache_file = "#{full_cache_dir}/#{name}-#{version}.seed"
|
130
|
+
cache_path = "preseed/#{@new_resource.cookbook_name}/#{name}-#{version}.seed"
|
131
|
+
|
132
|
+
Chef::Log.debug("Fetching preseed file to #{cache_path}")
|
133
|
+
|
134
|
+
remote_file = Chef::Resource::RemoteFile.new(
|
135
|
+
full_cache_file,
|
136
|
+
nil,
|
137
|
+
@node
|
138
|
+
)
|
139
|
+
remote_file.cookbook_name = @new_resource.cookbook_name
|
140
|
+
remote_file.source(@new_resource.response_file)
|
141
|
+
remote_file.backup(false)
|
142
|
+
|
143
|
+
rf_provider = Chef::Platform.provider_for_node(@node, remote_file)
|
144
|
+
rf_provider.load_current_resource
|
145
|
+
rf_provider.action_create
|
146
|
+
|
147
|
+
if remote_file.updated
|
148
|
+
Chef::FileCache.load(cache_path, false)
|
149
|
+
else
|
150
|
+
false
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def expand_options(options)
|
155
|
+
options ? " #{options}" : ""
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|