giraffesoft-chef 0.7.15
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +201 -0
- data/README.rdoc +135 -0
- data/bin/chef-client +26 -0
- data/bin/chef-solo +26 -0
- data/distro/debian/etc/init.d/chef-client +175 -0
- data/distro/debian/etc/init.d/chef-indexer +175 -0
- data/distro/debian/etc/init.d/chef-server +120 -0
- data/distro/debian/man/man1/chef-indexer.1 +42 -0
- data/distro/debian/man/man1/chef-server.1 +108 -0
- data/distro/debian/man/man8/chef-client.8 +61 -0
- data/distro/debian/man/man8/chef-solo.8 +58 -0
- data/distro/redhat/etc/chef/client.rb +16 -0
- data/distro/redhat/etc/chef/indexer.rb +10 -0
- data/distro/redhat/etc/chef/server.rb +22 -0
- data/distro/redhat/etc/init.d/chef-client +74 -0
- data/distro/redhat/etc/init.d/chef-indexer +76 -0
- data/distro/redhat/etc/init.d/chef-server +77 -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 +421 -0
- data/lib/chef/compile.rb +170 -0
- data/lib/chef/config.rb +141 -0
- data/lib/chef/cookbook.rb +171 -0
- data/lib/chef/cookbook/metadata.rb +407 -0
- data/lib/chef/cookbook/metadata/version.rb +87 -0
- data/lib/chef/cookbook_loader.rb +180 -0
- data/lib/chef/couchdb.rb +176 -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 +386 -0
- data/lib/chef/mixin/convert_to_class_name.rb +48 -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 +92 -0
- data/lib/chef/mixin/from_file.rb +50 -0
- data/lib/chef/mixin/generate_url.rb +49 -0
- data/lib/chef/mixin/language.rb +79 -0
- data/lib/chef/mixin/params_validate.rb +197 -0
- data/lib/chef/mixin/recipe_definition_dsl_core.rb +77 -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 +254 -0
- data/lib/chef/provider.rb +101 -0
- data/lib/chef/provider/cron.rb +187 -0
- data/lib/chef/provider/deploy.rb +281 -0
- data/lib/chef/provider/deploy/revision.rb +70 -0
- data/lib/chef/provider/deploy/timestamped.rb +33 -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/git.rb +198 -0
- data/lib/chef/provider/group.rb +120 -0
- data/lib/chef/provider/group/gpasswd.rb +50 -0
- data/lib/chef/provider/group/groupadd.rb +78 -0
- data/lib/chef/provider/group/pw.rb +88 -0
- data/lib/chef/provider/group/usermod.rb +57 -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 +117 -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 +109 -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 +136 -0
- data/lib/chef/provider/package/yum-dump.py +106 -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 +141 -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 +135 -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 +71 -0
- data/lib/chef/provider/service/redhat.rb +62 -0
- data/lib/chef/provider/service/simple.rb +115 -0
- data/lib/chef/provider/subversion.rb +148 -0
- data/lib/chef/provider/template.rb +143 -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 +144 -0
- data/lib/chef/resource.rb +380 -0
- data/lib/chef/resource/apt_package.rb +34 -0
- data/lib/chef/resource/bash.rb +33 -0
- data/lib/chef/resource/cron.rb +179 -0
- data/lib/chef/resource/csh.rb +33 -0
- data/lib/chef/resource/deploy.rb +350 -0
- data/lib/chef/resource/deploy_revision.rb +35 -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/git.rb +36 -0
- data/lib/chef/resource/group.rb +70 -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/scm.rb +129 -0
- data/lib/chef/resource/script.rb +51 -0
- data/lib/chef/resource/service.rb +134 -0
- data/lib/chef/resource/subversion.rb +33 -0
- data/lib/chef/resource/template.rb +60 -0
- data/lib/chef/resource/timestamped_deploy.rb +31 -0
- data/lib/chef/resource/user.rb +98 -0
- data/lib/chef/resource_collection.rb +204 -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 +130 -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 +347 -0
- data/lib/chef/util/file_edit.rb +125 -0
- data/lib/chef/util/fileedit.rb +121 -0
- metadata +293 -0
@@ -0,0 +1,407 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Author:: AJ Christensen (<aj@opscode.com>)
|
4
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
5
|
+
# License:: Apache License, Version 2.0
|
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 'chef/mixin/from_file'
|
21
|
+
require 'chef/mixin/params_validate'
|
22
|
+
require 'chef/mixin/check_helper'
|
23
|
+
require 'chef/log'
|
24
|
+
require 'chef/cookbook/metadata/version'
|
25
|
+
|
26
|
+
class Chef
|
27
|
+
class Cookbook
|
28
|
+
class Metadata
|
29
|
+
|
30
|
+
include Chef::Mixin::CheckHelper
|
31
|
+
include Chef::Mixin::ParamsValidate
|
32
|
+
include Chef::Mixin::FromFile
|
33
|
+
|
34
|
+
attr_accessor :cookbook,
|
35
|
+
:platforms,
|
36
|
+
:dependencies,
|
37
|
+
:recommendations,
|
38
|
+
:suggestions,
|
39
|
+
:conflicting,
|
40
|
+
:providing,
|
41
|
+
:replacing,
|
42
|
+
:attributes,
|
43
|
+
:recipes,
|
44
|
+
:version
|
45
|
+
|
46
|
+
# Builds a new Chef::Cookbook::Metadata object.
|
47
|
+
#
|
48
|
+
# === Parameters
|
49
|
+
# cookbook<String>:: An optional cookbook object
|
50
|
+
# maintainer<String>:: An optional maintainer
|
51
|
+
# maintainer_email<String>:: An optional maintainer email
|
52
|
+
# license<String>::An optional license. Default is Apache v2.0
|
53
|
+
#
|
54
|
+
# === Returns
|
55
|
+
# metadata<Chef::Cookbook::Metadata>
|
56
|
+
def initialize(cookbook=nil, maintainer='Your Name', maintainer_email='youremail@example.com', license='Apache v2.0')
|
57
|
+
@cookbook = cookbook
|
58
|
+
@name = cookbook ? cookbook.name : ""
|
59
|
+
@long_description = ""
|
60
|
+
self.maintainer(maintainer)
|
61
|
+
self.maintainer_email(maintainer_email)
|
62
|
+
self.license(license)
|
63
|
+
self.description('A fabulous new cookbook')
|
64
|
+
@platforms = Mash.new
|
65
|
+
@dependencies = Mash.new
|
66
|
+
@recommendations = Mash.new
|
67
|
+
@suggestions = Mash.new
|
68
|
+
@conflicting = Mash.new
|
69
|
+
@providing = Mash.new
|
70
|
+
@replacing = Mash.new
|
71
|
+
@attributes = Mash.new
|
72
|
+
@recipes = Mash.new
|
73
|
+
@version = Version.new "0.0.0"
|
74
|
+
if cookbook
|
75
|
+
@recipes = cookbook.recipes.inject({}) do |r, e|
|
76
|
+
e = self.name if e =~ /::default$/
|
77
|
+
r[e] = ""
|
78
|
+
self.provides e
|
79
|
+
r
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Sets the cookbooks maintainer, or returns it.
|
85
|
+
#
|
86
|
+
# === Parameters
|
87
|
+
# maintainer<String>:: The maintainers name
|
88
|
+
#
|
89
|
+
# === Returns
|
90
|
+
# maintainer<String>:: Returns the current maintainer.
|
91
|
+
def maintainer(arg=nil)
|
92
|
+
set_or_return(
|
93
|
+
:maintainer,
|
94
|
+
arg,
|
95
|
+
:kind_of => [ String ]
|
96
|
+
)
|
97
|
+
end
|
98
|
+
|
99
|
+
# Sets the maintainers email address, or returns it.
|
100
|
+
#
|
101
|
+
# === Parameters
|
102
|
+
# maintainer_email<String>:: The maintainers email address
|
103
|
+
#
|
104
|
+
# === Returns
|
105
|
+
# maintainer_email<String>:: Returns the current maintainer email.
|
106
|
+
def maintainer_email(arg=nil)
|
107
|
+
set_or_return(
|
108
|
+
:maintainer_email,
|
109
|
+
arg,
|
110
|
+
:kind_of => [ String ]
|
111
|
+
)
|
112
|
+
end
|
113
|
+
|
114
|
+
# Sets the current license, or returns it.
|
115
|
+
#
|
116
|
+
# === Parameters
|
117
|
+
# license<String>:: The current license.
|
118
|
+
#
|
119
|
+
# === Returns
|
120
|
+
# license<String>:: Returns the current license
|
121
|
+
def license(arg=nil)
|
122
|
+
set_or_return(
|
123
|
+
:license,
|
124
|
+
arg,
|
125
|
+
:kind_of => [ String ]
|
126
|
+
)
|
127
|
+
end
|
128
|
+
|
129
|
+
# Sets the current description, or returns it. Should be short - one line only!
|
130
|
+
#
|
131
|
+
# === Parameters
|
132
|
+
# description<String>:: The new description
|
133
|
+
#
|
134
|
+
# === Returns
|
135
|
+
# description<String>:: Returns the description
|
136
|
+
def description(arg=nil)
|
137
|
+
set_or_return(
|
138
|
+
:description,
|
139
|
+
arg,
|
140
|
+
:kind_of => [ String ]
|
141
|
+
)
|
142
|
+
end
|
143
|
+
|
144
|
+
# Sets the current long description, or returns it. Might come from a README, say.
|
145
|
+
#
|
146
|
+
# === Parameters
|
147
|
+
# long_description<String>:: The new long description
|
148
|
+
#
|
149
|
+
# === Returns
|
150
|
+
# long_description<String>:: Returns the long description
|
151
|
+
def long_description(arg=nil)
|
152
|
+
set_or_return(
|
153
|
+
:long_description,
|
154
|
+
arg,
|
155
|
+
:kind_of => [ String ]
|
156
|
+
)
|
157
|
+
end
|
158
|
+
|
159
|
+
# Sets the current cookbook version, or returns it. Can be two or three digits, seperated
|
160
|
+
# by dots. ie: '2.1', '1.5.4' or '0.9'.
|
161
|
+
#
|
162
|
+
# === Parameters
|
163
|
+
# version<String>:: The curent version, as a string
|
164
|
+
#
|
165
|
+
# === Returns
|
166
|
+
# version<String>:: Returns the current version
|
167
|
+
def version(arg=nil)
|
168
|
+
if arg
|
169
|
+
@version = Version.new(arg)
|
170
|
+
end
|
171
|
+
|
172
|
+
@version.to_s
|
173
|
+
end
|
174
|
+
|
175
|
+
# Sets the name of the cookbook, or returns it.
|
176
|
+
#
|
177
|
+
# === Parameters
|
178
|
+
# name<String>:: The curent cookbook name.
|
179
|
+
#
|
180
|
+
# === Returns
|
181
|
+
# name<String>:: Returns the current cookbook name.
|
182
|
+
def name(arg=nil)
|
183
|
+
set_or_return(
|
184
|
+
:name,
|
185
|
+
arg,
|
186
|
+
:kind_of => [ String ]
|
187
|
+
)
|
188
|
+
end
|
189
|
+
|
190
|
+
# Adds a supported platform, with version checking strings.
|
191
|
+
#
|
192
|
+
# === Parameters
|
193
|
+
# platform<String>,<Symbol>:: The platform (like :ubuntu or :mac_os_x)
|
194
|
+
# *versions<String>:: A list of versions matching << <= = >= >> followed by a version.
|
195
|
+
#
|
196
|
+
# === Returns
|
197
|
+
# versions<Array>:: Returns the list of versions for the platform
|
198
|
+
def supports(platform, *versions)
|
199
|
+
versions.each { |v| _check_version_expression(v) }
|
200
|
+
@platforms[platform] = versions
|
201
|
+
@platforms[platform]
|
202
|
+
end
|
203
|
+
|
204
|
+
# Adds a dependency on another cookbook, with version checking strings.
|
205
|
+
#
|
206
|
+
# === Parameters
|
207
|
+
# cookbook<String>:: The cookbook
|
208
|
+
# *versions<String>:: A list of versions matching << <= = >= >> followed by a version.
|
209
|
+
#
|
210
|
+
# === Returns
|
211
|
+
# versions<Array>:: Returns the list of versions for the platform
|
212
|
+
def depends(cookbook, *versions)
|
213
|
+
versions.each { |v| _check_version_expression(v) }
|
214
|
+
@dependencies[cookbook] = versions
|
215
|
+
@dependencies[cookbook]
|
216
|
+
end
|
217
|
+
|
218
|
+
# Adds a recommendation for another cookbook, with version checking strings.
|
219
|
+
#
|
220
|
+
# === Parameters
|
221
|
+
# cookbook<String>:: The cookbook
|
222
|
+
# *versions<String>:: A list of versions matching << <= = >= >> followed by a version.
|
223
|
+
#
|
224
|
+
# === Returns
|
225
|
+
# versions<Array>:: Returns the list of versions for the platform
|
226
|
+
def recommends(cookbook, *versions)
|
227
|
+
versions.each { |v| _check_version_expression(v) }
|
228
|
+
@recommendations[cookbook] = versions
|
229
|
+
@recommendations[cookbook]
|
230
|
+
end
|
231
|
+
|
232
|
+
# Adds a suggestion for another cookbook, with version checking strings.
|
233
|
+
#
|
234
|
+
# === Parameters
|
235
|
+
# cookbook<String>:: The cookbook
|
236
|
+
# *versions<String>:: A list of versions matching << <= = >= >> followed by a version.
|
237
|
+
#
|
238
|
+
# === Returns
|
239
|
+
# versions<Array>:: Returns the list of versions for the platform
|
240
|
+
def suggests(cookbook, *versions)
|
241
|
+
versions.each { |v| _check_version_expression(v) }
|
242
|
+
@suggestions[cookbook] = versions
|
243
|
+
@suggestions[cookbook]
|
244
|
+
end
|
245
|
+
|
246
|
+
# Adds a conflict for another cookbook, with version checking strings.
|
247
|
+
#
|
248
|
+
# === Parameters
|
249
|
+
# cookbook<String>:: The cookbook
|
250
|
+
# *versions<String>:: A list of versions matching << <= = >= >> followed by a version.
|
251
|
+
#
|
252
|
+
# === Returns
|
253
|
+
# versions<Array>:: Returns the list of versions for the platform
|
254
|
+
def conflicts(cookbook, *versions)
|
255
|
+
versions.each { |v| _check_version_expression(v) }
|
256
|
+
@conflicting[cookbook] = versions
|
257
|
+
@conflicting[cookbook]
|
258
|
+
end
|
259
|
+
|
260
|
+
# Adds a recipe, definition, or resource provided by this cookbook.
|
261
|
+
#
|
262
|
+
# Recipes are specified as normal
|
263
|
+
# Definitions are followed by (), and can include :params for prototyping
|
264
|
+
# Resources are the stringified version (service[apache2])
|
265
|
+
#
|
266
|
+
# === Parameters
|
267
|
+
# recipe, definition, resource<String>:: The thing we provide
|
268
|
+
# *versions<String>:: A list of versions matching << <= = >= >> followed by a version.
|
269
|
+
#
|
270
|
+
# === Returns
|
271
|
+
# versions<Array>:: Returns the list of versions for the platform
|
272
|
+
def provides(cookbook, *versions)
|
273
|
+
versions.each { |v| _check_version_expression(v) }
|
274
|
+
@providing[cookbook] = versions
|
275
|
+
@providing[cookbook]
|
276
|
+
end
|
277
|
+
|
278
|
+
# Adds a cookbook that is replaced by this one, with version checking strings.
|
279
|
+
#
|
280
|
+
# === Parameters
|
281
|
+
# cookbook<String>:: The cookbook we replace
|
282
|
+
# *versions<String>:: A list of versions matching << <= = >= >> followed by a version.
|
283
|
+
#
|
284
|
+
# === Returns
|
285
|
+
# versions<Array>:: Returns the list of versions for the platform
|
286
|
+
def replaces(cookbook, *versions)
|
287
|
+
versions.each { |v| _check_version_expression(v) }
|
288
|
+
@replacing[cookbook] = versions
|
289
|
+
@replacing[cookbook]
|
290
|
+
end
|
291
|
+
|
292
|
+
# Adds a description for a recipe.
|
293
|
+
#
|
294
|
+
# === Parameters
|
295
|
+
# recipe<String>:: The recipe
|
296
|
+
# description<String>:: The description of the recipe
|
297
|
+
#
|
298
|
+
# === Returns
|
299
|
+
# description<String>:: Returns the current description
|
300
|
+
def recipe(name, description)
|
301
|
+
@recipes[name] = description
|
302
|
+
end
|
303
|
+
|
304
|
+
# Adds an attribute that a user needs to configure for this cookbook. Takes
|
305
|
+
# a name (with the / notation for a nested attribute), followed by any of
|
306
|
+
# these options
|
307
|
+
#
|
308
|
+
# display_name<String>:: What a UI should show for this attribute
|
309
|
+
# description<String>:: A hint as to what this attr is for
|
310
|
+
# multiple_values<True>,<False>:: Whether it supports multiple values
|
311
|
+
# type<String>:: "string", "hash" or "array" - default is "string"
|
312
|
+
# required<True>,<False>:: Whether this attr is required - default false
|
313
|
+
# recipes<Array>:: An array of recipes which need this attr set.
|
314
|
+
# default<String>,<Array>,<Hash>:: The default value
|
315
|
+
#
|
316
|
+
# === Parameters
|
317
|
+
# name<String>:: The name of the attribute ('foo', or 'apache2/log_dir')
|
318
|
+
# options<Hash>:: The description of the options
|
319
|
+
#
|
320
|
+
# === Returns
|
321
|
+
# options<Hash>:: Returns the current options hash
|
322
|
+
def attribute(name, options)
|
323
|
+
validate(
|
324
|
+
options,
|
325
|
+
{
|
326
|
+
:display_name => { :kind_of => String },
|
327
|
+
:description => { :kind_of => String },
|
328
|
+
:multiple_values => { :equal_to => [ true, false ], :default => false },
|
329
|
+
:type => { :equal_to => [ "string", "array", "hash" ], :default => "string" },
|
330
|
+
:required => { :equal_to => [ true, false ], :default => false },
|
331
|
+
:recipes => { :kind_of => [ Array ], :default => [] },
|
332
|
+
:default => { :kind_of => [ String, Array, Hash ] }
|
333
|
+
}
|
334
|
+
)
|
335
|
+
@attributes[name] = options
|
336
|
+
@attributes[name]
|
337
|
+
end
|
338
|
+
|
339
|
+
def _check_version_expression(version_string)
|
340
|
+
if version_string =~ /^(>>|>=|=|<=|<<) (.+)$/
|
341
|
+
[ $1, $2 ]
|
342
|
+
else
|
343
|
+
raise ArgumentError, "Version expression #{version_string} is invalid!"
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
def to_json(*a)
|
348
|
+
result = {
|
349
|
+
:name => self.name,
|
350
|
+
:description => self.description,
|
351
|
+
:long_description => self.long_description,
|
352
|
+
:maintainer => self.maintainer,
|
353
|
+
:maintainer_email => self.maintainer_email,
|
354
|
+
:license => self.license,
|
355
|
+
:platforms => self.platforms,
|
356
|
+
:dependencies => self.dependencies,
|
357
|
+
:recommendations => self.recommendations,
|
358
|
+
:suggestions => self.suggestions,
|
359
|
+
:conflicting => self.conflicting,
|
360
|
+
:providing => self.providing,
|
361
|
+
:replacing => self.replacing,
|
362
|
+
:attributes => self.attributes,
|
363
|
+
:recipes => self.recipes,
|
364
|
+
:version => self.version
|
365
|
+
}
|
366
|
+
result.to_json(*a)
|
367
|
+
end
|
368
|
+
|
369
|
+
def self.from_hash(o)
|
370
|
+
cm = self.new()
|
371
|
+
cm.from_hash(o)
|
372
|
+
cm
|
373
|
+
end
|
374
|
+
|
375
|
+
def from_hash(o)
|
376
|
+
self.name o['name'] if o.has_key?('name')
|
377
|
+
self.description o['description'] if o.has_key?('description')
|
378
|
+
self.long_description o['long_description'] if o.has_key?('long_description')
|
379
|
+
self.maintainer o['maintainer'] if o.has_key?('maintainer')
|
380
|
+
self.maintainer_email o['maintainer_email'] if o.has_key?('maintainer_email')
|
381
|
+
self.license o['license'] if o.has_key?('license')
|
382
|
+
self.platforms = o['platforms'] if o.has_key?('platforms')
|
383
|
+
self.dependencies = o['dependencies'] if o.has_key?('dependencies')
|
384
|
+
self.recommendations = o['recommendations'] if o.has_key?('recommendations')
|
385
|
+
self.suggestions = o['suggestions'] if o.has_key?('suggestions')
|
386
|
+
self.conflicting = o['conflicting'] if o.has_key?('conflicting')
|
387
|
+
self.providing = o['providing'] if o.has_key?('providing')
|
388
|
+
self.replacing = o['replacing'] if o.has_key?('replacing')
|
389
|
+
self.attributes = o['attributes'] if o.has_key?('attributes')
|
390
|
+
self.recipes = o['recipes'] if o.has_key?('recipes')
|
391
|
+
self.version = o['version'] if o.has_key?('version')
|
392
|
+
self
|
393
|
+
end
|
394
|
+
|
395
|
+
def self.from_json(string)
|
396
|
+
o = JSON.parse(string)
|
397
|
+
self.from_hash(o)
|
398
|
+
end
|
399
|
+
|
400
|
+
def from_json(string)
|
401
|
+
o = JSON.parse(string)
|
402
|
+
from_hash(o)
|
403
|
+
end
|
404
|
+
|
405
|
+
end
|
406
|
+
end
|
407
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
#
|
2
|
+
# Author:: AJ Christensen (<aj@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/cookbook'
|
20
|
+
require 'chef/cookbook/metadata'
|
21
|
+
|
22
|
+
class Chef::Cookbook::Metadata
|
23
|
+
class Version
|
24
|
+
include Comparable
|
25
|
+
|
26
|
+
attr_accessor :major,
|
27
|
+
:minor,
|
28
|
+
:patch
|
29
|
+
|
30
|
+
def initialize(str="")
|
31
|
+
@major, @minor, @patch = _parse(str)
|
32
|
+
end
|
33
|
+
|
34
|
+
def _parse(str="")
|
35
|
+
@major, @minor, @patch = case str
|
36
|
+
when /^(\d+)\.(\d+)\.(\d+)$/
|
37
|
+
[ $1.to_i, $2.to_i, $3.to_i ]
|
38
|
+
when /^(\d+)\.(\d+)$/
|
39
|
+
[ $1.to_i, $2.to_i, 0 ]
|
40
|
+
else
|
41
|
+
raise "Metadata version does not match 'x.y.z' or 'x.y'"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def inspect
|
46
|
+
"#{@major}.#{@minor}.#{@patch}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def to_s
|
50
|
+
"#{@major}.#{@minor}.#{@patch}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def <=>(v)
|
54
|
+
major, minor, patch = (
|
55
|
+
[ :major, :minor, :patch ].collect do |method|
|
56
|
+
self.send(method) <=> v.send(method)
|
57
|
+
end
|
58
|
+
)
|
59
|
+
|
60
|
+
Chef::Log.debug "(#{self.to_s}/#{v.to_s}) major,minor,patch: #{[major,minor,patch].join(',')}"
|
61
|
+
|
62
|
+
# all these returns feels like C, surely there is a better way!
|
63
|
+
|
64
|
+
if major == 0 && minor == 0 && patch == 0
|
65
|
+
comp = 0
|
66
|
+
end
|
67
|
+
|
68
|
+
if major == 1
|
69
|
+
comp = 1
|
70
|
+
end
|
71
|
+
|
72
|
+
if major == 0 && minor == 1 && patch == -1
|
73
|
+
comp = 1
|
74
|
+
end
|
75
|
+
|
76
|
+
if minor == 1 && major == 0 && patch == 0
|
77
|
+
comp = 1
|
78
|
+
end
|
79
|
+
|
80
|
+
if patch == 1 && major == 0 && minor == 0
|
81
|
+
comp = 1
|
82
|
+
end
|
83
|
+
|
84
|
+
return (comp || -1)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|