chef 11.18.12 → 12.0.0.alpha.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (307) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +10 -0
  3. data/README.md +1 -1
  4. data/distro/common/html/_sources/index.txt +5 -2
  5. data/distro/common/html/_sources/knife_serve.txt +19 -0
  6. data/distro/common/html/_sources/knife_ssl_check.txt +2 -2
  7. data/distro/common/html/_sources/knife_ssl_fetch.txt +2 -2
  8. data/distro/common/html/_static/basic.css +1 -1
  9. data/distro/common/html/_static/doctools.js +1 -1
  10. data/distro/common/html/_static/searchtools.js +1 -1
  11. data/distro/common/html/_static/websupport.js +1 -1
  12. data/distro/common/html/ctl_chef_client.html +19 -9
  13. data/distro/common/html/ctl_chef_server.html +7 -1
  14. data/distro/common/html/ctl_chef_shell.html +3 -4
  15. data/distro/common/html/ctl_chef_solo.html +12 -7
  16. data/distro/common/html/index.html +19 -12
  17. data/distro/common/html/knife.html +1 -2
  18. data/distro/common/html/knife_bootstrap.html +16 -5
  19. data/distro/common/html/knife_client.html +8 -5
  20. data/distro/common/html/knife_common_options.html +11 -12
  21. data/distro/common/html/knife_configure.html +2 -3
  22. data/distro/common/html/knife_cookbook.html +16 -17
  23. data/distro/common/html/knife_cookbook_site.html +19 -18
  24. data/distro/common/html/knife_data_bag.html +6 -7
  25. data/distro/common/html/knife_delete.html +2 -3
  26. data/distro/common/html/knife_deps.html +2 -3
  27. data/distro/common/html/knife_diff.html +3 -4
  28. data/distro/common/html/knife_download.html +6 -7
  29. data/distro/common/html/knife_edit.html +0 -1
  30. data/distro/common/html/knife_environment.html +3 -4
  31. data/distro/common/html/knife_exec.html +0 -1
  32. data/distro/common/html/knife_index_rebuild.html +0 -1
  33. data/distro/common/html/knife_list.html +5 -6
  34. data/distro/common/html/knife_node.html +13 -6
  35. data/distro/common/html/knife_raw.html +0 -1
  36. data/distro/common/html/knife_recipe_list.html +0 -1
  37. data/distro/common/html/knife_role.html +1 -2
  38. data/distro/common/html/knife_search.html +2 -3
  39. data/distro/common/html/knife_serve.html +79 -0
  40. data/distro/common/html/knife_show.html +1 -2
  41. data/distro/common/html/knife_ssh.html +2 -3
  42. data/distro/common/html/knife_ssl_check.html +12 -9
  43. data/distro/common/html/knife_ssl_fetch.html +9 -10
  44. data/distro/common/html/knife_status.html +2 -3
  45. data/distro/common/html/knife_tag.html +0 -1
  46. data/distro/common/html/knife_upload.html +3 -4
  47. data/distro/common/html/knife_user.html +2 -3
  48. data/distro/common/html/knife_using.html +0 -1
  49. data/distro/common/html/knife_xargs.html +3 -4
  50. data/distro/common/html/search.html +0 -1
  51. data/distro/common/html/searchindex.js +1 -1
  52. data/lib/chef/api_client.rb +1 -1
  53. data/lib/chef/application.rb +24 -67
  54. data/lib/chef/application/client.rb +1 -1
  55. data/lib/chef/application/knife.rb +1 -1
  56. data/lib/chef/chef_fs/chef_fs_data_store.rb +2 -3
  57. data/lib/chef/chef_fs/command_line.rb +2 -3
  58. data/lib/chef/chef_fs/data_handler/group_data_handler.rb +1 -5
  59. data/lib/chef/chef_fs/file_system/acl_entry.rb +1 -2
  60. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +1 -2
  61. data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +2 -2
  62. data/lib/chef/chef_fs/file_system/rest_list_dir.rb +2 -3
  63. data/lib/chef/chef_fs/file_system/rest_list_entry.rb +4 -5
  64. data/lib/chef/config.rb +26 -2
  65. data/lib/chef/config_fetcher.rb +1 -1
  66. data/lib/chef/cookbook/cookbook_version_loader.rb +4 -4
  67. data/lib/chef/cookbook/metadata.rb +1 -1
  68. data/lib/chef/cookbook/synchronizer.rb +50 -8
  69. data/lib/chef/cookbook_uploader.rb +9 -23
  70. data/lib/chef/cookbook_version.rb +3 -2
  71. data/lib/chef/data_bag.rb +1 -1
  72. data/lib/chef/data_bag_item.rb +1 -1
  73. data/lib/chef/dsl/recipe.rb +1 -14
  74. data/lib/chef/encrypted_data_bag_item/decryptor.rb +3 -3
  75. data/lib/chef/environment.rb +1 -1
  76. data/lib/chef/exceptions.rb +2 -24
  77. data/lib/chef/file_content_management/tempfile.rb +8 -1
  78. data/lib/chef/formatters/base.rb +0 -7
  79. data/lib/chef/http.rb +12 -19
  80. data/lib/chef/http/json_input.rb +12 -1
  81. data/lib/chef/json_compat.rb +45 -64
  82. data/lib/chef/knife.rb +2 -5
  83. data/lib/chef/knife/bootstrap.rb +2 -2
  84. data/lib/chef/knife/bootstrap/archlinux-gems.erb +2 -2
  85. data/lib/chef/knife/bootstrap/centos5-gems.erb +2 -2
  86. data/lib/chef/knife/bootstrap/chef-aix.erb +2 -2
  87. data/lib/chef/knife/bootstrap/chef-full.erb +2 -2
  88. data/lib/chef/knife/bootstrap/fedora13-gems.erb +2 -2
  89. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +2 -2
  90. data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +2 -2
  91. data/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb +2 -2
  92. data/lib/chef/knife/cookbook_site_download.rb +1 -1
  93. data/lib/chef/knife/cookbook_site_install.rb +10 -34
  94. data/lib/chef/knife/cookbook_site_list.rb +1 -1
  95. data/lib/chef/knife/cookbook_site_search.rb +1 -1
  96. data/lib/chef/knife/cookbook_site_share.rb +3 -3
  97. data/lib/chef/knife/cookbook_site_show.rb +3 -3
  98. data/lib/chef/knife/cookbook_site_unshare.rb +1 -1
  99. data/lib/chef/knife/cookbook_upload.rb +1 -1
  100. data/lib/chef/knife/core/subcommand_loader.rb +0 -24
  101. data/lib/chef/knife/core/ui.rb +8 -7
  102. data/lib/chef/knife/deps.rb +2 -3
  103. data/lib/chef/knife/serve.rb +2 -1
  104. data/lib/chef/local_mode.rb +105 -0
  105. data/lib/chef/mixin/file_class.rb +1 -4
  106. data/lib/chef/mixin/shell_out.rb +15 -0
  107. data/lib/chef/mixin/windows_architecture_helper.rb +0 -16
  108. data/lib/chef/node.rb +1 -1
  109. data/lib/chef/platform/query_helpers.rb +1 -5
  110. data/lib/chef/policy_builder/expand_node_object.rb +3 -0
  111. data/lib/chef/provider.rb +2 -0
  112. data/lib/chef/provider/cookbook_file.rb +0 -1
  113. data/lib/chef/provider/deploy.rb +0 -1
  114. data/lib/chef/provider/deploy/revision.rb +1 -1
  115. data/lib/chef/provider/env.rb +10 -25
  116. data/lib/chef/provider/env/windows.rb +23 -10
  117. data/lib/chef/provider/execute.rb +0 -3
  118. data/lib/chef/provider/file.rb +0 -3
  119. data/lib/chef/provider/git.rb +0 -6
  120. data/lib/chef/provider/group/dscl.rb +9 -27
  121. data/lib/chef/provider/group/gpasswd.rb +0 -3
  122. data/lib/chef/provider/group/groupmod.rb +0 -4
  123. data/lib/chef/provider/group/suse.rb +0 -3
  124. data/lib/chef/provider/group/usermod.rb +0 -3
  125. data/lib/chef/provider/link.rb +22 -5
  126. data/lib/chef/provider/log.rb +15 -4
  127. data/lib/chef/provider/mdadm.rb +0 -3
  128. data/lib/chef/provider/mount/mount.rb +0 -2
  129. data/lib/chef/provider/mount/solaris.rb +0 -2
  130. data/lib/chef/provider/package.rb +0 -1
  131. data/lib/chef/provider/package/apt.rb +0 -3
  132. data/lib/chef/provider/package/dpkg.rb +0 -1
  133. data/lib/chef/provider/package/easy_install.rb +0 -4
  134. data/lib/chef/provider/package/freebsd/base.rb +0 -3
  135. data/lib/chef/provider/package/freebsd/pkgng.rb +0 -2
  136. data/lib/chef/provider/package/freebsd/port.rb +0 -2
  137. data/lib/chef/provider/package/ips.rb +0 -3
  138. data/lib/chef/provider/package/paludis.rb +0 -5
  139. data/lib/chef/provider/package/portage.rb +0 -2
  140. data/lib/chef/provider/package/rpm.rb +2 -4
  141. data/lib/chef/provider/package/rubygems.rb +0 -4
  142. data/lib/chef/provider/package/smartos.rb +0 -3
  143. data/lib/chef/provider/package/windows/msi.rb +0 -2
  144. data/lib/chef/provider/package/yum.rb +0 -4
  145. data/lib/chef/provider/package/zypper.rb +0 -3
  146. data/lib/chef/provider/registry_key.rb +0 -2
  147. data/lib/chef/provider/remote_directory.rb +0 -1
  148. data/lib/chef/provider/remote_file.rb +0 -1
  149. data/lib/chef/provider/remote_file/cache_control_data.rb +1 -3
  150. data/lib/chef/provider/remote_file/content.rb +0 -1
  151. data/lib/chef/provider/remote_file/fetcher.rb +0 -2
  152. data/lib/chef/provider/remote_file/ftp.rb +0 -1
  153. data/lib/chef/provider/resource_update.rb +0 -3
  154. data/lib/chef/provider/service/freebsd.rb +0 -3
  155. data/lib/chef/provider/service/init.rb +0 -3
  156. data/lib/chef/provider/service/macosx.rb +0 -1
  157. data/lib/chef/provider/service/redhat.rb +0 -2
  158. data/lib/chef/provider/service/simple.rb +0 -3
  159. data/lib/chef/provider/service/solaris.rb +0 -3
  160. data/lib/chef/provider/service/systemd.rb +15 -14
  161. data/lib/chef/provider/service/windows.rb +0 -3
  162. data/lib/chef/provider/subversion.rb +0 -2
  163. data/lib/chef/provider/template.rb +0 -2
  164. data/lib/chef/provider/template/content.rb +0 -1
  165. data/lib/chef/provider/user/dscl.rb +156 -549
  166. data/lib/chef/provider/user/solaris.rb +0 -1
  167. data/lib/chef/provider/user/useradd.rb +0 -3
  168. data/lib/chef/provider/whyrun_safe_ruby_block.rb +1 -1
  169. data/lib/chef/providers.rb +0 -1
  170. data/lib/chef/resource.rb +1 -4
  171. data/lib/chef/resource/freebsd_package.rb +2 -10
  172. data/lib/chef/resource/lwrp_base.rb +1 -12
  173. data/lib/chef/resource/user.rb +0 -18
  174. data/lib/chef/resource_collection.rb +1 -1
  175. data/lib/chef/resource_reporter.rb +10 -10
  176. data/lib/chef/resources.rb +0 -1
  177. data/lib/chef/role.rb +3 -3
  178. data/lib/chef/run_list.rb +1 -1
  179. data/lib/chef/tasks/chef_repo.rake +131 -264
  180. data/lib/chef/user.rb +1 -1
  181. data/lib/chef/util/path_helper.rb +2 -2
  182. data/lib/chef/version.rb +9 -1
  183. data/lib/chef/win32/api/system.rb +0 -9
  184. data/spec/data/bootstrap/test-hints.erb +1 -1
  185. data/spec/data/bootstrap/test.erb +1 -1
  186. data/spec/functional/dsl/reboot_pending_spec.rb +53 -58
  187. data/spec/functional/knife/cookbook_delete_spec.rb +3 -3
  188. data/spec/functional/knife/exec_spec.rb +1 -1
  189. data/spec/functional/mixin/shell_out_spec.rb +48 -0
  190. data/spec/functional/resource/base.rb +0 -10
  191. data/spec/functional/resource/group_spec.rb +1 -5
  192. data/spec/functional/resource/link_spec.rb +8 -0
  193. data/spec/functional/resource/{user/useradd_spec.rb → user_spec.rb} +1 -1
  194. data/spec/integration/knife/chef_fs_data_store_spec.rb +3 -3
  195. data/spec/integration/knife/chef_repo_path_spec.rb +1 -6
  196. data/spec/integration/knife/chef_repository_file_system_spec.rb +1 -1
  197. data/spec/integration/knife/chefignore_spec.rb +1 -1
  198. data/spec/integration/knife/common_options_spec.rb +50 -3
  199. data/spec/integration/knife/cookbook_api_ipv6_spec.rb +1 -1
  200. data/spec/integration/knife/delete_spec.rb +1 -1
  201. data/spec/integration/knife/deps_spec.rb +1 -1
  202. data/spec/integration/knife/diff_spec.rb +3 -3
  203. data/spec/integration/knife/download_spec.rb +3 -3
  204. data/spec/integration/knife/list_spec.rb +1 -1
  205. data/spec/integration/knife/raw_spec.rb +1 -11
  206. data/spec/integration/knife/redirection_spec.rb +1 -1
  207. data/spec/integration/knife/serve_spec.rb +2 -2
  208. data/spec/integration/knife/show_spec.rb +1 -1
  209. data/spec/integration/knife/upload_spec.rb +9 -9
  210. data/spec/spec_helper.rb +0 -9
  211. data/spec/support/pedant/pedant_config.rb +2 -1
  212. data/spec/support/pedant/run_pedant.rb +2 -1
  213. data/spec/support/platform_helpers.rb +5 -24
  214. data/spec/support/shared/integration/integration_helper.rb +2 -1
  215. data/spec/support/shared/matchers.rb +17 -0
  216. data/spec/tiny_server.rb +1 -2
  217. data/spec/unit/api_client_spec.rb +3 -3
  218. data/spec/unit/application_spec.rb +9 -32
  219. data/spec/unit/config_fetcher_spec.rb +1 -1
  220. data/spec/unit/cookbook/metadata_spec.rb +3 -7
  221. data/spec/unit/cookbook/synchronizer_spec.rb +441 -226
  222. data/spec/unit/cookbook_loader_spec.rb +1 -1
  223. data/spec/unit/cookbook_uploader_spec.rb +160 -0
  224. data/spec/unit/cookbook_version_spec.rb +0 -4
  225. data/spec/unit/data_bag_item_spec.rb +1 -5
  226. data/spec/unit/data_bag_spec.rb +1 -5
  227. data/spec/unit/deprecation_spec.rb +1 -1
  228. data/spec/unit/dsl/recipe_spec.rb +12 -0
  229. data/spec/unit/encrypted_data_bag_item_spec.rb +7 -14
  230. data/spec/unit/environment_spec.rb +3 -7
  231. data/spec/unit/exceptions_spec.rb +0 -6
  232. data/spec/unit/http/json_input_spec.rb +128 -0
  233. data/spec/unit/json_compat_spec.rb +17 -58
  234. data/spec/unit/knife/client_create_spec.rb +3 -3
  235. data/spec/unit/knife/configure_client_spec.rb +6 -5
  236. data/spec/unit/knife/cookbook_delete_spec.rb +1 -1
  237. data/spec/unit/knife/cookbook_download_spec.rb +5 -5
  238. data/spec/unit/knife/cookbook_metadata_from_file_spec.rb +1 -0
  239. data/spec/unit/knife/cookbook_metadata_spec.rb +1 -1
  240. data/spec/unit/knife/cookbook_site_download_spec.rb +10 -11
  241. data/spec/unit/knife/cookbook_site_install_spec.rb +116 -161
  242. data/spec/unit/knife/cookbook_site_share_spec.rb +8 -8
  243. data/spec/unit/knife/cookbook_upload_spec.rb +3 -2
  244. data/spec/unit/knife/core/bootstrap_context_spec.rb +3 -3
  245. data/spec/unit/knife/core/subcommand_loader_spec.rb +1 -66
  246. data/spec/unit/knife/data_bag_from_file_spec.rb +2 -1
  247. data/spec/unit/knife/tag_create_spec.rb +3 -3
  248. data/spec/unit/knife/tag_delete_spec.rb +3 -3
  249. data/spec/unit/knife/user_create_spec.rb +1 -1
  250. data/spec/unit/knife_spec.rb +14 -14
  251. data/spec/unit/lwrp_spec.rb +1 -21
  252. data/spec/unit/mixin/shell_out_spec.rb +92 -0
  253. data/spec/unit/node_spec.rb +0 -4
  254. data/spec/unit/platform/query_helpers_spec.rb +0 -23
  255. data/spec/unit/provider/env/windows_spec.rb +34 -70
  256. data/spec/unit/provider/env_spec.rb +11 -76
  257. data/spec/unit/provider/group/dscl_spec.rb +1 -38
  258. data/spec/unit/provider/log_spec.rb +18 -0
  259. data/spec/unit/provider/package/rpm_spec.rb +0 -12
  260. data/spec/unit/provider/remote_file/cache_control_data_spec.rb +1 -1
  261. data/spec/unit/provider/service/systemd_service_spec.rb +44 -27
  262. data/spec/unit/provider/user/dscl_spec.rb +264 -660
  263. data/spec/unit/provider/user/useradd_spec.rb +0 -1
  264. data/spec/unit/provider/whyrun_safe_ruby_block_spec.rb +2 -2
  265. data/spec/unit/provider_spec.rb +12 -0
  266. data/spec/unit/recipe_spec.rb +0 -41
  267. data/spec/unit/resource_collection_spec.rb +1 -5
  268. data/spec/unit/resource_reporter_spec.rb +3 -51
  269. data/spec/unit/resource_spec.rb +3 -14
  270. data/spec/unit/rest_spec.rb +1 -4
  271. data/spec/unit/role_spec.rb +0 -10
  272. data/spec/unit/run_list_spec.rb +1 -5
  273. data/spec/unit/user_spec.rb +1 -5
  274. metadata +20 -100
  275. data/lib/chef/mixin/windows_env_helper.rb +0 -56
  276. data/lib/chef/provider/dsc_script.rb +0 -175
  277. data/lib/chef/resource/dsc_script.rb +0 -126
  278. data/lib/chef/streaming_cookbook_uploader.rb +0 -205
  279. data/lib/chef/util/dsc/configuration_generator.rb +0 -115
  280. data/lib/chef/util/dsc/lcm_output_parser.rb +0 -133
  281. data/lib/chef/util/dsc/local_configuration_manager.rb +0 -141
  282. data/lib/chef/util/dsc/resource_info.rb +0 -26
  283. data/lib/chef/util/powershell/cmdlet.rb +0 -136
  284. data/lib/chef/util/powershell/cmdlet_result.rb +0 -46
  285. data/spec/data/mac_users/10.7-8.plist.xml +0 -559
  286. data/spec/data/mac_users/10.7-8.shadow.xml +0 -11
  287. data/spec/data/mac_users/10.7.plist.xml +0 -559
  288. data/spec/data/mac_users/10.7.shadow.xml +0 -11
  289. data/spec/data/mac_users/10.8.plist.xml +0 -559
  290. data/spec/data/mac_users/10.8.shadow.xml +0 -21
  291. data/spec/data/mac_users/10.9.plist.xml +0 -560
  292. data/spec/data/mac_users/10.9.shadow.xml +0 -21
  293. data/spec/functional/provider/whyrun_safe_ruby_block_spec.rb +0 -51
  294. data/spec/functional/resource/dsc_script_spec.rb +0 -382
  295. data/spec/functional/resource/env_spec.rb +0 -182
  296. data/spec/functional/resource/user/dscl_spec.rb +0 -199
  297. data/spec/functional/util/powershell/cmdlet_spec.rb +0 -113
  298. data/spec/support/lib/chef/resource/zen_follower.rb +0 -46
  299. data/spec/support/shared/shared_examples.rb +0 -10
  300. data/spec/unit/chef_fs/data_handler/group_handler_spec.rb +0 -63
  301. data/spec/unit/formatters/base_spec.rb +0 -48
  302. data/spec/unit/provider/dsc_script_spec.rb +0 -174
  303. data/spec/unit/resource/dsc_script_spec.rb +0 -98
  304. data/spec/unit/util/dsc/configuration_generator_spec.rb +0 -171
  305. data/spec/unit/util/dsc/lcm_output_parser_spec.rb +0 -169
  306. data/spec/unit/util/dsc/local_configuration_manager_spec.rb +0 -139
  307. data/spec/unit/util/powershell/cmdlet_spec.rb +0 -106
