chef 0.8.16 → 0.9.0.a3

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.

Files changed (185) hide show
  1. data/bin/shef +1 -0
  2. data/distro/common/man/man1/chef-server-webui.1 +106 -0
  3. data/distro/common/man/man1/chef-server.1 +0 -1
  4. data/distro/common/man/man1/chef-solr-indexer.1 +55 -0
  5. data/distro/common/man/man1/chef-solr.1 +55 -0
  6. data/distro/common/man/man8/chef-client.8 +4 -2
  7. data/distro/common/man/man8/chef-solo.8 +1 -2
  8. data/distro/common/man/man8/chef-solr-rebuild.8 +37 -0
  9. data/distro/common/man/man8/knife.8 +668 -266
  10. data/distro/common/man/man8/shef.8 +45 -0
  11. data/distro/common/markdown/README +3 -0
  12. data/distro/common/markdown/knife.mkd +520 -0
  13. data/distro/debian/etc/default/chef-client +4 -0
  14. data/distro/debian/etc/default/chef-server +6 -0
  15. data/distro/debian/etc/default/chef-server-webui +6 -0
  16. data/distro/debian/etc/default/chef-solr +4 -0
  17. data/distro/debian/etc/default/chef-solr-indexer +4 -0
  18. data/distro/debian/etc/init.d/chef-client +41 -41
  19. data/distro/debian/etc/init.d/chef-server +10 -10
  20. data/distro/debian/etc/init.d/chef-server-webui +121 -0
  21. data/distro/debian/etc/init.d/chef-solr +177 -0
  22. data/distro/debian/etc/init.d/chef-solr-indexer +176 -0
  23. data/distro/redhat/etc/init.d/chef-client +76 -48
  24. data/distro/redhat/etc/init.d/chef-server +85 -51
  25. data/distro/redhat/etc/init.d/chef-server-webui +85 -51
  26. data/distro/redhat/etc/init.d/chef-solr +77 -49
  27. data/distro/redhat/etc/init.d/chef-solr-indexer +77 -48
  28. data/distro/redhat/etc/logrotate.d/chef-client +8 -0
  29. data/distro/redhat/etc/logrotate.d/chef-server +8 -0
  30. data/distro/redhat/etc/logrotate.d/chef-server-webui +8 -0
  31. data/distro/redhat/etc/logrotate.d/chef-solr +8 -0
  32. data/distro/redhat/etc/logrotate.d/chef-solr-indexer +8 -0
  33. data/distro/redhat/etc/sysconfig/chef-client +9 -4
  34. data/distro/redhat/etc/sysconfig/chef-server +10 -6
  35. data/distro/redhat/etc/sysconfig/chef-server-webui +10 -6
  36. data/distro/redhat/etc/sysconfig/chef-solr +3 -4
  37. data/distro/redhat/etc/sysconfig/chef-solr-indexer +3 -3
  38. data/lib/chef.rb +16 -5
  39. data/lib/chef/application/knife.rb +2 -2
  40. data/lib/chef/application/solo.rb +1 -7
  41. data/lib/chef/cache/checksum.rb +12 -5
  42. data/lib/chef/cache/file_cache_by_checksum.rb +52 -0
  43. data/lib/chef/checksum.rb +115 -0
  44. data/lib/chef/client.rb +193 -185
  45. data/lib/chef/config.rb +9 -1
  46. data/lib/chef/cookbook/cookbook_collection.rb +43 -0
  47. data/lib/chef/cookbook/file_system_file_vendor.rb +53 -0
  48. data/lib/chef/cookbook/file_vendor.rb +47 -0
  49. data/lib/chef/cookbook/metadata.rb +34 -35
  50. data/lib/chef/cookbook/metadata/version.rb +1 -1
  51. data/lib/chef/cookbook_loader.rb +70 -45
  52. data/lib/chef/cookbook_version.rb +760 -0
  53. data/lib/chef/couchdb.rb +8 -5
  54. data/lib/chef/data_bag_item.rb +5 -5
  55. data/lib/chef/exceptions.rb +10 -0
  56. data/lib/chef/file_access_control.rb +134 -0
  57. data/lib/chef/handler.rb +62 -0
  58. data/lib/chef/handler/json_file.rb +47 -0
  59. data/lib/chef/knife.rb +14 -2
  60. data/lib/chef/knife/bootstrap.rb +126 -0
  61. data/lib/chef/knife/cookbook_bulk_delete.rb +1 -1
  62. data/lib/chef/knife/cookbook_delete.rb +4 -4
  63. data/lib/chef/knife/cookbook_download.rb +57 -26
  64. data/lib/chef/knife/cookbook_metadata.rb +2 -2
  65. data/lib/chef/knife/cookbook_show.rb +30 -11
  66. data/lib/chef/knife/cookbook_upload.rb +113 -86
  67. data/lib/chef/knife/ec2_server_create.rb +146 -0
  68. data/lib/chef/knife/ec2_server_delete.rb +84 -0
  69. data/lib/chef/knife/ec2_server_list.rb +82 -0
  70. data/lib/chef/knife/status.rb +51 -0
  71. data/lib/chef/mixin/language_include_attribute.rb +16 -11
  72. data/lib/chef/mixin/language_include_recipe.rb +15 -16
  73. data/lib/chef/mixin/recipe_definition_dsl_core.rb +17 -20
  74. data/lib/chef/mixin/shell_out.rb +38 -0
  75. data/lib/chef/mixins.rb +1 -1
  76. data/lib/chef/node.rb +190 -63
  77. data/lib/chef/node/attribute.rb +92 -78
  78. data/lib/chef/platform.rb +24 -4
  79. data/lib/chef/provider.rb +28 -10
  80. data/lib/chef/provider/breakpoint.rb +2 -2
  81. data/lib/chef/provider/cookbook_file.rb +96 -0
  82. data/lib/chef/provider/cron.rb +2 -2
  83. data/lib/chef/provider/deploy.rb +12 -10
  84. data/lib/chef/provider/env.rb +152 -0
  85. data/lib/chef/provider/env/windows.rb +75 -0
  86. data/lib/chef/provider/file.rb +10 -14
  87. data/lib/chef/provider/group.rb +15 -2
  88. data/lib/chef/provider/group/dscl.rb +17 -25
  89. data/lib/chef/provider/group/gpasswd.rb +6 -3
  90. data/lib/chef/provider/group/pw.rb +3 -7
  91. data/lib/chef/provider/group/windows.rb +79 -0
  92. data/lib/chef/provider/link.rb +4 -5
  93. data/lib/chef/provider/mdadm.rb +25 -18
  94. data/lib/chef/provider/mount/mount.rb +28 -27
  95. data/lib/chef/provider/package.rb +35 -35
  96. data/lib/chef/provider/package/dpkg.rb +13 -10
  97. data/lib/chef/provider/package/easy_install.rb +6 -6
  98. data/lib/chef/provider/package/freebsd.rb +17 -51
  99. data/lib/chef/provider/package/rpm.rb +1 -1
  100. data/lib/chef/provider/package/rubygems.rb +391 -74
  101. data/lib/chef/provider/package/yum.rb +2 -2
  102. data/lib/chef/provider/package/zypper.rb +2 -1
  103. data/lib/chef/provider/remote_directory.rb +60 -83
  104. data/lib/chef/provider/remote_file.rb +17 -66
  105. data/lib/chef/provider/script.rb +20 -9
  106. data/lib/chef/provider/service.rb +23 -30
  107. data/lib/chef/provider/service/arch.rb +3 -3
  108. data/lib/chef/provider/service/debian.rb +22 -17
  109. data/lib/chef/provider/service/freebsd.rb +4 -4
  110. data/lib/chef/provider/service/init.rb +2 -2
  111. data/lib/chef/provider/service/redhat.rb +14 -16
  112. data/lib/chef/provider/service/simple.rb +7 -3
  113. data/lib/chef/provider/service/solaris.rb +85 -0
  114. data/lib/chef/provider/service/upstart.rb +12 -7
  115. data/lib/chef/provider/service/windows.rb +2 -2
  116. data/lib/chef/provider/template.rb +133 -118
  117. data/lib/chef/provider/user.rb +34 -17
  118. data/lib/chef/provider/user/dscl.rb +117 -114
  119. data/lib/chef/provider/user/windows.rb +124 -0
  120. data/lib/chef/providers.rb +7 -0
  121. data/lib/chef/recipe.rb +39 -20
  122. data/lib/chef/resource.rb +47 -52
  123. data/lib/chef/resource/apt_package.rb +4 -4
  124. data/lib/chef/resource/bash.rb +4 -4
  125. data/lib/chef/resource/cookbook_file.rb +45 -0
  126. data/lib/chef/resource/cron.rb +3 -3
  127. data/lib/chef/resource/csh.rb +4 -4
  128. data/lib/chef/resource/deploy.rb +3 -3
  129. data/lib/chef/resource/directory.rb +4 -4
  130. data/lib/chef/resource/dpkg_package.rb +4 -4
  131. data/lib/chef/resource/easy_install_package.rb +3 -3
  132. data/lib/chef/resource/env.rb +58 -0
  133. data/lib/chef/resource/erl_call.rb +3 -3
  134. data/lib/chef/resource/execute.rb +3 -3
  135. data/lib/chef/resource/file.rb +3 -3
  136. data/lib/chef/resource/freebsd_package.rb +3 -3
  137. data/lib/chef/resource/gem_package.rb +17 -9
  138. data/lib/chef/resource/git.rb +3 -3
  139. data/lib/chef/resource/group.rb +3 -3
  140. data/lib/chef/resource/http_request.rb +4 -4
  141. data/lib/chef/resource/ifconfig.rb +3 -3
  142. data/lib/chef/resource/link.rb +3 -3
  143. data/lib/chef/resource/log.rb +2 -2
  144. data/lib/chef/resource/macports_package.rb +2 -2
  145. data/lib/chef/resource/mdadm.rb +3 -3
  146. data/lib/chef/resource/mount.rb +2 -2
  147. data/lib/chef/resource/package.rb +4 -4
  148. data/lib/chef/resource/pacman_package.rb +4 -4
  149. data/lib/chef/resource/perl.rb +4 -4
  150. data/lib/chef/resource/portage_package.rb +4 -4
  151. data/lib/chef/resource/python.rb +4 -4
  152. data/lib/chef/resource/remote_directory.rb +3 -3
  153. data/lib/chef/resource/remote_file.rb +26 -3
  154. data/lib/chef/resource/route.rb +3 -3
  155. data/lib/chef/resource/ruby.rb +3 -3
  156. data/lib/chef/resource/ruby_block.rb +3 -2
  157. data/lib/chef/resource/scm.rb +7 -5
  158. data/lib/chef/resource/script.rb +4 -4
  159. data/lib/chef/resource/service.rb +3 -3
  160. data/lib/chef/resource/subversion.rb +4 -2
  161. data/lib/chef/resource/template.rb +3 -3
  162. data/lib/chef/resource/user.rb +3 -3
  163. data/lib/chef/resource/yum_package.rb +3 -3
  164. data/lib/chef/resource_collection.rb +9 -5
  165. data/lib/chef/resources.rb +2 -0
  166. data/lib/chef/rest.rb +4 -0
  167. data/lib/chef/role.rb +2 -0
  168. data/lib/chef/run_context.rb +108 -0
  169. data/lib/chef/run_list.rb +75 -98
  170. data/lib/chef/run_list/run_list_expansion.rb +156 -0
  171. data/lib/chef/run_list/run_list_item.rb +71 -0
  172. data/lib/chef/runner.rb +58 -61
  173. data/lib/chef/sandbox.rb +147 -0
  174. data/lib/chef/shef.rb +4 -3
  175. data/lib/chef/shef/ext.rb +12 -4
  176. data/lib/chef/shef/shef_session.rb +27 -23
  177. data/lib/chef/shell_out.rb +375 -0
  178. data/lib/chef/util/windows.rb +56 -0
  179. data/lib/chef/util/windows/net_group.rb +101 -0
  180. data/lib/chef/util/windows/net_user.rb +198 -0
  181. data/lib/chef/version.rb +20 -0
  182. metadata +112 -22
  183. data/lib/chef/compile.rb +0 -158
  184. data/lib/chef/cookbook.rb +0 -201
  185. data/lib/chef/mixin/generate_url.rb +0 -58
