chef 12.5.1-universal-mingw32 → 12.6.0-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -1
  3. data/README.md +6 -4
  4. data/Rakefile +1 -4
  5. data/chef-windows.gemspec +21 -0
  6. data/chef.gemspec +58 -0
  7. data/lib/chef/api_client/registration.rb +9 -4
  8. data/lib/chef/application.rb +3 -84
  9. data/lib/chef/application/apply.rb +9 -2
  10. data/lib/chef/application/client.rb +8 -3
  11. data/lib/chef/application/solo.rb +7 -1
  12. data/lib/chef/application/windows_service.rb +21 -6
  13. data/lib/chef/application/windows_service_manager.rb +2 -3
  14. data/lib/chef/audit/runner.rb +1 -0
  15. data/lib/chef/chef_class.rb +1 -11
  16. data/lib/chef/chef_fs/chef_fs_data_store.rb +181 -2
  17. data/lib/chef/chef_fs/file_system/cookbook_subdir.rb +5 -0
  18. data/lib/chef/chef_fs/file_system/file_system_entry.rb +11 -7
  19. data/lib/chef/client.rb +28 -1
  20. data/lib/chef/cookbook/cookbook_collection.rb +14 -1
  21. data/lib/chef/cookbook/cookbook_version_loader.rb +1 -1
  22. data/lib/chef/cookbook/metadata.rb +115 -9
  23. data/lib/chef/cookbook/remote_file_vendor.rb +1 -1
  24. data/lib/chef/cookbook_version.rb +6 -2
  25. data/lib/chef/data_bag.rb +1 -1
  26. data/lib/chef/data_bag_item.rb +1 -1
  27. data/lib/chef/digester.rb +5 -1
  28. data/lib/chef/dsl/chef_provisioning.rb +57 -0
  29. data/lib/chef/dsl/cheffish.rb +64 -0
  30. data/lib/chef/dsl/declare_resource.rb +108 -0
  31. data/lib/chef/dsl/platform_introspection.rb +3 -3
  32. data/lib/chef/dsl/recipe.rb +3 -73
  33. data/lib/chef/dsl/resources.rb +27 -1
  34. data/lib/chef/event_dispatch/base.rb +3 -0
  35. data/lib/chef/event_dispatch/dispatcher.rb +5 -0
  36. data/lib/chef/event_dispatch/events_output_stream.rb +8 -0
  37. data/lib/chef/exceptions.rb +21 -1
  38. data/lib/chef/file_access_control/unix.rb +12 -12
  39. data/lib/chef/file_content_management/deploy/cp.rb +2 -2
  40. data/lib/chef/file_content_management/deploy/mv_unix.rb +4 -4
  41. data/lib/chef/file_content_management/deploy/mv_windows.rb +1 -1
  42. data/lib/chef/formatters/base.rb +7 -0
  43. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +2 -2
  44. data/lib/chef/formatters/indentable_output_stream.rb +5 -0
  45. data/lib/chef/http.rb +19 -3
  46. data/lib/chef/http/decompressor.rb +2 -2
  47. data/lib/chef/json_compat.rb +1 -0
  48. data/lib/chef/knife.rb +16 -2
  49. data/lib/chef/knife/bootstrap.rb +55 -10
  50. data/lib/chef/knife/cookbook_site_install.rb +5 -1
  51. data/lib/chef/knife/core/bootstrap_context.rb +2 -1
  52. data/lib/chef/knife/core/node_presenter.rb +1 -1
  53. data/lib/chef/knife/ssh.rb +30 -16
  54. data/lib/chef/knife/ssl_check.rb +4 -2
  55. data/lib/chef/knife/ssl_fetch.rb +3 -2
  56. data/lib/chef/knife/status.rb +14 -1
  57. data/lib/chef/log.rb +14 -0
  58. data/lib/chef/mixin/get_source_from_package.rb +7 -2
  59. data/lib/chef/mixin/properties.rb +302 -0
  60. data/lib/chef/mixin/proxified_socket.rb +38 -0
  61. data/lib/chef/mixin/subclass_directive.rb +37 -0
  62. data/lib/chef/node.rb +13 -5
  63. data/lib/chef/platform/query_helpers.rb +14 -3
  64. data/lib/chef/platform/service_helpers.rb +20 -38
  65. data/lib/chef/policy_builder/expand_node_object.rb +3 -0
  66. data/lib/chef/policy_builder/policyfile.rb +1 -0
  67. data/lib/chef/property.rb +51 -12
  68. data/lib/chef/provider.rb +40 -35
  69. data/lib/chef/provider/deploy.rb +1 -1
  70. data/lib/chef/provider/dsc_resource.rb +54 -20
  71. data/lib/chef/provider/execute.rb +25 -4
  72. data/lib/chef/provider/group.rb +1 -1
  73. data/lib/chef/provider/lwrp_base.rb +1 -0
  74. data/lib/chef/provider/package.rb +76 -30
  75. data/lib/chef/provider/package/dpkg.rb +152 -69
  76. data/lib/chef/provider/package/openbsd.rb +6 -8
  77. data/lib/chef/provider/package/solaris.rb +2 -0
  78. data/lib/chef/provider/package/windows.rb +95 -14
  79. data/lib/chef/provider/package/windows/exe.rb +129 -0
  80. data/lib/chef/provider/package/windows/msi.rb +37 -13
  81. data/lib/chef/provider/package/windows/registry_uninstall_entry.rb +89 -0
  82. data/lib/chef/provider/package/yum.rb +13 -3
  83. data/lib/chef/provider/powershell_script.rb +3 -0
  84. data/lib/chef/provider/remote_file/cache_control_data.rb +37 -4
  85. data/lib/chef/provider/remote_file/http.rb +1 -1
  86. data/lib/chef/provider/script.rb +1 -0
  87. data/lib/chef/provider/service.rb +13 -10
  88. data/lib/chef/provider/service/solaris.rb +43 -17
  89. data/lib/chef/provider/service/upstart.rb +3 -3
  90. data/lib/chef/provider/user.rb +1 -1
  91. data/lib/chef/provider/user/dscl.rb +111 -100
  92. data/lib/chef/provider/user/windows.rb +5 -3
  93. data/lib/chef/recipe.rb +3 -5
  94. data/lib/chef/resource.rb +77 -320
  95. data/lib/chef/resource/action_class.rb +4 -0
  96. data/lib/chef/resource/dpkg_package.rb +4 -3
  97. data/lib/chef/resource/dsc_resource.rb +40 -2
  98. data/lib/chef/resource/execute.rb +9 -1
  99. data/lib/chef/resource/ksh.rb +32 -0
  100. data/lib/chef/resource/lwrp_base.rb +6 -10
  101. data/lib/chef/resource/package.rb +8 -9
  102. data/lib/chef/resource/registry_key.rb +1 -1
  103. data/lib/chef/resource/resource_notification.rb +14 -1
  104. data/lib/chef/resource/script.rb +1 -1
  105. data/lib/chef/resource/windows_package.rb +1 -1
  106. data/lib/chef/resource_builder.rb +14 -7
  107. data/lib/chef/resource_reporter.rb +6 -0
  108. data/lib/chef/resources.rb +1 -7
  109. data/lib/chef/rest.rb +1 -1
  110. data/lib/chef/run_context.rb +45 -2
  111. data/lib/chef/run_list/run_list_expansion.rb +47 -0
  112. data/lib/chef/runner.rb +25 -0
  113. data/lib/chef/search/query.rb +16 -2
  114. data/lib/chef/util/diff.rb +2 -2
  115. data/lib/chef/util/powershell/ps_credential.rb +2 -3
  116. data/lib/chef/version.rb +1 -1
  117. data/lib/chef/win32/api/file.rb +51 -1
  118. data/lib/chef/win32/file.rb +5 -0
  119. data/lib/chef/win32/file/version_info.rb +93 -0
  120. data/lib/chef/win32/mutex.rb +1 -1
  121. data/spec/data/apt/chef-integration-test2-1.0/debian/changelog +5 -0
  122. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2.debhelper.log +45 -0
  123. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2.substvars +1 -0
  124. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/conffiles +1 -0
  125. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/control +10 -0
  126. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/md5sums +1 -0
  127. data/spec/data/apt/chef-integration-test2-1.0/debian/compat +1 -0
  128. data/spec/data/apt/chef-integration-test2-1.0/debian/conffiles +1 -0
  129. data/spec/data/apt/chef-integration-test2-1.0/debian/control +13 -0
  130. data/spec/data/apt/chef-integration-test2-1.0/debian/copyright +34 -0
  131. data/spec/data/apt/chef-integration-test2-1.0/debian/files +1 -0
  132. data/spec/data/apt/chef-integration-test2-1.0/debian/rules +13 -0
  133. data/spec/data/apt/chef-integration-test2-1.0/debian/source/format +1 -0
  134. data/spec/data/apt/chef-integration-test2_1.0-1.debian.tar.gz +0 -0
  135. data/spec/data/apt/chef-integration-test2_1.0-1.dsc +18 -0
  136. data/spec/data/apt/chef-integration-test2_1.0-1_amd64.build +91 -0
  137. data/spec/data/apt/chef-integration-test2_1.0-1_amd64.changes +31 -0
  138. data/spec/data/apt/chef-integration-test2_1.0-1_amd64.deb +0 -0
  139. data/spec/data/apt/chef-integration-test2_1.0.orig.tar.gz +0 -0
  140. data/spec/functional/application_spec.rb +1 -1
  141. data/spec/functional/audit/runner_spec.rb +4 -0
  142. data/spec/functional/knife/ssh_spec.rb +5 -5
  143. data/spec/functional/notifications_spec.rb +74 -4
  144. data/spec/functional/resource/aix_service_spec.rb +2 -2
  145. data/spec/functional/resource/dpkg_package_spec.rb +339 -0
  146. data/spec/functional/resource/ifconfig_spec.rb +3 -1
  147. data/spec/functional/resource/mount_spec.rb +5 -2
  148. data/spec/functional/resource/package_spec.rb +1 -1
  149. data/spec/functional/resource/user/windows_spec.rb +8 -0
  150. data/spec/functional/resource/windows_package_spec.rb +177 -0
  151. data/spec/functional/win32/version_info_spec.rb +50 -0
  152. data/spec/integration/client/client_spec.rb +80 -0
  153. data/spec/integration/knife/download_spec.rb +9 -0
  154. data/spec/integration/knife/upload_spec.rb +28 -1
  155. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +93 -23
  156. data/spec/integration/recipes/resource_action_spec.rb +211 -116
  157. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +72 -0
  158. data/spec/integration/solo/solo_spec.rb +34 -0
  159. data/spec/spec_helper.rb +11 -1
  160. data/spec/support/platform_helpers.rb +8 -0
  161. data/spec/support/shared/integration/integration_helper.rb +6 -0
  162. data/spec/support/shared/unit/execute_resource.rb +5 -0
  163. data/spec/support/shared/unit/platform_introspector.rb +7 -0
  164. data/spec/tiny_server.rb +6 -2
  165. data/spec/unit/api_client/registration_spec.rb +5 -4
  166. data/spec/unit/application_spec.rb +1 -181
  167. data/spec/unit/chef_fs/file_system/cookbook_subdir_spec.rb +34 -0
  168. data/spec/unit/cookbook/metadata_spec.rb +122 -2
  169. data/spec/unit/http_spec.rb +102 -0
  170. data/spec/unit/knife/bootstrap_spec.rb +55 -13
  171. data/spec/unit/knife/core/bootstrap_context_spec.rb +10 -3
  172. data/spec/unit/knife/ssl_check_spec.rb +7 -3
  173. data/spec/unit/knife/ssl_fetch_spec.rb +2 -2
  174. data/spec/unit/knife/status_spec.rb +13 -13
  175. data/spec/unit/knife_spec.rb +26 -2
  176. data/spec/unit/lwrp_spec.rb +1 -1
  177. data/spec/unit/mixin/properties_spec.rb +97 -0
  178. data/spec/unit/mixin/proxified_socket_spec.rb +94 -0
  179. data/spec/unit/mixin/subclass_directive_spec.rb +45 -0
  180. data/spec/unit/node_spec.rb +9 -1
  181. data/spec/unit/policy_builder/policyfile_spec.rb +2 -0
  182. data/spec/unit/property/validation_spec.rb +14 -12
  183. data/spec/unit/property_spec.rb +56 -0
  184. data/spec/unit/provider/deploy_spec.rb +1 -1
  185. data/spec/unit/provider/dsc_resource_spec.rb +63 -24
  186. data/spec/unit/provider/execute_spec.rb +95 -28
  187. data/spec/unit/provider/package/dpkg_spec.rb +185 -96
  188. data/spec/unit/provider/package/windows/exe_spec.rb +251 -0
  189. data/spec/unit/provider/package/windows/msi_spec.rb +94 -10
  190. data/spec/unit/provider/package/windows_spec.rb +227 -26
  191. data/spec/unit/provider/package/yum_spec.rb +6 -0
  192. data/spec/unit/provider/package_spec.rb +495 -366
  193. data/spec/unit/provider/remote_file/cache_control_data_spec.rb +62 -36
  194. data/spec/unit/provider/script_spec.rb +2 -2
  195. data/spec/unit/provider/service/solaris_smf_service_spec.rb +110 -39
  196. data/spec/unit/provider/service/upstart_service_spec.rb +19 -0
  197. data/spec/unit/provider/user/dscl_spec.rb +14 -0
  198. data/spec/unit/provider/user/windows_spec.rb +2 -2
  199. data/spec/unit/provider/user_spec.rb +9 -0
  200. data/spec/unit/provider_resolver_spec.rb +6 -30
  201. data/spec/unit/recipe_spec.rb +46 -20
  202. data/spec/unit/resource/chef_gem_spec.rb +1 -1
  203. data/spec/unit/resource/dsc_resource_spec.rb +14 -3
  204. data/spec/unit/resource/ksh_spec.rb +40 -0
  205. data/spec/unit/resource/registry_key_spec.rb +2 -2
  206. data/spec/unit/resource/resource_notification_spec.rb +44 -45
  207. data/spec/unit/resource_reporter_spec.rb +7 -0
  208. data/spec/unit/resource_spec.rb +268 -253
  209. data/spec/unit/rest_spec.rb +2 -2
  210. data/spec/unit/run_list/run_list_expansion_spec.rb +18 -3
  211. data/spec/unit/search/query_spec.rb +19 -1
  212. data/spec/unit/util/powershell/ps_credential_spec.rb +8 -1
  213. data/spec/unit/windows_service_spec.rb +83 -38
  214. data/tasks/external_tests.rb +19 -9
  215. data/tasks/rspec.rb +1 -1
  216. metadata +70 -21
  217. data/spec/support/pedant/Gemfile +0 -3
  218. data/spec/support/pedant/pedant_config.rb +0 -129
  219. data/spec/support/pedant/run_pedant.rb +0 -63
  220. data/spec/support/pedant/stickywicket.pem +0 -27
  221. data/spec/unit/provider/package_spec.rbe +0 -0