@@ -1,115 +0,0 @@
1
- #
2
- # Author:: Adam Edwards (<adamed@getchef.com>)
3
- #
4
- # Copyright:: 2014, Chef Software, Inc.
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/util/powershell/cmdlet'
20
-
21
- class Chef::Util::DSC
22
- class ConfigurationGenerator
23
- def initialize(node, config_directory)
24
- @node = node
25
- @config_directory = config_directory
26
- end
27
-
28
- def configuration_document_from_script_code(code, configuration_flags, shellout_flags)
29
- Chef::Log.debug("DSC: DSC code:\n '#{code}'")
30
- generated_script_path = write_document_generation_script(code, 'chef_dsc')
31
- begin
32
- configuration_document_from_script_path(generated_script_path, 'chef_dsc', configuration_flags, shellout_flags)
33
- ensure
34
- ::FileUtils.rm(generated_script_path)
35
- end
36
- end
37
-
38
- def configuration_document_from_script_path(script_path, configuration_name, configuration_flags, shellout_flags)
39
- validate_configuration_name!(configuration_name)
40
-
41
- document_generation_cmdlet = Chef::Util::Powershell::Cmdlet.new(
42
- @node,
43
- configuration_document_generation_code(script_path, configuration_name))
44
-
45
- merged_configuration_flags = get_merged_configuration_flags!(configuration_flags, configuration_name)
46
-
47
- document_generation_cmdlet.run!(merged_configuration_flags, shellout_flags)
48
- configuration_document_location = find_configuration_document(configuration_name)
49
-
50
- if ! configuration_document_location
51
- raise RuntimeError, "No DSC configuration for '#{configuration_name}' was generated from supplied DSC script"
52
- end
53
-
54
- configuration_document = get_configuration_document(configuration_document_location)
55
- ::FileUtils.rm_rf(configuration_document_location)
56
- configuration_document
57
- end
58
-
59
- protected
60
-
61
- # From PowerShell error help for the Configuration language element:
62
- # Standard names may only contain letters (a-z, A-Z), numbers (0-9), and underscore (_).
63
- # The name may not be null or empty, and should start with a letter.
64
- def validate_configuration_name!(configuration_name)
65
- if !!(configuration_name =~ /\A[A-Za-z]+[_a-zA-Z0-9]*\Z/) == false
66
- raise ArgumentError, 'Configuration `#{configuration_name}` is not a valid PowerShell cmdlet name'
67
- end
68
- end
69
-
70
- def get_merged_configuration_flags!(configuration_flags, configuration_name)
71
- merged_configuration_flags = { :outputpath => configuration_document_directory(configuration_name) }
72
- if configuration_flags
73
- configuration_flags.map do | switch, value |
74
- if merged_configuration_flags.key?(switch.to_s.downcase.to_sym)
75
- raise ArgumentError, "The `flags` attribute for the dsc_script resource contained a command line switch :#{switch.to_s} that is disallowed."
76
- end
77
- merged_configuration_flags[switch.to_s.downcase.to_sym] = value
78
- end
79
- end
80
- merged_configuration_flags
81
- end
82
-
83
- def configuration_code(code, configuration_name)
84
- "$ProgressPreference = 'SilentlyContinue';Configuration '#{configuration_name}'\n{\n\tnode 'localhost'\n{\n\t#{code}\n}}\n"
85
- end
86
-
87
- def configuration_document_generation_code(configuration_script, configuration_name)
88
- ". '#{configuration_script}';#{configuration_name}"
89
- end
90
-
91
- def write_document_generation_script(code, configuration_name)
92
- script_path = "#{@config_directory}/chef_dsc_config.ps1"
93
- ::File.open(script_path, 'wt') do | script |
94
- script.write(configuration_code(code, configuration_name))
95
- end
96
- script_path
97
- end
98
-
99
- def find_configuration_document(configuration_name)
100
- document_directory = configuration_document_directory(configuration_name)
101
- document_file_name = ::Dir.entries(document_directory).find { | path | path =~ /.*.mof/ }
102
- ::File.join(document_directory, document_file_name) if document_file_name
103
- end
104
-
105
- def configuration_document_directory(configuration_name)
106
- ::File.join(@config_directory, configuration_name)
107
- end
108
-
109
- def get_configuration_document(document_path)
110
- ::File.open(document_path, 'rb') do | file |
111
- file.read
112
- end
113
- end
114
- end
115
- end
@@ -1,133 +0,0 @@
1
- #
2
- # Author:: Jay Mundrawala (<jdm@getchef.com>)
3
- #
4
- # Copyright:: 2014, Chef Software, Inc.
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- require 'chef/log'
20
- require 'chef/util/dsc/resource_info'
21
-
22
- class Chef
23
- class Util
24
- class DSC
25
- class LocalConfigurationManager
26
- module Parser
27
- # Parses the output from LCM and returns a list of Chef::Util::DSC::ResourceInfo objects
28
- # that describe how the resources affected the system
29
- #
30
- # Example:
31
- # parse <<-EOF
32
- # What if: [Machine]: LCM: [Start Set ]
33
- # What if: [Machine]: LCM: [Start Resource ] [[File]FileToNotBeThere]
34
- # What if: [Machine]: LCM: [Start Set ] [[File]FileToNotBeThere]
35
- # What if: [C:\ShouldNotExist.txt] removed
36
- # What if: [Machine]: LCM: [End Set ] [[File]FileToNotBeThere] in 0.1 seconds
37
- # What if: [Machine]: LCM: [End Resource ] [[File]FileToNotBeThere]
38
- # What if: [Machine]: LCM: [End Set ]
39
- # EOF
40
- #
41
- # would return
42
- #
43
- # [
44
- # Chef::Util::DSC::ResourceInfo.new(
45
- # '[[File]FileToNotBeThere]',
46
- # true,
47
- # [
48
- # '[[File]FileToNotBeThere]',
49
- # '[C:\Shouldnotexist.txt]',
50
- # '[[File]FileToNotBeThere] in 0.1 seconds'
51
- # ]
52
- # )
53
- # ]
54
- #
55
- def self.parse(lcm_output)
56
- return [] unless lcm_output
57
-
58
- current_resource = Hash.new
59
-
60
- resources = []
61
- lcm_output.lines.each do |line|
62
- op_action, op_type, info = parse_line(line)
63
-
64
- case op_action
65
- when :start
66
- case op_type
67
- when :set
68
- if current_resource[:name]
69
- current_resource[:context] = :logging
70
- current_resource[:logs] = [info]
71
- end
72
- when :resource
73
- if current_resource[:name]
74
- resources.push(current_resource)
75
- end
76
- current_resource = {:name => info}
77
- else
78
- Chef::Log.debug("Ignoring op_action #{op_action}: Read line #{line}")
79
- end
80
- when :end
81
- # Make sure we log the last line
82
- if current_resource[:context] == :logging and info.include? current_resource[:name]
83
- current_resource[:logs].push(info)
84
- end
85
- current_resource[:context] = nil
86
- when :skip
87
- current_resource[:skipped] = true
88
- when :info
89
- if current_resource[:context] == :logging
90
- current_resource[:logs].push(info)
91
- end
92
- end
93
- end
94
-
95
- if current_resource[:name]
96
- resources.push(current_resource)
97
- end
98
-
99
- build_resource_info(resources)
100
- end
101
-
102
- def self.parse_line(line)
103
- if match = line.match(/^.*?:.*?:\s*LCM:\s*\[(.*?)\](.*)/)
104
- # If the line looks like
105
- # What If: [machinename]: LCM: [op_action op_type] message
106
- # extract op_action, op_type, and message
107
- operation, info = match.captures
108
- op_action, op_type = operation.strip.split(' ').map {|m| m.downcase.to_sym}
109
- else
110
- op_action = op_type = :info
111
- if match = line.match(/^.*?:.*?: \s+(.*)/)
112
- info = match.captures[0]
113
- else
114
- info = line
115
- end
116
- end
117
- info.strip! # Because this was formatted for humans
118
- return [op_action, op_type, info]
119
- end
120
- private_class_method :parse_line
121
-
122
- def self.build_resource_info(resources)
123
- resources.map do |r|
124
- Chef::Util::DSC::ResourceInfo.new(r[:name], !r[:skipped], r[:logs])
125
- end
126
- end
127
- private_class_method :build_resource_info
128
-
129
- end
130
- end
131
- end
132
- end
133
- end
@@ -1,141 +0,0 @@
1
- #
2
- # Author:: Adam Edwards (<adamed@getchef.com>)
3
- #
4
- # Copyright:: 2014, Chef Software, Inc.
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/util/powershell/cmdlet'
20
- require 'chef/util/dsc/lcm_output_parser'
21
-
22
- class Chef::Util::DSC
23
- class LocalConfigurationManager
24
- def initialize(node, configuration_path)
25
- @node = node
26
- @configuration_path = configuration_path
27
- clear_execution_time
28
- end
29
-
30
- def test_configuration(configuration_document)
31
- status = run_configuration_cmdlet(configuration_document)
32
- log_what_if_exception(status.stderr) unless status.succeeded?
33
- configuration_update_required?(status.return_value)
34
- end
35
-
36
- def set_configuration(configuration_document)
37
- run_configuration_cmdlet(configuration_document, true)
38
- end
39
-
40
- def last_operation_execution_time_seconds
41
- if @operation_start_time && @operation_end_time
42
- @operation_end_time - @operation_start_time
43
- end
44
- end
45
-
46
- private
47
-
48
- def run_configuration_cmdlet(configuration_document, apply_configuration = false)
49
- Chef::Log.debug("DSC: Calling DSC Local Config Manager to #{apply_configuration ? "set" : "test"} configuration document.")
50
- test_only_parameters = ! apply_configuration ? '-whatif; if (! $?) { exit 1 }' : ''
51
-
52
- start_operation_timing
53
- command_code = lcm_command_code(@configuration_path, test_only_parameters)
54
- status = nil
55
-
56
- begin
57
- save_configuration_document(configuration_document)
58
- cmdlet = ::Chef::Util::Powershell::Cmdlet.new(@node, "#{command_code}")
59
- if apply_configuration
60
- status = cmdlet.run!
61
- else
62
- status = cmdlet.run
63
- end
64
- ensure
65
- end_operation_timing
66
- remove_configuration_document
67
- if last_operation_execution_time_seconds
68
- Chef::Log.debug("DSC: DSC operation completed in #{last_operation_execution_time_seconds} seconds.")
69
- end
70
- end
71
- Chef::Log.debug("DSC: Completed call to DSC Local Config Manager")
72
- status
73
- end
74
-
75
- def lcm_command_code(configuration_path, test_only_parameters)
76
- <<-EOH
77
- $ProgressPreference = 'SilentlyContinue';start-dscconfiguration -path #{@configuration_path} -wait -erroraction 'continue' -force #{test_only_parameters}
78
- EOH
79
- end
80
-
81
- def log_what_if_exception(what_if_exception_output)
82
- if whatif_not_supported?(what_if_exception_output)
83
- # LCM returns an error if any of the resources do not support the opptional What-If
84
- Chef::Log::warn("Received error while testing configuration due to resource not supporting 'WhatIf'")
85
- elsif dsc_module_import_failure?(what_if_exception_output)
86
- Chef::Log::warn("Received error while testing configuration due to a module for an imported resource possibly not being fully installed:\n#{what_if_exception_output.gsub(/\s+/, ' ')}")
87
- else
88
- Chef::Log::warn("Received error while testing configuration:\n#{what_if_exception_output.gsub(/\s+/, ' ')}")
89
- end
90
- end
91
-
92
- def whatif_not_supported?(what_if_exception_output)
93
- !! (what_if_exception_output.gsub(/[\r\n]+/, '').gsub(/\s+/, ' ') =~ /A parameter cannot be found that matches parameter name 'Whatif'/i)
94
- end
95
-
96
- def dsc_module_import_failure?(what_if_output)
97
- !! (what_if_output =~ /\sCimException/ &&
98
- what_if_output =~ /ProviderOperationExecutionFailure/ &&
99
- what_if_output =~ /\smodule\s+is\s+installed/)
100
- end
101
-
102
- def configuration_update_required?(what_if_output)
103
- Chef::Log.debug("DSC: DSC returned the following '-whatif' output from test operation:\n#{what_if_output}")
104
- begin
105
- Parser::parse(what_if_output)
106
- rescue Chef::Util::DSC::LocalConfigurationManager::Parser => e
107
- Chef::Log::warn("Could not parse LCM output: #{e}")
108
- [Chef::Util::DSC::ResourceInfo.new('Unknown DSC Resources', true, ['Unknown changes because LCM output was not parsable.'])]
109
- end
110
- end
111
-
112
- def save_configuration_document(configuration_document)
113
- ::FileUtils.mkdir_p(@configuration_path)
114
- ::File.open(configuration_document_path, 'wb') do | file |
115
- file.write(configuration_document)
116
- end
117
- end
118
-
119
- def remove_configuration_document
120
- ::FileUtils.rm(configuration_document_path)
121
- end
122
-
123
- def configuration_document_path
124
- File.join(@configuration_path,'..mof')
125
- end
126
-
127
- def clear_execution_time
128
- @operation_start_time = nil
129
- @operation_end_time = nil
130
- end
131
-
132
- def start_operation_timing
133
- clear_execution_time
134
- @operation_start_time = Time.now
135
- end
136
-
137
- def end_operation_timing
138
- @operation_end_time = Time.now
139
- end
140
- end
141
- end
@@ -1,26 +0,0 @@
1
-
2
- class Chef
3
- class Util
4
- class DSC
5
- class ResourceInfo
6
- # The name is the text following [Start Set]
7
- attr_reader :name
8
-
9
- # A list of all log messages between [Start Set] and [End Set].
10
- # Each line is an element in the list.
11
- attr_reader :change_log
12
-
13
- def initialize(name, sets, change_log)
14
- @name = name
15
- @sets = sets
16
- @change_log = change_log || []
17
- end
18
-
19
- # Does this resource change the state of the system?
20
- def changes_state?
21
- @sets
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,136 +0,0 @@
1
- #
2
- # Author:: Adam Edwards (<adamed@getchef.com>)
3
- #
4
- # Copyright:: 2014, Chef Software, Inc.
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 'mixlib/shellout'
20
- require 'chef/mixin/windows_architecture_helper'
21
- require 'chef/util/powershell/cmdlet_result'
22
-
23
- class Chef::Util::Powershell
24
- class Cmdlet
25
- def initialize(node, cmdlet, output_format=nil, output_format_options={})
26
- @output_format = output_format
27
- @node = node
28
-
29
- case output_format
30
- when nil
31
- @json_format = false
32
- when :json
33
- @json_format = true
34
- when :text
35
- @json_format = false
36
- when :object
37
- @json_format = true
38
- else
39
- raise ArgumentError, "Invalid output format #{output_format.to_s} specified"
40
- end
41
-
42
- @cmdlet = cmdlet
43
- @output_format_options = output_format_options
44
- end
45
-
46
- attr_reader :output_format
47
-
48
- def run(switches={}, execution_options={}, *arguments)
49
- arguments_string = arguments.join(' ')
50
-
51
- switches_string = command_switches_string(switches)
52
-
53
- json_depth = 5
54
-
55
- if @json_format && @output_format_options.has_key?(:depth)
56
- json_depth = @output_format_options[:depth]
57
- end
58
-
59
- json_command = @json_format ? " | convertto-json -compress -depth #{json_depth}" : ""
60
- command_string = "powershell.exe -executionpolicy bypass -noprofile -noninteractive -command \"trap [Exception] {write-error -exception ($_.Exception.Message);exit 1};#{@cmdlet} #{switches_string} #{arguments_string}#{json_command}\";if ( ! $? ) { exit 1 }"
61
-
62
- augmented_options = {:returns => [0], :live_stream => false}.merge(execution_options)
63
- command = Mixlib::ShellOut.new(command_string, augmented_options)
64
-
65
- os_architecture = "#{ENV['PROCESSOR_ARCHITEW6432']}" == 'AMD64' ? :x86_64 : :i386
66
-
67
- status = nil
68
-
69
- with_os_architecture(@node) do
70
- status = command.run_command
71
- end
72
-
73
- CmdletResult.new(status, @output_format)
74
- end
75
-
76
- def run!(switches={}, execution_options={}, *arguments)
77
- result = run(switches, execution_options, arguments)
78
-
79
- if ! result.succeeded?
80
- raise Chef::Exceptions::PowershellCmdletException, "Powershell Cmdlet failed: #{result.stderr}"
81
- end
82
-
83
- result
84
- end
85
-
86
- protected
87
-
88
- include Chef::Mixin::WindowsArchitectureHelper
89
-
90
- def validate_switch_name!(switch_parameter_name)
91
- if !!(switch_parameter_name.to_s =~ /\A[A-Za-z]+[_a-zA-Z0-9]*\Z/) == false
92
- raise ArgumentError, "`#{switch_parameter_name}` is not a valid PowerShell cmdlet switch parameter name"
93
- end
94
- end
95
-
96
- def escape_parameter_value(parameter_value)
97
- parameter_value.gsub(/(`|'|"|#)/,'`\1')
98
- end
99
-
100
- def escape_string_parameter_value(parameter_value)
101
- "'#{escape_parameter_value(parameter_value)}'"
102
- end
103
-
104
- def command_switches_string(switches)
105
- command_switches = switches.map do | switch_name, switch_value |
106
- if switch_name.class != Symbol
107
- raise ArgumentError, "Invalid type `#{switch_name} `for PowerShell switch '#{switch_name.to_s}'. The switch must be specified as a Symbol'"
108
- end
109
-
110
- validate_switch_name!(switch_name)
111
-
112
- switch_argument = ''
113
- switch_present = true
114
-
115
- case switch_value
116
- when Numeric
117
- switch_argument = switch_value.to_s
118
- when Float
119
- switch_argument = switch_value.to_s
120
- when FalseClass
121
- switch_present = false
122
- when TrueClass
123
- when String
124
- switch_argument = escape_string_parameter_value(switch_value)
125
- else
126
- raise ArgumentError, "Invalid argument type `#{switch_value.class}` specified for PowerShell switch `:#{switch_name.to_s}`. Arguments to PowerShell must be of type `String`, `Numeric`, `Float`, `FalseClass`, or `TrueClass`"
127
- end
128
-
129
- switch_present ? ["-#{switch_name.to_s.downcase}", switch_argument].join(' ').strip : ''
130
- end
131
-
132
- command_switches.join(' ')
133
- end
134
- end
135
- end
136
-