garcun 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitattributes +17 -0
- data/.gitignore +197 -0
- data/.rspec +2 -0
- data/Gemfile +22 -0
- data/LICENSE +201 -0
- data/README.md +521 -0
- data/Rakefile +47 -0
- data/garcun.gemspec +83 -0
- data/lib/garcon.rb +290 -0
- data/lib/garcon/chef/chef_helpers.rb +343 -0
- data/lib/garcon/chef/coerce/coercer.rb +134 -0
- data/lib/garcon/chef/coerce/coercions/boolean_definitions.rb +34 -0
- data/lib/garcon/chef/coerce/coercions/date_definitions.rb +32 -0
- data/lib/garcon/chef/coerce/coercions/date_time_definitions.rb +32 -0
- data/lib/garcon/chef/coerce/coercions/fixnum_definitions.rb +34 -0
- data/lib/garcon/chef/coerce/coercions/float_definitions.rb +32 -0
- data/lib/garcon/chef/coerce/coercions/hash_definitions.rb +29 -0
- data/lib/garcon/chef/coerce/coercions/integer_definitions.rb +31 -0
- data/lib/garcon/chef/coerce/coercions/string_definitions.rb +45 -0
- data/lib/garcon/chef/coerce/coercions/time_definitions.rb +32 -0
- data/lib/garcon/chef/handler/devreporter.rb +127 -0
- data/lib/garcon/chef/log.rb +64 -0
- data/lib/garcon/chef/node.rb +100 -0
- data/lib/garcon/chef/provider/civilize.rb +209 -0
- data/lib/garcon/chef/provider/development.rb +159 -0
- data/lib/garcon/chef/provider/download.rb +420 -0
- data/lib/garcon/chef/provider/house_keeping.rb +265 -0
- data/lib/garcon/chef/provider/node_cache.rb +31 -0
- data/lib/garcon/chef/provider/partial.rb +183 -0
- data/lib/garcon/chef/provider/recovery.rb +80 -0
- data/lib/garcon/chef/provider/zip_file.rb +271 -0
- data/lib/garcon/chef/resource/attribute.rb +52 -0
- data/lib/garcon/chef/resource/base_dsl.rb +174 -0
- data/lib/garcon/chef/resource/blender.rb +140 -0
- data/lib/garcon/chef/resource/lazy_eval.rb +66 -0
- data/lib/garcon/chef/resource/resource_name.rb +109 -0
- data/lib/garcon/chef/secret_bag.rb +204 -0
- data/lib/garcon/chef/validations.rb +76 -0
- data/lib/garcon/chef_inclusions.rb +151 -0
- data/lib/garcon/configuration.rb +138 -0
- data/lib/garcon/core_ext.rb +39 -0
- data/lib/garcon/core_ext/array.rb +27 -0
- data/lib/garcon/core_ext/binding.rb +64 -0
- data/lib/garcon/core_ext/boolean.rb +66 -0
- data/lib/garcon/core_ext/duration.rb +271 -0
- data/lib/garcon/core_ext/enumerable.rb +34 -0
- data/lib/garcon/core_ext/file.rb +127 -0
- data/lib/garcon/core_ext/filetest.rb +62 -0
- data/lib/garcon/core_ext/hash.rb +279 -0
- data/lib/garcon/core_ext/kernel.rb +159 -0
- data/lib/garcon/core_ext/lazy.rb +222 -0
- data/lib/garcon/core_ext/method_access.rb +243 -0
- data/lib/garcon/core_ext/module.rb +92 -0
- data/lib/garcon/core_ext/nil.rb +53 -0
- data/lib/garcon/core_ext/numeric.rb +44 -0
- data/lib/garcon/core_ext/object.rb +342 -0
- data/lib/garcon/core_ext/pathname.rb +152 -0
- data/lib/garcon/core_ext/process.rb +41 -0
- data/lib/garcon/core_ext/random.rb +497 -0
- data/lib/garcon/core_ext/string.rb +312 -0
- data/lib/garcon/core_ext/struct.rb +49 -0
- data/lib/garcon/core_ext/symbol.rb +170 -0
- data/lib/garcon/core_ext/time.rb +234 -0
- data/lib/garcon/exceptions.rb +101 -0
- data/lib/garcon/inflections.rb +237 -0
- data/lib/garcon/inflections/defaults.rb +79 -0
- data/lib/garcon/inflections/inflections.rb +182 -0
- data/lib/garcon/inflections/rules_collection.rb +37 -0
- data/lib/garcon/secret.rb +271 -0
- data/lib/garcon/stash/format.rb +114 -0
- data/lib/garcon/stash/journal.rb +226 -0
- data/lib/garcon/stash/queue.rb +83 -0
- data/lib/garcon/stash/serializer.rb +86 -0
- data/lib/garcon/stash/store.rb +435 -0
- data/lib/garcon/task.rb +31 -0
- data/lib/garcon/task/atomic.rb +151 -0
- data/lib/garcon/task/atomic_boolean.rb +127 -0
- data/lib/garcon/task/condition.rb +99 -0
- data/lib/garcon/task/copy_on_notify_observer_set.rb +154 -0
- data/lib/garcon/task/copy_on_write_observer_set.rb +153 -0
- data/lib/garcon/task/count_down_latch.rb +92 -0
- data/lib/garcon/task/delay.rb +196 -0
- data/lib/garcon/task/dereferenceable.rb +144 -0
- data/lib/garcon/task/event.rb +119 -0
- data/lib/garcon/task/executor.rb +275 -0
- data/lib/garcon/task/executor_options.rb +59 -0
- data/lib/garcon/task/future.rb +107 -0
- data/lib/garcon/task/immediate_executor.rb +84 -0
- data/lib/garcon/task/ivar.rb +171 -0
- data/lib/garcon/task/lazy_reference.rb +74 -0
- data/lib/garcon/task/monotonic_time.rb +69 -0
- data/lib/garcon/task/obligation.rb +256 -0
- data/lib/garcon/task/observable.rb +101 -0
- data/lib/garcon/task/priority_queue.rb +234 -0
- data/lib/garcon/task/processor_count.rb +128 -0
- data/lib/garcon/task/read_write_lock.rb +304 -0
- data/lib/garcon/task/safe_task_executor.rb +58 -0
- data/lib/garcon/task/single_thread_executor.rb +97 -0
- data/lib/garcon/task/thread_pool/cached.rb +71 -0
- data/lib/garcon/task/thread_pool/executor.rb +294 -0
- data/lib/garcon/task/thread_pool/fixed.rb +61 -0
- data/lib/garcon/task/thread_pool/worker.rb +90 -0
- data/lib/garcon/task/timer.rb +44 -0
- data/lib/garcon/task/timer_set.rb +194 -0
- data/lib/garcon/task/timer_task.rb +377 -0
- data/lib/garcon/task/waitable_list.rb +58 -0
- data/lib/garcon/utility/ansi.rb +199 -0
- data/lib/garcon/utility/at_random.rb +77 -0
- data/lib/garcon/utility/crypto.rb +292 -0
- data/lib/garcon/utility/equalizer.rb +146 -0
- data/lib/garcon/utility/faker/extensions/array.rb +22 -0
- data/lib/garcon/utility/faker/extensions/symbol.rb +9 -0
- data/lib/garcon/utility/faker/faker.rb +164 -0
- data/lib/garcon/utility/faker/faker/company.rb +17 -0
- data/lib/garcon/utility/faker/faker/hacker.rb +30 -0
- data/lib/garcon/utility/faker/faker/version.rb +3 -0
- data/lib/garcon/utility/faker/locales/en-US.yml +83 -0
- data/lib/garcon/utility/faker/locales/en.yml +21 -0
- data/lib/garcon/utility/file_helper.rb +170 -0
- data/lib/garcon/utility/hookers.rb +178 -0
- data/lib/garcon/utility/interpolation.rb +90 -0
- data/lib/garcon/utility/memstash.rb +364 -0
- data/lib/garcon/utility/misc.rb +54 -0
- data/lib/garcon/utility/msg_from_god.rb +62 -0
- data/lib/garcon/utility/retry.rb +238 -0
- data/lib/garcon/utility/timeout.rb +58 -0
- data/lib/garcon/utility/uber/builder.rb +91 -0
- data/lib/garcon/utility/uber/callable.rb +7 -0
- data/lib/garcon/utility/uber/delegates.rb +13 -0
- data/lib/garcon/utility/uber/inheritable_attr.rb +37 -0
- data/lib/garcon/utility/uber/options.rb +101 -0
- data/lib/garcon/utility/uber/uber_version.rb +3 -0
- data/lib/garcon/utility/uber/version.rb +33 -0
- data/lib/garcon/utility/url_helper.rb +100 -0
- data/lib/garcon/utils.rb +29 -0
- data/lib/garcon/version.rb +62 -0
- data/lib/garcun.rb +24 -0
- metadata +680 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
#
|
|
3
|
+
# Author: Stefano Harding <riddopic@gmail.com>
|
|
4
|
+
# License: Apache License, Version 2.0
|
|
5
|
+
# Copyright: (C) 2014-2015 Stefano Harding
|
|
6
|
+
#
|
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
# you may not use this file except in compliance with the License.
|
|
9
|
+
# You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
# See the License for the specific language governing permissions and
|
|
17
|
+
# limitations under the License.
|
|
18
|
+
#
|
|
19
|
+
|
|
20
|
+
require 'garcon'
|
|
21
|
+
|
|
22
|
+
class Chef
|
|
23
|
+
class Resource
|
|
24
|
+
class HouseKeeping < Chef::Resource
|
|
25
|
+
include Garcon
|
|
26
|
+
|
|
27
|
+
# Chef attributes
|
|
28
|
+
identity_attr :path
|
|
29
|
+
provides :house_keeping
|
|
30
|
+
|
|
31
|
+
# Actions
|
|
32
|
+
actions :purge
|
|
33
|
+
default_action :purge
|
|
34
|
+
|
|
35
|
+
# Attributes
|
|
36
|
+
attribute :path,
|
|
37
|
+
kind_of:String,
|
|
38
|
+
callbacks:{ path: ->(path) { validate_path(path, :dir) }},
|
|
39
|
+
name_attribute: true
|
|
40
|
+
attribute :exclude,
|
|
41
|
+
kind_of: [String, Regexp],
|
|
42
|
+
default: nil
|
|
43
|
+
attribute :manage_symlink_source,
|
|
44
|
+
kind_of: [TrueClass, FalseClass],
|
|
45
|
+
default: true
|
|
46
|
+
attribute :force_unlink,
|
|
47
|
+
kind_of: [TrueClass, FalseClass],
|
|
48
|
+
default: true
|
|
49
|
+
attribute :age,
|
|
50
|
+
kind_of: Integer,
|
|
51
|
+
default: nil
|
|
52
|
+
attribute :size,
|
|
53
|
+
kind_of: String,
|
|
54
|
+
regex: /\d+[kmgt]{1}b{0,1}/i,
|
|
55
|
+
default: nil
|
|
56
|
+
attribute :directory_size,
|
|
57
|
+
kind_of: String,
|
|
58
|
+
regex: /\d+[kmgtpe]{1}b{0,1}/i,
|
|
59
|
+
default: nil
|
|
60
|
+
attribute :recursive,
|
|
61
|
+
kind_of: [TrueClass, FalseClass],
|
|
62
|
+
default: false
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
class Provider
|
|
67
|
+
class HouseKeeping < Chef::Provider
|
|
68
|
+
include Garcon
|
|
69
|
+
|
|
70
|
+
provides :house_keeping
|
|
71
|
+
|
|
72
|
+
# Boolean indicating if WhyRun is supported by this provider
|
|
73
|
+
#
|
|
74
|
+
# @return [TrueClass, FalseClass]
|
|
75
|
+
#
|
|
76
|
+
# @api private
|
|
77
|
+
def whyrun_supported?
|
|
78
|
+
true
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Load and return the current resource
|
|
82
|
+
#
|
|
83
|
+
# @return [Chef::Provider::HouseKeeping]
|
|
84
|
+
#
|
|
85
|
+
# @api private
|
|
86
|
+
def load_current_resource(r = new_resource)
|
|
87
|
+
@current_resource ||= PurgeFlushBinge.new(r)
|
|
88
|
+
@current_resource.exclude(r.exclude) if r.exclude
|
|
89
|
+
@current_resource
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def action_purge(r = new_resource)
|
|
93
|
+
if @current_resource.num_files > 1
|
|
94
|
+
path = r.path
|
|
95
|
+
age = r.age
|
|
96
|
+
size = r.size
|
|
97
|
+
dsize = r.directory_size
|
|
98
|
+
num = @current_resource.num_files
|
|
99
|
+
purge = {}
|
|
100
|
+
purge.merge!(@current_resource.older_than(age)) unless age.nil?
|
|
101
|
+
purge.merge!(@current_resource.larger_than(size)) unless size.nil?
|
|
102
|
+
purge.merge!(@current_resource.to_dir_size(dsize)) unless dsize.nil?
|
|
103
|
+
num_purged = purge.length
|
|
104
|
+
|
|
105
|
+
converge_by "Processed #{num} files from #{path}, " \
|
|
106
|
+
"#{num_purged} purged" do
|
|
107
|
+
if purge.length > 1
|
|
108
|
+
purge.each do |file, data|
|
|
109
|
+
file file do
|
|
110
|
+
force_unlink r.force_unlink
|
|
111
|
+
manage_symlink_source r.manage_symlink_source
|
|
112
|
+
backup false
|
|
113
|
+
action :delete
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
r.updated_by_last_action(true)
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
private # P R O P R I E T À P R I V A T A Vietato L'accesso
|
|
123
|
+
|
|
124
|
+
class PurgeFlushBinge
|
|
125
|
+
def initialize(new_resource)
|
|
126
|
+
search_path = if new_resource.recursive
|
|
127
|
+
::File.join(new_resource.path, '**', '*')
|
|
128
|
+
else
|
|
129
|
+
::File.join(new_resource.path, '*')
|
|
130
|
+
end
|
|
131
|
+
@file_map = Hash.new
|
|
132
|
+
@dir_size = 0
|
|
133
|
+
|
|
134
|
+
Dir[search_path].select { |f| ::File.file?(f) }.map do |file|
|
|
135
|
+
fstat = ::File.stat(file)
|
|
136
|
+
@dir_size += fstat.size
|
|
137
|
+
@file_map.store(file,
|
|
138
|
+
ctime: fstat.ctime.to_i,
|
|
139
|
+
mtime: fstat.mtime.to_i,
|
|
140
|
+
size: fstat.size)
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def older_than(days)
|
|
145
|
+
purge_time = Time.now - (60 * 60 * 24 * days.to_i)
|
|
146
|
+
@file_map.select { |file, data| data[:mtime] < purge_time.to_i }
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def larger_than(size)
|
|
150
|
+
@file_map.select do |file, data|
|
|
151
|
+
c = Humanize.new(size.to_s)
|
|
152
|
+
data[:size].to_f > c.to_size(:b).to_f
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def to_dir_size(size)
|
|
157
|
+
sorted = @file_map.sort_by { |k,v| v[:mtime] }
|
|
158
|
+
c = Humanize.new(size.to_s)
|
|
159
|
+
delete_size = @dir_size - c.to_size(:b).to_f
|
|
160
|
+
return {} if delete_size <= 0
|
|
161
|
+
|
|
162
|
+
f_size = 0
|
|
163
|
+
list = {}
|
|
164
|
+
sorted.each do |f|
|
|
165
|
+
list[f[0]] = f[1]
|
|
166
|
+
f_size += f[1][:size]
|
|
167
|
+
break if f_size >= delete_size
|
|
168
|
+
end
|
|
169
|
+
list
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def exclude(regexp)
|
|
173
|
+
@file_map.delete_if { |file| file.match(Regexp.new(regexp)) }
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def num_files
|
|
177
|
+
@file_map.length
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
class Humanize
|
|
182
|
+
def initialize(size)
|
|
183
|
+
@units = { b: 1, kb: 1024**1, mb: 1024**2, gb: 1024**3, tb: 1024**4 }
|
|
184
|
+
@size_int = size.partition(/\D{1,2}/).at(0).to_i
|
|
185
|
+
unit = size.partition(/\D{1,2}/).at(1).to_s.downcase
|
|
186
|
+
case
|
|
187
|
+
when unit.match(/[kmgtpe]{1}/)
|
|
188
|
+
@size_unit = unit.concat('b')
|
|
189
|
+
when unit.match(/[kmgtpe]{1}b/)
|
|
190
|
+
@size_unit = unit
|
|
191
|
+
else
|
|
192
|
+
@size_unit = 'b'
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
def to_size(unit, places = 1)
|
|
197
|
+
unit_val = @units[unit.to_s.downcase.to_sym]
|
|
198
|
+
bytes = @size_int * @units[@size_unit.to_sym]
|
|
199
|
+
size = bytes.to_f / unit_val.to_f
|
|
200
|
+
sprintf("%.#{places}f", size).to_f
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
def from_size(places = 1)
|
|
204
|
+
unit_val = @units[@size_unit.to_s.downcase.to_sym]
|
|
205
|
+
sprintf("%.#{places}f", @size_int * unit_val)
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
# Chef::Platform mapping for resource and providers
|
|
213
|
+
#
|
|
214
|
+
# @return [undefined]
|
|
215
|
+
#
|
|
216
|
+
# @api private.
|
|
217
|
+
Chef::Platform.set(
|
|
218
|
+
platform: :amazon,
|
|
219
|
+
resource: :house_keeping,
|
|
220
|
+
provider: Chef::Provider::HouseKeeping
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
# Chef::Platform mapping for resource and providers
|
|
224
|
+
#
|
|
225
|
+
# @return [undefined]
|
|
226
|
+
#
|
|
227
|
+
# @api private.
|
|
228
|
+
Chef::Platform.set(
|
|
229
|
+
platform: :centos,
|
|
230
|
+
resource: :house_keeping,
|
|
231
|
+
provider: Chef::Provider::HouseKeeping
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
# Chef::Platform mapping for resource and providers
|
|
235
|
+
#
|
|
236
|
+
# @return [undefined]
|
|
237
|
+
#
|
|
238
|
+
# @api private.
|
|
239
|
+
Chef::Platform.set(
|
|
240
|
+
platform: :oracle,
|
|
241
|
+
resource: :house_keeping,
|
|
242
|
+
provider: Chef::Provider::HouseKeeping
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
# Chef::Platform mapping for resource and providers
|
|
246
|
+
#
|
|
247
|
+
# @return [undefined]
|
|
248
|
+
#
|
|
249
|
+
# @api private.
|
|
250
|
+
Chef::Platform.set(
|
|
251
|
+
platform: :redhat,
|
|
252
|
+
resource: :house_keeping,
|
|
253
|
+
provider: Chef::Provider::HouseKeeping
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
# Chef::Platform mapping for resource and providers
|
|
257
|
+
#
|
|
258
|
+
# @return [undefined]
|
|
259
|
+
#
|
|
260
|
+
# @api private.
|
|
261
|
+
Chef::Platform.set(
|
|
262
|
+
platform: :scientific,
|
|
263
|
+
resource: :house_keeping,
|
|
264
|
+
provider: Chef::Provider::HouseKeeping
|
|
265
|
+
)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
#
|
|
3
|
+
# Author: Stefano Harding <riddopic@gmail.com>
|
|
4
|
+
# License: Apache License, Version 2.0
|
|
5
|
+
# Copyright: (C) 2014-2015 Stefano Harding
|
|
6
|
+
#
|
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
# you may not use this file except in compliance with the License.
|
|
9
|
+
# You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
# See the License for the specific language governing permissions and
|
|
17
|
+
# limitations under the License.
|
|
18
|
+
#
|
|
19
|
+
|
|
20
|
+
require 'garcon'
|
|
21
|
+
|
|
22
|
+
# Cache the node object for profit and gross revenue margins.
|
|
23
|
+
#
|
|
24
|
+
class Chef::Resource::NodeCache < Chef::Resource
|
|
25
|
+
include Garcon(blender: true)
|
|
26
|
+
attribute(:name, kind_of: String, name_attribute: true)
|
|
27
|
+
attribute(:cache, kinf_of: Hash, default: lazy { node })
|
|
28
|
+
action(:run) do
|
|
29
|
+
Garcon.config.stash.load(node: new_resource.node)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
#
|
|
3
|
+
# Author: Stefano Harding <riddopic@gmail.com>
|
|
4
|
+
# License: Apache License, Version 2.0
|
|
5
|
+
# Copyright: (C) 2014-2015 Stefano Harding
|
|
6
|
+
#
|
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
# you may not use this file except in compliance with the License.
|
|
9
|
+
# You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
# See the License for the specific language governing permissions and
|
|
17
|
+
# limitations under the License.
|
|
18
|
+
#
|
|
19
|
+
|
|
20
|
+
require 'garcon'
|
|
21
|
+
require 'digest/md5'
|
|
22
|
+
|
|
23
|
+
class Chef
|
|
24
|
+
class Resource
|
|
25
|
+
class Partial < Chef::Resource
|
|
26
|
+
include Garcon
|
|
27
|
+
|
|
28
|
+
# Chef attributes
|
|
29
|
+
identity_attr :name
|
|
30
|
+
provides :partial
|
|
31
|
+
|
|
32
|
+
# Actions
|
|
33
|
+
actions :run
|
|
34
|
+
default_action :run
|
|
35
|
+
|
|
36
|
+
# Attributes
|
|
37
|
+
attribute :run_list,
|
|
38
|
+
kind_of: String
|
|
39
|
+
attribute :save,
|
|
40
|
+
kind_of: [TrueClass, FalseClass],
|
|
41
|
+
default: true
|
|
42
|
+
attribute :arguments,
|
|
43
|
+
kind_of: Hash
|
|
44
|
+
attribute :attributes,
|
|
45
|
+
kind_of: Hash
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
class Provider
|
|
50
|
+
class Partial < Chef::Provider
|
|
51
|
+
include Garcon
|
|
52
|
+
|
|
53
|
+
# Boolean indicating if WhyRun is supported by this provider
|
|
54
|
+
#
|
|
55
|
+
# @return [TrueClass, FalseClass]
|
|
56
|
+
#
|
|
57
|
+
# @api private
|
|
58
|
+
def whyrun_supported?
|
|
59
|
+
true
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Load and return the current resource.
|
|
63
|
+
#
|
|
64
|
+
# @return [Chef::Provider::Partial]
|
|
65
|
+
#
|
|
66
|
+
# @api private
|
|
67
|
+
def load_current_resource
|
|
68
|
+
@current_resource ||= Chef::Resource::Partial.new(new_resource.name)
|
|
69
|
+
@current_resource
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def action_run(r = new_resource)
|
|
73
|
+
converge_by "Executing partial run list: #{r.run_list}" do
|
|
74
|
+
partial = r.name
|
|
75
|
+
runner = Chef::PartialRun.new(partial, r.attributes, r.arguments)
|
|
76
|
+
runner.partial_run(r.run_list)
|
|
77
|
+
unless runner.run_status.updated_resources.empty?
|
|
78
|
+
r.updated_by_last_action(true)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
if r.save
|
|
83
|
+
node.consume_attributes(runner.clean_attrs)
|
|
84
|
+
runner.save_updated_node
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
class PartialRun < Client
|
|
91
|
+
def initialize(partial, attributes = nil, arguments = {})
|
|
92
|
+
super(attributes, arguments)
|
|
93
|
+
@partial = partial
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def partial_run(run_list)
|
|
97
|
+
cache_path = file_cache_path
|
|
98
|
+
begin
|
|
99
|
+
digest = Digest::MD5.hexdigest(@partial)
|
|
100
|
+
Chef::Config[:file_cache_path] = file_cache_path("partial-#{digest}")
|
|
101
|
+
run_ohai
|
|
102
|
+
register unless Chef::Config[:solo]
|
|
103
|
+
load_node
|
|
104
|
+
run_list_items = run_list.split(',').collect do |item|
|
|
105
|
+
Chef::RunList::RunListItem.new(item)
|
|
106
|
+
end
|
|
107
|
+
node.run_list(*run_list_items)
|
|
108
|
+
build_node
|
|
109
|
+
run_context = setup_run_context
|
|
110
|
+
converge(run_context)
|
|
111
|
+
ensure
|
|
112
|
+
Chef::Config[:file_cache_path] = cache_path
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# Clean the node data
|
|
117
|
+
#
|
|
118
|
+
def clean_attrs
|
|
119
|
+
data = node.to_hash
|
|
120
|
+
%w(run_list recipes roles).each { |k| data.delete(k) }
|
|
121
|
+
data
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def run_completed_successfully
|
|
125
|
+
# do nothing
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# Chef::Platform mapping for resource and providers
|
|
131
|
+
#
|
|
132
|
+
# @return [undefined]
|
|
133
|
+
#
|
|
134
|
+
# @api private.
|
|
135
|
+
Chef::Platform.set(
|
|
136
|
+
platform: :amazon,
|
|
137
|
+
resource: :partial,
|
|
138
|
+
provider: Chef::Provider::Partial
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
# Chef::Platform mapping for resource and providers
|
|
142
|
+
#
|
|
143
|
+
# @return [undefined]
|
|
144
|
+
#
|
|
145
|
+
# @api private.
|
|
146
|
+
Chef::Platform.set(
|
|
147
|
+
platform: :centos,
|
|
148
|
+
resource: :partial,
|
|
149
|
+
provider: Chef::Provider::Partial
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
# Chef::Platform mapping for resource and providers
|
|
153
|
+
#
|
|
154
|
+
# @return [undefined]
|
|
155
|
+
#
|
|
156
|
+
# @api private.
|
|
157
|
+
Chef::Platform.set(
|
|
158
|
+
platform: :oracle,
|
|
159
|
+
resource: :partial,
|
|
160
|
+
provider: Chef::Provider::Partial
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
# Chef::Platform mapping for resource and providers
|
|
164
|
+
#
|
|
165
|
+
# @return [undefined]
|
|
166
|
+
#
|
|
167
|
+
# @api private.
|
|
168
|
+
Chef::Platform.set(
|
|
169
|
+
platform: :redhat,
|
|
170
|
+
resource: :partial,
|
|
171
|
+
provider: Chef::Provider::Partial
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
# Chef::Platform mapping for resource and providers
|
|
175
|
+
#
|
|
176
|
+
# @return [undefined]
|
|
177
|
+
#
|
|
178
|
+
# @api private.
|
|
179
|
+
Chef::Platform.set(
|
|
180
|
+
platform: :scientific,
|
|
181
|
+
resource: :partial,
|
|
182
|
+
provider: Chef::Provider::Partial
|
|
183
|
+
)
|