@@ -69,7 +69,7 @@ class Chef
69
69
  Chef::FileCache.move_to(raw_file.path, cache_filename)
70
70
  else
71
71
  Chef::Log.debug("Not fetching #{cache_filename}, as the cache is up to date.")
72
- Chef::Log.debug("current checksum: #{current_checksum}; manifest checksum: #{found_manifest_record['checksum']})")
72
+ Chef::Log.debug("Current checksum: #{current_checksum}; manifest checksum: #{found_manifest_record['checksum']})")
73
73
  end
74
74
 
75
75
  full_path_cache_filename = Chef::FileCache.load(cache_filename, false)
@@ -4,7 +4,7 @@
4
4
  # Author:: Tim Hinderliter (<tim@opscode.com>)
5
5
  # Author:: Seth Falcon (<seth@opscode.com>)
6
6
  # Author:: Daniel DeLeo (<dan@opscode.com>)
7
- # Copyright:: Copyright 2008-2011 Opscode, Inc.
7
+ # Copyright:: Copyright 2008-2015 Chef Software, Inc.
8
8
  # License:: Apache License, Version 2.0
9
9
  #
10
10
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -450,7 +450,11 @@ class Chef
450
450
  end
451
451
  relative_search_path.map {|relative_path| File.join(segment.to_s, relative_path)}