@@ -1,158 +0,0 @@
1
- #
2
- # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Author:: Christopher Walters (<cw@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
- require 'chef/cookbook_loader'
20
- require 'chef/resource_collection'
21
- require 'chef/node'
22
- require 'chef/role'
23
- require 'chef/log'
24
- require 'chef/mixin/deep_merge'
25
- require 'chef/mixin/language_include_recipe'
26
-
27
- class Chef
28
- class Compile
29
-
30
- attr_accessor :node, :cookbook_loader, :collection, :definitions
31
-
32
- include Chef::Mixin::LanguageIncludeRecipe
33
-
34
- # Creates a new Chef::Compile object and populates its fields. This object gets
35
- # used by the Chef Server to generate a fully compiled recipe list for a node.
36
- #
37
- # === Returns
38
- # object<Chef::Compile>:: Duh. :)
39
- def initialize(node=nil)
40
- @node = node
41
- @cookbook_loader = Chef::CookbookLoader.new
42
- @node.cookbook_loader = @cookbook_loader
43
- @collection = Chef::ResourceCollection.new
44
- @definitions = Hash.new
45
- @recipes = Array.new
46
- @default_attributes = Hash.new
47
- @override_attributes = Hash.new
48
-
49
- load_libraries
50
- load_providers
51
- load_resources
52
- load_attributes
53
- load_definitions
54
- load_recipes
55
- end
56
-
57
- # Looks up the node via the "name" argument, first from CouchDB, then by calling
58
- # Chef::Node.find_file(name)
59
- #
60
- # The first step in compiling the catalog. Results available via the node accessor.
61
- #
62
- # === Returns
63
- # node<Chef::Node>:: The loaded Chef Node
64
- def load_node(name)
65
- Chef::Log.debug("Loading Chef Node #{name} from CouchDB")
66
- @node = Chef::Node.load(name)
67
- Chef::Log.debug("Loading Recipe for Chef Node #{name}")
68
- @node.find_file(name)
69
- @node
70
- end
71
-
72
- # Load all the attributes, from every cookbook
73
- #
74
- # === Returns
75
- # true:: Always returns true
76
- def load_attributes()
77
- @cookbook_loader.each do |cookbook|
78
- cookbook.load_attributes(@node)
79
- end
80
-
81
- true
82
- end
83
-
84
- # Load all the definitions, from every cookbook, so they are available when we process
85
- # the recipes.
86
- #
87
- # Results available via the definitions accessor.
88
- #
89
- # === Returns
90
- # true:: Always returns true
91
- def load_definitions()
92
- @cookbook_loader.each do |cookbook|
93
- hash = cookbook.load_definitions
94
- @definitions.merge!(hash)
95
- end
96
- true
97
- end
98
-
99
- # Load all the libraries, from every cookbook, so they are available when we process
100
- # the recipes.
101
- #
102
- # === Returns
103
- # true:: Always returns true
104
- def load_libraries()
105
- @cookbook_loader.each do |cookbook|
106
- cookbook.load_libraries
107
- end
108
- true
109
- end
110
-
111
- # Load all the providers, from every cookbook, so they are available when we process
112
- # the recipes.
113
- #
114
- # === Returns
115
- # true:: Always returns true
116
- def load_providers()
117
- @cookbook_loader.each do |cookbook|
118
- cookbook.load_providers
119
- end
120
- true
121
- end
122
-
123
- # Load all the resources, from every cookbook, so they are available when we process
124
- # the recipes.
125
- #
126
- # === Returns
127
- # true:: Always returns true
128
- def load_resources()
129
- @cookbook_loader.each do |cookbook|
130
- cookbook.load_resources
131
- end
132
- true
133
- end
134
-
135
- # Load all the recipes specified in the node data (loaded via load_node, above.)
136
- #
137
- # The results are available via the collection accessor (which returns a Chef::ResourceCollection
138
- # object)
139
- #
140
- # === Returns
141
- # true:: Always returns true
142
- def load_recipes
143
- expand_node
144
- @recipes.each do |recipe|
145
- include_recipe(recipe)
146
- end
147
- true
148
- end
149
-
150
- def expand_node
151
- @recipes, @default_attributes, @override_attributes = @node.run_list.expand
152
- @node.default_attrs = Chef::Mixin::DeepMerge.merge(@node.default_attrs, @default_attributes)
153
- @node.override_attrs = Chef::Mixin::DeepMerge.merge(@node.override_attrs, @override_attributes)
154
- return @recipes, @default_attributes, @override_attributes
155
- end
156
-
157
- end
158
- end
@@ -1,201 +0,0 @@
1
- #
2
- # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Author:: Nuo Yan (<nuo@opscode.com>)
4
- # Author:: Christopher Walters (<cw@opscode.com>)
5
- # Copyright:: Copyright (c) 2008 Opscode, Inc.
6
- # License:: Apache License, Version 2.0
7
- #
8
- # Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- # See the License for the specific language governing permissions and
18
- # limitations under the License.
19
-
20
- require 'chef/log'
21
- require 'chef/node'
22
- require 'chef/resource_definition_list'
23
- require 'chef/recipe'
24
- require 'chef/mixin/convert_to_class_name'
25
-
26
- class Chef
27
- class Cookbook
28
- include Chef::Mixin::ConvertToClassName
29
-
30
- attr_accessor :definition_files, :template_files, :remote_files,
31
- :lib_files, :resource_files, :provider_files, :name
32
- attr_reader :recipe_files, :attribute_files
33
-
34
- # Creates a new Chef::Cookbook object.
35
- #
36
- # === Returns
37
- # object<Chef::Cookbook>:: Duh. :)
38
- def initialize(name)
39
- @name = name
40
- @attribute_files = Array.new
41
- @attribute_names = Hash.new
42
- @definition_files = Array.new
43
- @template_files = Array.new
44
- @remote_files = Array.new
45
- @recipe_files = Array.new
46
- @recipe_names = Hash.new
47
- @lib_files = Array.new
48
- @resource_files = Array.new
49
- @provider_files = Array.new
50
- end
51
-
52
- # Loads all the library files in this cookbook via require.
53
- #
54
- # === Returns
55
- # true:: Always returns true
56
- def load_libraries
57
- @lib_files.each do |file|
58
- Chef::Log.debug("Loading cookbook #{name} library file: #{file}")
59
- require file
60
- end
61
- true
62
- end
63
-
64
- # Loads all the attribute files in this cookbook within a particular <Chef::Node>.
65
- #
66
- # === Parameters
67
- # node<Chef::Node>:: The Chef::Node to apply the attributes to
68
- #
69
- # === Returns
70
- # node<Chef::Node>:: The updated Chef::Node object
71
- #
72
- # === Raises
73
- # <ArgumentError>:: If the argument is not a kind_of? <Chef::Node>
74
- def load_attributes(node)
75
- @attribute_files.each do |file|
76
- load_attribute_file(file, node)
77
- end
78
- node
79
- end
80
-
81
- def load_attribute_file(file, node)
82
- Chef::Log.debug("Loading attributes from #{file}")
83
- node.from_file(file)
84
- end
85
-
86
- def load_attribute(name, node)
87
- attr_name = shorten_name(name)
88
- file = @attribute_files[@attribute_names[attr_name]]
89
- load_attribute_file(file, node)
90
- node
91
- end
92
-
93
- # Loads all the resource definitions in this cookbook.
94
- #
95
- # === Returns
96
- # definitions<Hash>: A hash of <Chef::ResourceDefinition> objects, keyed by name.
97
- def load_definitions
98
- results = Hash.new
99
- @definition_files.each do |file|
100
- Chef::Log.debug("Loading cookbook #{name}'s definitions from #{file}")
101
- resourcelist = Chef::ResourceDefinitionList.new
102
- resourcelist.from_file(file)
103
- results.merge!(resourcelist.defines) do |key, oldval, newval|
104
- Chef::Log.info("Overriding duplicate definition #{key}, new found in #{file}")
105
- newval
106
- end
107
- end
108
- results
109
- end
110
-
111
- # Loads all the resources in this cookbook.
112
- #
113
- # === Returns
114
- # true:: Always returns true
115
- def load_resources
116
- @resource_files.each do |file|
117
- Chef::Log.debug("Loading cookbook #{name}'s resources from #{file}")
118
- Chef::Resource.build_from_file(name, file)
119
- end
120
- end
121
-
122
- # Loads all the providers in this cookbook.
123
- #
124
- # === Returns
125
- # true:: Always returns true
126
- def load_providers
127
- @provider_files.each do |file|
128
- Chef::Log.debug("Loading cookbook #{name}'s providers from #{file}")
129
- Chef::Provider.build_from_file(name, file)
130
- end
131
- end
132
-
133
- def recipe_files=(*args)
134
- @recipe_files, @recipe_names = set_with_names(args.flatten)
135
- @recipe_files
136
- end
137
-
138
- def attribute_files=(*args)
139
- @attribute_files, @attribute_names = set_with_names(args.flatten)
140
- @attribute_files
141
- end
142
-
143
- def recipe?(name)
144
- lookup_name = name
145
- if name =~ /(.+)::(.+)/
146
- cookbook_name = $1
147
- lookup_name = $2
148
- return false unless cookbook_name == @name
149
- end
150
- @recipe_names.has_key?(lookup_name)
151
- end
152
-
153
- def recipes
154
- results = Array.new
155
- @recipe_names.each_key do |rname|
156
- results << "#{@name}::#{rname}"
157
- end
158
- results
159
- end
160
-
161
- def load_recipe(name, node, collection=nil, definitions=nil, cookbook_loader=nil)
162
- cookbook_name = @name
163
- recipe_name = shorten_name(name)
164
-
165
- unless @recipe_names.has_key?(recipe_name)
166
- raise ArgumentError, "Cannot find a recipe matching #{recipe_name} in cookbook #{@name}"
167
- end
168
- Chef::Log.debug("Found recipe #{recipe_name} in cookbook #{cookbook_name}") if Chef::Log.debug?
169
- recipe = Chef::Recipe.new(cookbook_name, recipe_name, node,
170
- collection, definitions, cookbook_loader)
171
- recipe.from_file(@recipe_files[@recipe_names[recipe_name]])
172
- recipe
173
- end
174
-
175
- private
176
-
177
- def shorten_name(name)
178
- short_name = nil
179
- nmatch = name.match(/^(.+?)::(.+)$/)
180
- short_name = nmatch ? nmatch[2] : name
181
- end
182
-
183
- def set_with_names(file_list)
184
- files = file_list
185
- names = Hash.new
186
- files.each_index do |i|
187
- file = files[i]
188
- case file
189
- when /(.+\/)(.+).rb$/
190
- names[$2] = i
191
- when /(.+).rb$/
192
- names[$1] = i
193
- else
194
- names[file] = i
195
- end
196
- end
197
- [ files, names ]
198
- end
199
-
200
- end
201
- end
@@ -1,58 +0,0 @@
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/platform'
20
-
21
- class Chef
22
- module Mixin
23
- module GenerateURL
24
-
25
- def generate_cookbook_url(url, cookbook, type, node, args=nil)
26
- Chef::Log.debug("generating cookbook url for url=#{url}, cookbook=#{cookbook.inspect}, type=#{type}, node=#{node}")
27
- new_url = nil
28
- if url =~ /^(http|https):\/\//
29
- new_url = url
30
- else
31
- new_url = "cookbooks/#{cookbook}/#{type}?"
32
- new_url += "id=#{url}"
33
- new_url = generate_cookbook_url_from_uri(new_url, node, args)
34
- end
35
- Chef::Log.debug("generated cookbook url: #{new_url}")
36
- return new_url
37
- end
38
-
39
- def generate_cookbook_url_from_uri(uri, node, args=nil)
40
- platform, version = Chef::Platform.find_platform_and_version(node)
41
- uri =~ /cookbooks\/(.+?)\/(.+)\?/
42
- cookbook = $1
43
- type = $2
44
- if type == "files" || type == "templates"
45
- uri += "&platform=#{platform}&version=#{version}&fqdn=#{node[:fqdn]}&node_name=#{node.name}"
46
- end
47
- if args
48
- args.each do |key, value|
49
- uri += "&#{key}=#{value}"
50
- end
51
- end
52
-
53
- uri
54
- end
55
-
56
- end
57
- end
58
- end