452
452
  else
453
- [File.join(segment, path)]
453
+ if segment.to_sym == :root_files
454
+ [path]
455
+ else
456
+ [File.join(segment, path)]
457
+ end
454
458
  end
455
459
  end
456
460
  private :preferences_for_path
@@ -144,7 +144,7 @@ class Chef
144
144
  def save
145
145
  begin
146
146
  if Chef::Config[:why_run]
147
- Chef::Log.warn("In whyrun mode, so NOT performing data bag save.")
147
+ Chef::Log.warn("In why-run mode, so NOT performing data bag save.")
148
148
  else
149
149
  create
150
150
  end
@@ -170,7 +170,7 @@ class Chef
170
170
  r = chef_server_rest
171
171
  begin
172
172
  if Chef::Config[:why_run]
173
- Chef::Log.warn("In whyrun mode, so NOT performing data bag item save.")
173
+ Chef::Log.warn("In why-run mode, so NOT performing data bag item save.")
174
174
  else
175
175
  r.put_rest("data/#{data_bag}/#{item_id}", self)
176
176
  end
@@ -38,7 +38,11 @@ class Chef
38
38
  end
39
39
 
40
40
  def generate_checksum(file)
41
- checksum_file(file, OpenSSL::Digest::SHA256.new)
41
+ if file.is_a?(StringIO)
42
+ checksum_io(file, OpenSSL::Digest::SHA256.new)
43
+ else
44
+ checksum_file(file, OpenSSL::Digest::SHA256.new)
45
+ end
42
46
  end
43
47
 
44
48
  def self.generate_md5_checksum_for_file(*args)
@@ -0,0 +1,57 @@
1
+ #
2
+ # Author:: John Keiser (<jkeiser@chef.io>)
3
+ # Copyright:: Copyright (c) 2015 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
+ class Chef
20
+ module DSL
21
+ # Lazy activation for the chef-provisioning gem. Specifically, we set up methods for
22
+ # each resource and DSL method in chef-provisioning which, when invoked, will
23
+ # require 'chef-provisioning' (which will define the actual method) and then call the
24
+ # method chef-provisioning defined.
25
+ module ChefProvisioning
26
+ %w(
27
+ add_machine_options
28
+ current_image_options
29
+ current_machine_options
30
+ load_balancer
31
+ machine_batch
32
+ machine_execute
33
+ machine_file
34
+ machine_image
35
+ machine
36
+ with_driver
37
+ with_image_options
38
+ with_machine_options
39
+ ).each do |method_name|
40
+ eval(<<-EOM, binding, __FILE__, __LINE__+1)
41
+ def #{method_name}(*args, &block)
42
+ Chef::DSL::ChefProvisioning.load_chef_provisioning
43
+ self.#{method_name}(*args, &block)
44
+ end
45
+ EOM
46
+ end
47
+
48
+ def self.load_chef_provisioning
49
+ # Remove all chef-provisioning methods; they will be added back in by chef-provisioning
50
+ public_instance_methods(false).each do |method_name|
51
+ remove_method(method_name)
52
+ end
53
+ require 'chef/provisioning'
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,64 @@
1
+ #
2
+ # Author:: John Keiser (<jkeiser@chef.io>)
3
+ # Copyright:: Copyright (c) 2015 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
+ class Chef
20
+ module DSL
21
+ # Lazy activation for the cheffish gem. Specifically, we set up methods for
22
+ # each resource and DSL method in cheffish which, when invoked, will
23
+ # require 'cheffish' (which will define the actual method) and then call the
24
+ # method cheffish defined.
25
+ module Cheffish
26
+ %w(
27
+ chef_acl
28
+ chef_client
29
+ chef_container
30
+ chef_data_bag
31
+ chef_environment
32
+ chef_group
33
+ chef_mirror
34
+ chef_node
35
+ chef_organization
36
+ chef_role
37
+ chef_user
38
+ private_key
39
+ public_key
40
+ with_chef_data_bag
41
+ with_chef_environment
42
+ with_chef_data_bag_item_encryption
43
+ with_chef_server
44
+ with_chef_local_server
45
+ get_private_key
46
+ ).each do |method_name|
47
+ eval(<<-EOM, binding, __FILE__, __LINE__+1)
48
+ def #{method_name}(*args, &block)
49
+ Chef::DSL::Cheffish.load_cheffish
50
+ self.#{method_name}(*args, &block)
51
+ end
52
+ EOM
53
+ end
54
+
55
+ def self.load_cheffish
56
+ # Remove all cheffish methods; they will be added back in by cheffish
57
+ public_instance_methods(false).each do |method_name|
58
+ remove_method(method_name)
59
+ end
60
+ require 'cheffish'
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,108 @@
1
+ #--
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Author:: Christopher Walters (<cw@opscode.com>)
4
+ # Copyright:: Copyright (c) 2008, 2009-2015 Chef Software, 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/exceptions'
21
+
22
+ class Chef
23
+ module DSL
24
+ module DeclareResource
25
+
26
+ #
27
+ # Instantiates a resource (via #build_resource), then adds it to the
28
+ # resource collection. Note that resource classes are looked up directly,
29
+ # so this will create the resource you intended even if the method name
30
+ # corresponding to that resource has been overridden.
31
+ #
32
+ # @param type [Symbol] The type of resource (e.g. `:file` or `:package`)
33
+ # @param name [String] The name of the resource (e.g. '/x/y.txt' or 'apache2')
34
+ # @param created_at [String] The caller of the resource. Use `caller[0]`
35
+ # to get the caller of your function. Defaults to the caller of this
36
+ # function.
37
+ # @param resource_attrs_block A block that lets you set attributes of the
38
+ # resource (it is instance_eval'd on the resource instance).
39
+ #
40
+ # @return [Chef::Resource] The new resource.
41
+ #
42
+ # @example
43
+ # declare_resource(:file, '/x/y.txy', caller[0]) do
44
+ # action :delete
45
+ # end
46
+ # # Equivalent to
47
+ # file '/x/y.txt' do
48
+ # action :delete
49
+ # end
50
+ #
51
+ def declare_resource(type, name, created_at=nil, run_context: self.run_context, create_if_missing: false, &resource_attrs_block)
52
+ created_at ||= caller[0]
53
+
54
+ if create_if_missing
55
+ begin
56
+ resource = run_context.resource_collection.find(type => name)
57
+ return resource
58
+ rescue Chef::Exceptions::ResourceNotFound
59
+ end
60
+ end
61
+
62
+ resource = build_resource(type, name, created_at, &resource_attrs_block)
63
+
64
+ run_context.resource_collection.insert(resource, resource_type: type, instance_name: name)
65
+ resource
66
+ end
67
+
68
+ #
69
+ # Instantiate a resource of the given +type+ with the given +name+ and
70
+ # attributes as given in the +resource_attrs_block+.
71
+ #
72
+ # The resource is NOT added to the resource collection.
73
+ #
74
+ # @param type [Symbol] The type of resource (e.g. `:file` or `:package`)
75
+ # @param name [String] The name of the resource (e.g. '/x/y.txt' or 'apache2')
76
+ # @param created_at [String] The caller of the resource. Use `caller[0]`
77
+ # to get the caller of your function. Defaults to the caller of this
78
+ # function.
79
+ # @param resource_attrs_block A block that lets you set attributes of the
80
+ # resource (it is instance_eval'd on the resource instance).
81
+ #
82
+ # @return [Chef::Resource] The new resource.
83
+ #
84
+ # @example
85
+ # build_resource(:file, '/x/y.txy', caller[0]) do
86
+ # action :delete
87
+ # end
88
+ #
89
+ def build_resource(type, name, created_at=nil, run_context: self.run_context, &resource_attrs_block)
90
+ created_at ||= caller[0]
91
+ Thread.exclusive do
92
+ require 'chef/resource_builder' unless defined?(Chef::ResourceBuilder)
93
+ end
94
+
95
+ Chef::ResourceBuilder.new(
96
+ type: type,
97
+ name: name,
98
+ created_at: created_at,
99
+ params: @params,
100
+ run_context: run_context,
101
+ cookbook_name: cookbook_name,
102
+ recipe_name: recipe_name,
103
+ enclosing_provider: self.is_a?(Chef::Provider) ? self : nil
104
+ ).build(&resource_attrs_block)
105
+ end
106
+ end
107
+ end
108
+ end
@@ -50,7 +50,7 @@ class Chef
50
50
 
51
51
  def value_for_node(node)
52
52
  platform, version = node[:platform].to_s, node[:platform_version].to_s
53
- # Check if we match a version constraint via Chef::VersionConstraint and Chef::Version::Platform
53
+ # Check if we match a version constraint via Chef::VersionConstraint::Platform and Chef::Version::Platform
54
54
  matched_value = match_versions(node)
55
55
  if @values.key?(platform) && @values[platform].key?(version)
56
56
  @values[platform][version]
@@ -76,11 +76,11 @@ class Chef
76
76
  keys = @values[platform].keys
77
77
  keys.each do |k|
78
78
  begin
79
- if Chef::VersionConstraint.new(k).include?(node_version)
79
+ if Chef::VersionConstraint::Platform.new(k).include?(node_version)
80
80
  key_matches << k
81
81
  end
82
82
  rescue Chef::Exceptions::InvalidVersionConstraint => e
83
- Chef::Log.debug "Caught InvalidVersionConstraint. This means that a key in value_for_platform cannot be interpreted as a Chef::VersionConstraint."
83
+ Chef::Log.debug "Caught InvalidVersionConstraint. This means that a key in value_for_platform cannot be interpreted as a Chef::VersionConstraint::Platform."
84
84
  Chef::Log.debug(e)
85
85
  end
86
86
  end
@@ -1,7 +1,7 @@
1
1
  #--
2
2
  # Author:: Adam Jacob (<adam@opscode.com>)
3
3
  # Author:: Christopher Walters (<cw@opscode.com>)
4
- # Copyright:: Copyright (c) 2008, 2009 Opscode, Inc.
4
+ # Copyright:: Copyright (c) 2008, 2009-2015 Chef Software, Inc.
5
5
  # License:: Apache License, Version 2.0
6
6
  #
7
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,12 +17,12 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
- require 'chef/mixin/convert_to_class_name'
21
20
  require 'chef/exceptions'
22
21
  require 'chef/mixin/shell_out'
23
22
  require 'chef/mixin/powershell_out'
24
23
  require 'chef/dsl/resources'
25
24
  require 'chef/dsl/definitions'
25
+ require 'chef/dsl/declare_resource'
26
26
 
27
27
  class Chef
28
28
  module DSL
@@ -37,76 +37,7 @@ class Chef
37
37
 
38
38
  include Chef::DSL::Resources
39
39
  include Chef::DSL::Definitions
40
-
41
- #
42
- # Instantiates a resource (via #build_resource), then adds it to the
43
- # resource collection. Note that resource classes are looked up directly,
44
- # so this will create the resource you intended even if the method name
45
- # corresponding to that resource has been overridden.
46
- #
47
- # @param type [Symbol] The type of resource (e.g. `:file` or `:package`)
48
- # @param name [String] The name of the resource (e.g. '/x/y.txt' or 'apache2')
49
- # @param created_at [String] The caller of the resource. Use `caller[0]`
50
- # to get the caller of your function. Defaults to the caller of this
51
- # function.
52
- # @param resource_attrs_block A block that lets you set attributes of the
53
- # resource (it is instance_eval'd on the resource instance).
54
- #
55
- # @return [Chef::Resource] The new resource.
56
- #
57
- # @example
58
- # declare_resource(:file, '/x/y.txy', caller[0]) do
59
- # action :delete
60
- # end
61
- # # Equivalent to
62
- # file '/x/y.txt' do
63
- # action :delete
64
- # end
65
- #
66
- def declare_resource(type, name, created_at=nil, &resource_attrs_block)
67
- created_at ||= caller[0]
68
-
69
- resource = build_resource(type, name, created_at, &resource_attrs_block)
70
-
71
- run_context.resource_collection.insert(resource, resource_type: type, instance_name: name)
72
- resource
73
- end
74
-
75
- #
76
- # Instantiate a resource of the given +type+ with the given +name+ and
77
- # attributes as given in the +resource_attrs_block+.
78
- #
79
- # The resource is NOT added to the resource collection.
80
- #
81
- # @param type [Symbol] The type of resource (e.g. `:file` or `:package`)
82
- # @param name [String] The name of the resource (e.g. '/x/y.txt' or 'apache2')
83
- # @param created_at [String] The caller of the resource. Use `caller[0]`
84
- # to get the caller of your function. Defaults to the caller of this
85
- # function.
86
- # @param resource_attrs_block A block that lets you set attributes of the
87
- # resource (it is instance_eval'd on the resource instance).
88
- #
89
- # @return [Chef::Resource] The new resource.
90
- #
91
- # @example
92
- # build_resource(:file, '/x/y.txy', caller[0]) do
93
- # action :delete
94
- # end
95
- #
96
- def build_resource(type, name, created_at=nil, &resource_attrs_block)
97
- created_at ||= caller[0]
98
-
99
- Chef::ResourceBuilder.new(
100
- type: type,
101
- name: name,
102
- created_at: created_at,
103
- params: @params,
104
- run_context: run_context,
105
- cookbook_name: cookbook_name,
106
- recipe_name: recipe_name,
107
- enclosing_provider: self.is_a?(Chef::Provider) ? self : nil
108
- ).build(&resource_attrs_block)
109
- end
40
+ include Chef::DSL::DeclareResource
110
41
 
111
42
  def resource_class_for(snake_case_name)
112
43
  Chef::Resource.resource_for_node(snake_case_name, run_context.node)
@@ -196,7 +127,6 @@ class Chef
196
127
  end
197
128
 
198
129
  # Avoid circular references for things that are only used in instance methods
199
- require 'chef/resource_builder'
200
130
  require 'chef/resource'
201
131
 
202
132
  # **DEPRECATED**
@@ -1,3 +1,23 @@
1
+ #
2
+ # Author:: John Keiser <jkeiser@chef.io>
3
+ # Copyright:: Copyright (c) 2015 Chef Software, 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
+ require 'chef/dsl/cheffish'
19
+ require 'chef/dsl/chef_provisioning'
20
+
1
21
  class Chef
2
22
  module DSL
3
23
  #
@@ -7,6 +27,11 @@ class Chef
7
27
  #
8
28
  # @api private
9
29
  module Resources
30
+ # Include the lazy loaders for cheffish and chef-provisioning, so that the
31
+ # resource DSL is there but the gems aren't activated yet.
32
+ include Chef::DSL::Cheffish
33
+ include Chef::DSL::ChefProvisioning
34
+
10
35
  def self.add_resource_dsl(dsl_name)
11
36
  begin
12
37
  module_eval(<<-EOM, __FILE__, __LINE__+1)
@@ -24,7 +49,8 @@ class Chef
24
49
  end
25
50
  end
26
51
  def self.remove_resource_dsl(dsl_name)
27
- remove_method(dsl_name) if method_defined?(dsl_name)
52
+ remove_method(dsl_name)
53
+ rescue NameError
28
54
  end
29
55
  end
30
56
  end