rmm-chef 0.10.0.rc.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (441) hide show
  1. data/LICENSE +201 -0
  2. data/README.rdoc +171 -0
  3. data/bin/chef-client +26 -0
  4. data/bin/chef-solo +25 -0
  5. data/bin/knife +26 -0
  6. data/bin/shef +34 -0
  7. data/distro/README +2 -0
  8. data/distro/arch/etc/conf.d/chef-client.conf +5 -0
  9. data/distro/arch/etc/conf.d/chef-expander.conf +8 -0
  10. data/distro/arch/etc/conf.d/chef-server-webui.conf +10 -0
  11. data/distro/arch/etc/conf.d/chef-server.conf +10 -0
  12. data/distro/arch/etc/conf.d/chef-solr.conf +8 -0
  13. data/distro/arch/etc/rc.d/chef-client +76 -0
  14. data/distro/arch/etc/rc.d/chef-expander +78 -0
  15. data/distro/arch/etc/rc.d/chef-server +78 -0
  16. data/distro/arch/etc/rc.d/chef-server-webui +78 -0
  17. data/distro/arch/etc/rc.d/chef-solr +78 -0
  18. data/distro/common/html/chef-client.8.html +141 -0
  19. data/distro/common/html/chef-expander-cluster.8.html +164 -0
  20. data/distro/common/html/chef-expanderctl.8.html +146 -0
  21. data/distro/common/html/chef-server-webui.8.html +185 -0
  22. data/distro/common/html/chef-server.8.html +182 -0
  23. data/distro/common/html/chef-solo.8.html +191 -0
  24. data/distro/common/html/chef-solr.8.html +163 -0
  25. data/distro/common/html/knife-bootstrap.1.html +241 -0
  26. data/distro/common/html/knife-client.1.html +219 -0
  27. data/distro/common/html/knife-configure.1.html +170 -0
  28. data/distro/common/html/knife-cookbook-site.1.html +239 -0
  29. data/distro/common/html/knife-cookbook.1.html +373 -0
  30. data/distro/common/html/knife-data-bag.1.html +234 -0
  31. data/distro/common/html/knife-environment.1.html +267 -0
  32. data/distro/common/html/knife-exec.1.html +134 -0
  33. data/distro/common/html/knife-index.1.html +125 -0
  34. data/distro/common/html/knife-node.1.html +270 -0
  35. data/distro/common/html/knife-recipe.1.html +92 -0
  36. data/distro/common/html/knife-role.1.html +200 -0
  37. data/distro/common/html/knife-search.1.html +143 -0
  38. data/distro/common/html/knife-ssh.1.html +156 -0
  39. data/distro/common/html/knife-status.1.html +128 -0
  40. data/distro/common/html/knife-tag.1.html +137 -0
  41. data/distro/common/html/knife.1.html +295 -0
  42. data/distro/common/html/shef.1.html +283 -0
  43. data/distro/common/man/man1/knife-bootstrap.1 +189 -0
  44. data/distro/common/man/man1/knife-client.1 +99 -0
  45. data/distro/common/man/man1/knife-configure.1 +88 -0
  46. data/distro/common/man/man1/knife-cookbook-site.1 +137 -0
  47. data/distro/common/man/man1/knife-cookbook.1 +320 -0
  48. data/distro/common/man/man1/knife-data-bag.1 +130 -0
  49. data/distro/common/man/man1/knife-environment.1 +178 -0
  50. data/distro/common/man/man1/knife-exec.1 +46 -0
  51. data/distro/common/man/man1/knife-index.1 +29 -0
  52. data/distro/common/man/man1/knife-node.1 +154 -0
  53. data/distro/common/man/man1/knife-role.1 +88 -0
  54. data/distro/common/man/man1/knife-search.1 +61 -0
  55. data/distro/common/man/man1/knife-ssh.1 +74 -0
  56. data/distro/common/man/man1/knife-status.1 +29 -0
  57. data/distro/common/man/man1/knife-tag.1 +43 -0
  58. data/distro/common/man/man1/knife.1 +251 -0
  59. data/distro/common/man/man1/shef.1 +256 -0
  60. data/distro/common/man/man8/chef-client.8 +84 -0
  61. data/distro/common/man/man8/chef-expander-cluster.8 +97 -0
  62. data/distro/common/man/man8/chef-expanderctl.8 +62 -0
  63. data/distro/common/man/man8/chef-server-webui.8 +155 -0
  64. data/distro/common/man/man8/chef-server.8 +147 -0
  65. data/distro/common/man/man8/chef-solo.8 +158 -0
  66. data/distro/common/man/man8/chef-solr.8 +114 -0
  67. data/distro/common/markdown/README +3 -0
  68. data/distro/common/markdown/man1/knife-bootstrap.mkd +138 -0
  69. data/distro/common/markdown/man1/knife-client.mkd +103 -0
  70. data/distro/common/markdown/man1/knife-configure.mkd +70 -0
  71. data/distro/common/markdown/man1/knife-cookbook-site.mkd +119 -0
  72. data/distro/common/markdown/man1/knife-cookbook.mkd +253 -0
  73. data/distro/common/markdown/man1/knife-data-bag.mkd +117 -0
  74. data/distro/common/markdown/man1/knife-environment.mkd +151 -0
  75. data/distro/common/markdown/man1/knife-exec.mkd +37 -0
  76. data/distro/common/markdown/man1/knife-index.mkd +30 -0
  77. data/distro/common/markdown/man1/knife-node.mkd +147 -0
  78. data/distro/common/markdown/man1/knife-role.mkd +85 -0
  79. data/distro/common/markdown/man1/knife-search.mkd +55 -0
  80. data/distro/common/markdown/man1/knife-ssh.mkd +62 -0
  81. data/distro/common/markdown/man1/knife-status.mkd +36 -0
  82. data/distro/common/markdown/man1/knife-tag.mkd +39 -0
  83. data/distro/common/markdown/man1/knife.mkd +189 -0
  84. data/distro/common/markdown/man1/shef.mkd +189 -0
  85. data/distro/common/markdown/man8/chef-client.mkd +65 -0
  86. data/distro/common/markdown/man8/chef-expander-cluster.mkd +82 -0
  87. data/distro/common/markdown/man8/chef-expanderctl.mkd +58 -0
  88. data/distro/common/markdown/man8/chef-server-webui.mkd +121 -0
  89. data/distro/common/markdown/man8/chef-server.mkd +121 -0
  90. data/distro/common/markdown/man8/chef-solo.mkd +107 -0
  91. data/distro/common/markdown/man8/chef-solr.mkd +85 -0
  92. data/distro/debian/etc/default/chef-client +4 -0
  93. data/distro/debian/etc/default/chef-expander +8 -0
  94. data/distro/debian/etc/default/chef-server +9 -0
  95. data/distro/debian/etc/default/chef-server-webui +9 -0
  96. data/distro/debian/etc/default/chef-solr +8 -0
  97. data/distro/debian/etc/init.d/chef-client +175 -0
  98. data/distro/debian/etc/init.d/chef-expander +176 -0
  99. data/distro/debian/etc/init.d/chef-server +122 -0
  100. data/distro/debian/etc/init.d/chef-server-webui +123 -0
  101. data/distro/debian/etc/init.d/chef-solr +176 -0
  102. data/distro/debian/etc/init/chef-client.conf +17 -0
  103. data/distro/debian/etc/init/chef-expander.conf +17 -0
  104. data/distro/debian/etc/init/chef-server-webui.conf +17 -0
  105. data/distro/debian/etc/init/chef-server.conf +17 -0
  106. data/distro/debian/etc/init/chef-solr.conf +17 -0
  107. data/distro/redhat/etc/init.d/chef-client +106 -0
  108. data/distro/redhat/etc/init.d/chef-expander +104 -0
  109. data/distro/redhat/etc/init.d/chef-server +112 -0
  110. data/distro/redhat/etc/init.d/chef-server-webui +112 -0
  111. data/distro/redhat/etc/init.d/chef-solr +104 -0
  112. data/distro/redhat/etc/logrotate.d/chef-client +8 -0
  113. data/distro/redhat/etc/logrotate.d/chef-expander +8 -0
  114. data/distro/redhat/etc/logrotate.d/chef-server +8 -0
  115. data/distro/redhat/etc/logrotate.d/chef-server-webui +8 -0
  116. data/distro/redhat/etc/logrotate.d/chef-solr +8 -0
  117. data/distro/redhat/etc/sysconfig/chef-client +15 -0
  118. data/distro/redhat/etc/sysconfig/chef-expander +7 -0
  119. data/distro/redhat/etc/sysconfig/chef-server +14 -0
  120. data/distro/redhat/etc/sysconfig/chef-server-webui +14 -0
  121. data/distro/redhat/etc/sysconfig/chef-solr +8 -0
  122. data/lib/chef.rb +40 -0
  123. data/lib/chef/api_client.rb +265 -0
  124. data/lib/chef/application.rb +152 -0
  125. data/lib/chef/application/agent.rb +18 -0
  126. data/lib/chef/application/client.rb +280 -0
  127. data/lib/chef/application/knife.rb +188 -0
  128. data/lib/chef/application/solo.rb +218 -0
  129. data/lib/chef/applications.rb +4 -0
  130. data/lib/chef/certificate.rb +194 -0
  131. data/lib/chef/checksum.rb +182 -0
  132. data/lib/chef/checksum_cache.rb +189 -0
  133. data/lib/chef/client.rb +366 -0
  134. data/lib/chef/config.rb +244 -0
  135. data/lib/chef/cookbook/chefignore.rb +66 -0
  136. data/lib/chef/cookbook/cookbook_collection.rb +45 -0
  137. data/lib/chef/cookbook/cookbook_version_loader.rb +173 -0
  138. data/lib/chef/cookbook/file_system_file_vendor.rb +56 -0
  139. data/lib/chef/cookbook/file_vendor.rb +48 -0
  140. data/lib/chef/cookbook/metadata.rb +629 -0
  141. data/lib/chef/cookbook/remote_file_vendor.rb +87 -0
  142. data/lib/chef/cookbook/syntax_check.rb +136 -0
  143. data/lib/chef/cookbook_loader.rb +103 -0
  144. data/lib/chef/cookbook_site_streaming_uploader.rb +244 -0
  145. data/lib/chef/cookbook_uploader.rb +151 -0
  146. data/lib/chef/cookbook_version.rb +1071 -0
  147. data/lib/chef/cookbook_version_selector.rb +168 -0
  148. data/lib/chef/couchdb.rb +246 -0
  149. data/lib/chef/daemon.rb +172 -0
  150. data/lib/chef/data_bag.rb +223 -0
  151. data/lib/chef/data_bag_item.rb +267 -0
  152. data/lib/chef/encrypted_data_bag_item.rb +126 -0
  153. data/lib/chef/environment.rb +449 -0
  154. data/lib/chef/exceptions.rb +153 -0
  155. data/lib/chef/file_access_control.rb +144 -0
  156. data/lib/chef/file_cache.rb +218 -0
  157. data/lib/chef/handler.rb +206 -0
  158. data/lib/chef/handler/error_report.rb +40 -0
  159. data/lib/chef/handler/json_file.rb +58 -0
  160. data/lib/chef/index_queue.rb +29 -0
  161. data/lib/chef/index_queue/amqp_client.rb +116 -0
  162. data/lib/chef/index_queue/consumer.rb +76 -0
  163. data/lib/chef/index_queue/indexable.rb +109 -0
  164. data/lib/chef/json_compat.rb +52 -0
  165. data/lib/chef/knife.rb +548 -0
  166. data/lib/chef/knife/bootstrap.rb +228 -0
  167. data/lib/chef/knife/bootstrap/archlinux-gems.erb +48 -0
  168. data/lib/chef/knife/bootstrap/centos5-gems.erb +50 -0
  169. data/lib/chef/knife/bootstrap/fedora13-gems.erb +39 -0
  170. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +32 -0
  171. data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +48 -0
  172. data/lib/chef/knife/client_bulk_delete.rb +43 -0
  173. data/lib/chef/knife/client_create.rb +73 -0
  174. data/lib/chef/knife/client_delete.rb +48 -0
  175. data/lib/chef/knife/client_edit.rb +48 -0
  176. data/lib/chef/knife/client_list.rb +43 -0
  177. data/lib/chef/knife/client_reregister.rb +59 -0
  178. data/lib/chef/knife/client_show.rb +53 -0
  179. data/lib/chef/knife/configure.rb +149 -0
  180. data/lib/chef/knife/configure_client.rb +52 -0
  181. data/lib/chef/knife/cookbook_bulk_delete.rb +72 -0
  182. data/lib/chef/knife/cookbook_create.rb +274 -0
  183. data/lib/chef/knife/cookbook_delete.rb +149 -0
  184. data/lib/chef/knife/cookbook_download.rb +134 -0
  185. data/lib/chef/knife/cookbook_list.rb +53 -0
  186. data/lib/chef/knife/cookbook_metadata.rb +107 -0
  187. data/lib/chef/knife/cookbook_metadata_from_file.rb +44 -0
  188. data/lib/chef/knife/cookbook_show.rb +102 -0
  189. data/lib/chef/knife/cookbook_site_download.rb +70 -0
  190. data/lib/chef/knife/cookbook_site_install.rb +148 -0
  191. data/lib/chef/knife/cookbook_site_list.rb +60 -0
  192. data/lib/chef/knife/cookbook_site_search.rb +51 -0
  193. data/lib/chef/knife/cookbook_site_share.rb +114 -0
  194. data/lib/chef/knife/cookbook_site_show.rb +57 -0
  195. data/lib/chef/knife/cookbook_site_unshare.rb +56 -0
  196. data/lib/chef/knife/cookbook_site_vendor.rb +46 -0
  197. data/lib/chef/knife/cookbook_test.rb +93 -0
  198. data/lib/chef/knife/cookbook_upload.rb +169 -0
  199. data/lib/chef/knife/core/cookbook_scm_repo.rb +149 -0
  200. data/lib/chef/knife/core/generic_presenter.rb +184 -0
  201. data/lib/chef/knife/core/node_editor.rb +127 -0
  202. data/lib/chef/knife/core/node_presenter.rb +103 -0
  203. data/lib/chef/knife/core/object_loader.rb +75 -0
  204. data/lib/chef/knife/core/subcommand_loader.rb +112 -0
  205. data/lib/chef/knife/core/text_formatter.rb +100 -0
  206. data/lib/chef/knife/core/ui.rb +211 -0
  207. data/lib/chef/knife/data_bag_create.rb +95 -0
  208. data/lib/chef/knife/data_bag_delete.rb +51 -0
  209. data/lib/chef/knife/data_bag_edit.rb +94 -0
  210. data/lib/chef/knife/data_bag_from_file.rb +91 -0
  211. data/lib/chef/knife/data_bag_list.rb +46 -0
  212. data/lib/chef/knife/data_bag_show.rb +81 -0
  213. data/lib/chef/knife/environment_create.rb +53 -0
  214. data/lib/chef/knife/environment_delete.rb +45 -0
  215. data/lib/chef/knife/environment_edit.rb +45 -0
  216. data/lib/chef/knife/environment_from_file.rb +50 -0
  217. data/lib/chef/knife/environment_list.rb +42 -0
  218. data/lib/chef/knife/environment_show.rb +46 -0
  219. data/lib/chef/knife/exec.rb +51 -0
  220. data/lib/chef/knife/help.rb +102 -0
  221. data/lib/chef/knife/index_rebuild.rb +50 -0
  222. data/lib/chef/knife/node_bulk_delete.rb +80 -0
  223. data/lib/chef/knife/node_create.rb +50 -0
  224. data/lib/chef/knife/node_delete.rb +47 -0
  225. data/lib/chef/knife/node_edit.rb +72 -0
  226. data/lib/chef/knife/node_from_file.rb +50 -0
  227. data/lib/chef/knife/node_list.rb +46 -0
  228. data/lib/chef/knife/node_run_list_add.rb +67 -0
  229. data/lib/chef/knife/node_run_list_remove.rb +48 -0
  230. data/lib/chef/knife/node_show.rb +68 -0
  231. data/lib/chef/knife/recipe_list.rb +32 -0
  232. data/lib/chef/knife/role_bulk_delete.rb +70 -0
  233. data/lib/chef/knife/role_create.rb +55 -0
  234. data/lib/chef/knife/role_delete.rb +47 -0
  235. data/lib/chef/knife/role_edit.rb +48 -0
  236. data/lib/chef/knife/role_from_file.rb +54 -0
  237. data/lib/chef/knife/role_list.rb +43 -0
  238. data/lib/chef/knife/role_show.rb +54 -0
  239. data/lib/chef/knife/search.rb +138 -0
  240. data/lib/chef/knife/ssh.rb +329 -0
  241. data/lib/chef/knife/status.rb +104 -0
  242. data/lib/chef/knife/tag_create.rb +52 -0
  243. data/lib/chef/knife/tag_delete.rb +60 -0
  244. data/lib/chef/knife/tag_list.rb +47 -0
  245. data/lib/chef/log.rb +39 -0
  246. data/lib/chef/mash.rb +211 -0
  247. data/lib/chef/mixin/check_helper.rb +31 -0
  248. data/lib/chef/mixin/checksum.rb +32 -0
  249. data/lib/chef/mixin/command.rb +221 -0
  250. data/lib/chef/mixin/command/unix.rb +215 -0
  251. data/lib/chef/mixin/command/windows.rb +76 -0
  252. data/lib/chef/mixin/convert_to_class_name.rb +63 -0
  253. data/lib/chef/mixin/create_path.rb +56 -0
  254. data/lib/chef/mixin/deep_merge.rb +225 -0
  255. data/lib/chef/mixin/deprecation.rb +65 -0
  256. data/lib/chef/mixin/from_file.rb +50 -0
  257. data/lib/chef/mixin/language.rb +165 -0
  258. data/lib/chef/mixin/language_include_attribute.rb +61 -0
  259. data/lib/chef/mixin/language_include_recipe.rb +52 -0
  260. data/lib/chef/mixin/params_validate.rb +225 -0
  261. data/lib/chef/mixin/recipe_definition_dsl_core.rb +78 -0
  262. data/lib/chef/mixin/shell_out.rb +41 -0
  263. data/lib/chef/mixin/template.rb +95 -0
  264. data/lib/chef/mixin/xml_escape.rb +140 -0
  265. data/lib/chef/mixins.rb +15 -0
  266. data/lib/chef/monkey_patches/dir.rb +36 -0
  267. data/lib/chef/monkey_patches/numeric.rb +7 -0
  268. data/lib/chef/monkey_patches/object.rb +9 -0
  269. data/lib/chef/monkey_patches/regexp.rb +34 -0
  270. data/lib/chef/monkey_patches/string.rb +28 -0
  271. data/lib/chef/monkey_patches/tempfile.rb +64 -0
  272. data/lib/chef/nil_argument.rb +3 -0
  273. data/lib/chef/node.rb +677 -0
  274. data/lib/chef/node/attribute.rb +487 -0
  275. data/lib/chef/openid_registration.rb +187 -0
  276. data/lib/chef/platform.rb +409 -0
  277. data/lib/chef/provider.rb +124 -0
  278. data/lib/chef/provider/breakpoint.rb +36 -0
  279. data/lib/chef/provider/cookbook_file.rb +100 -0
  280. data/lib/chef/provider/cron.rb +186 -0
  281. data/lib/chef/provider/cron/solaris.rb +195 -0
  282. data/lib/chef/provider/deploy.rb +343 -0
  283. data/lib/chef/provider/deploy/revision.rb +80 -0
  284. data/lib/chef/provider/deploy/timestamped.rb +33 -0
  285. data/lib/chef/provider/directory.rb +72 -0
  286. data/lib/chef/provider/env.rb +152 -0
  287. data/lib/chef/provider/env/windows.rb +75 -0
  288. data/lib/chef/provider/erl_call.rb +101 -0
  289. data/lib/chef/provider/execute.rb +65 -0
  290. data/lib/chef/provider/file.rb +222 -0
  291. data/lib/chef/provider/git.rb +230 -0
  292. data/lib/chef/provider/group.rb +133 -0
  293. data/lib/chef/provider/group/aix.rb +70 -0
  294. data/lib/chef/provider/group/dscl.rb +121 -0
  295. data/lib/chef/provider/group/gpasswd.rb +53 -0
  296. data/lib/chef/provider/group/groupadd.rb +81 -0
  297. data/lib/chef/provider/group/pw.rb +84 -0
  298. data/lib/chef/provider/group/usermod.rb +57 -0
  299. data/lib/chef/provider/group/windows.rb +79 -0
  300. data/lib/chef/provider/http_request.rb +122 -0
  301. data/lib/chef/provider/ifconfig.rb +134 -0
  302. data/lib/chef/provider/link.rb +164 -0
  303. data/lib/chef/provider/log.rb +54 -0
  304. data/lib/chef/provider/mdadm.rb +91 -0
  305. data/lib/chef/provider/mount.rb +114 -0
  306. data/lib/chef/provider/mount/mount.rb +232 -0
  307. data/lib/chef/provider/mount/windows.rb +81 -0
  308. data/lib/chef/provider/ohai.rb +42 -0
  309. data/lib/chef/provider/package.rb +164 -0
  310. data/lib/chef/provider/package/apt.rb +110 -0
  311. data/lib/chef/provider/package/dpkg.rb +112 -0
  312. data/lib/chef/provider/package/easy_install.rb +136 -0
  313. data/lib/chef/provider/package/freebsd.rb +122 -0
  314. data/lib/chef/provider/package/macports.rb +105 -0
  315. data/lib/chef/provider/package/pacman.rb +101 -0
  316. data/lib/chef/provider/package/portage.rb +135 -0
  317. data/lib/chef/provider/package/rpm.rb +101 -0
  318. data/lib/chef/provider/package/rubygems.rb +462 -0
  319. data/lib/chef/provider/package/solaris.rb +127 -0
  320. data/lib/chef/provider/package/yum-dump.py +128 -0
  321. data/lib/chef/provider/package/yum.rb +261 -0
  322. data/lib/chef/provider/package/zypper.rb +127 -0
  323. data/lib/chef/provider/remote_directory.rb +139 -0
  324. data/lib/chef/provider/remote_file.rb +118 -0
  325. data/lib/chef/provider/route.rb +193 -0
  326. data/lib/chef/provider/ruby_block.rb +34 -0
  327. data/lib/chef/provider/script.rb +55 -0
  328. data/lib/chef/provider/service.rb +122 -0
  329. data/lib/chef/provider/service/arch.rb +109 -0
  330. data/lib/chef/provider/service/debian.rb +130 -0
  331. data/lib/chef/provider/service/freebsd.rb +154 -0
  332. data/lib/chef/provider/service/gentoo.rb +53 -0
  333. data/lib/chef/provider/service/init.rb +71 -0
  334. data/lib/chef/provider/service/insserv.rb +52 -0
  335. data/lib/chef/provider/service/redhat.rb +60 -0
  336. data/lib/chef/provider/service/simple.rb +120 -0
  337. data/lib/chef/provider/service/solaris.rb +85 -0
  338. data/lib/chef/provider/service/upstart.rb +192 -0
  339. data/lib/chef/provider/service/windows.rb +146 -0
  340. data/lib/chef/provider/subversion.rb +197 -0
  341. data/lib/chef/provider/template.rb +104 -0
  342. data/lib/chef/provider/user.rb +186 -0
  343. data/lib/chef/provider/user/dscl.rb +280 -0
  344. data/lib/chef/provider/user/pw.rb +113 -0
  345. data/lib/chef/provider/user/useradd.rb +137 -0
  346. data/lib/chef/provider/user/windows.rb +124 -0
  347. data/lib/chef/providers.rb +93 -0
  348. data/lib/chef/recipe.rb +128 -0
  349. data/lib/chef/resource.rb +554 -0
  350. data/lib/chef/resource/apt_package.rb +34 -0
  351. data/lib/chef/resource/bash.rb +33 -0
  352. data/lib/chef/resource/breakpoint.rb +35 -0
  353. data/lib/chef/resource/cookbook_file.rb +45 -0
  354. data/lib/chef/resource/cron.rb +188 -0
  355. data/lib/chef/resource/csh.rb +33 -0
  356. data/lib/chef/resource/deploy.rb +371 -0
  357. data/lib/chef/resource/deploy_revision.rb +40 -0
  358. data/lib/chef/resource/directory.rb +76 -0
  359. data/lib/chef/resource/dpkg_package.rb +34 -0
  360. data/lib/chef/resource/easy_install_package.rb +57 -0
  361. data/lib/chef/resource/env.rb +58 -0
  362. data/lib/chef/resource/erl_call.rb +83 -0
  363. data/lib/chef/resource/execute.rb +127 -0
  364. data/lib/chef/resource/file.rb +99 -0
  365. data/lib/chef/resource/freebsd_package.rb +35 -0
  366. data/lib/chef/resource/gem_package.rb +53 -0
  367. data/lib/chef/resource/git.rb +37 -0
  368. data/lib/chef/resource/group.rb +70 -0
  369. data/lib/chef/resource/http_request.rb +61 -0
  370. data/lib/chef/resource/ifconfig.rb +134 -0
  371. data/lib/chef/resource/link.rb +78 -0
  372. data/lib/chef/resource/log.rb +62 -0
  373. data/lib/chef/resource/macports_package.rb +29 -0
  374. data/lib/chef/resource/mdadm.rb +82 -0
  375. data/lib/chef/resource/mount.rb +135 -0
  376. data/lib/chef/resource/ohai.rb +40 -0
  377. data/lib/chef/resource/package.rb +80 -0
  378. data/lib/chef/resource/pacman_package.rb +33 -0
  379. data/lib/chef/resource/perl.rb +33 -0
  380. data/lib/chef/resource/portage_package.rb +33 -0
  381. data/lib/chef/resource/python.rb +33 -0
  382. data/lib/chef/resource/remote_directory.rb +109 -0
  383. data/lib/chef/resource/remote_file.rb +83 -0
  384. data/lib/chef/resource/route.rb +135 -0
  385. data/lib/chef/resource/rpm_package.rb +34 -0
  386. data/lib/chef/resource/ruby.rb +33 -0
  387. data/lib/chef/resource/ruby_block.rb +40 -0
  388. data/lib/chef/resource/scm.rb +147 -0
  389. data/lib/chef/resource/script.rb +60 -0
  390. data/lib/chef/resource/service.rb +160 -0
  391. data/lib/chef/resource/solaris_package.rb +36 -0
  392. data/lib/chef/resource/subversion.rb +36 -0
  393. data/lib/chef/resource/template.rb +69 -0
  394. data/lib/chef/resource/timestamped_deploy.rb +31 -0
  395. data/lib/chef/resource/user.rb +130 -0
  396. data/lib/chef/resource/yum_package.rb +43 -0
  397. data/lib/chef/resource_collection.rb +217 -0
  398. data/lib/chef/resource_collection/stepable_iterator.rb +124 -0
  399. data/lib/chef/resource_definition.rb +67 -0
  400. data/lib/chef/resource_definition_list.rb +38 -0
  401. data/lib/chef/resources.rb +64 -0
  402. data/lib/chef/rest.rb +392 -0
  403. data/lib/chef/rest/auth_credentials.rb +71 -0
  404. data/lib/chef/rest/cookie_jar.rb +31 -0
  405. data/lib/chef/rest/rest_request.rb +213 -0
  406. data/lib/chef/role.rb +342 -0
  407. data/lib/chef/run_context.rb +126 -0
  408. data/lib/chef/run_list.rb +165 -0
  409. data/lib/chef/run_list/run_list_expansion.rb +193 -0
  410. data/lib/chef/run_list/run_list_item.rb +92 -0
  411. data/lib/chef/run_list/versioned_recipe_list.rb +68 -0
  412. data/lib/chef/run_status.rb +121 -0
  413. data/lib/chef/runner.rb +92 -0
  414. data/lib/chef/sandbox.rb +153 -0
  415. data/lib/chef/search/query.rb +65 -0
  416. data/lib/chef/shef.rb +327 -0
  417. data/lib/chef/shef/ext.rb +569 -0
  418. data/lib/chef/shef/model_wrapper.rb +120 -0
  419. data/lib/chef/shef/shef_rest.rb +28 -0
  420. data/lib/chef/shef/shef_session.rb +284 -0
  421. data/lib/chef/shell_out.rb +250 -0
  422. data/lib/chef/shell_out/unix.rb +223 -0
  423. data/lib/chef/shell_out/windows.rb +98 -0
  424. data/lib/chef/solr_query.rb +187 -0
  425. data/lib/chef/solr_query/lucene.treetop +150 -0
  426. data/lib/chef/solr_query/lucene_nodes.rb +285 -0
  427. data/lib/chef/solr_query/query_transform.rb +65 -0
  428. data/lib/chef/solr_query/solr_http_request.rb +118 -0
  429. data/lib/chef/streaming_cookbook_uploader.rb +201 -0
  430. data/lib/chef/tasks/chef_repo.rake +330 -0
  431. data/lib/chef/util/file_edit.rb +122 -0
  432. data/lib/chef/util/windows.rb +56 -0
  433. data/lib/chef/util/windows/net_group.rb +101 -0
  434. data/lib/chef/util/windows/net_use.rb +121 -0
  435. data/lib/chef/util/windows/net_user.rb +198 -0
  436. data/lib/chef/util/windows/volume.rb +59 -0
  437. data/lib/chef/version.rb +23 -0
  438. data/lib/chef/version_class.rb +70 -0
  439. data/lib/chef/version_constraint.rb +116 -0
  440. data/lib/chef/webui_user.rb +231 -0
  441. metadata +759 -0
@@ -0,0 +1,151 @@
1
+
2
+ require 'set'
3
+ require 'rest_client'
4
+ require 'chef/exceptions'
5
+ require 'chef/knife/cookbook_metadata'
6
+ require 'chef/checksum_cache'
7
+ require 'chef/sandbox'
8
+ require 'chef/cookbook_version'
9
+ require 'chef/cookbook/syntax_check'
10
+ require 'chef/cookbook/file_system_file_vendor'
11
+
12
+ class Chef
13
+ class CookbookUploader
14
+
15
+ def self.work_queue
16
+ @work_queue ||= Queue.new
17
+ end
18
+
19
+ def self.setup_worker_threads
20
+ @worker_threads ||= begin
21
+ work_queue
22
+ (1...10).map do
23
+ Thread.new do
24
+ loop do
25
+ work_queue.pop.call
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ attr_reader :cookbook
33
+ attr_reader :path
34
+ attr_reader :opts
35
+ attr_reader :rest
36
+
37
+ # Creates a new CookbookUploader.
38
+ # ===Arguments:
39
+ # * cookbook::: A Chef::CookbookVersion describing the cookbook to be uploaded
40
+ # * path::: A String or Array of Strings representing the base paths to the
41
+ # cookbook repositories.
42
+ # * opts::: (optional) An options Hash
43
+ # ===Options:
44
+ # * :force indicates that the uploader should set the force option when
45
+ # uploading the cookbook. This allows frozen CookbookVersion
46
+ # documents on the server to be overwritten (otherwise a 409 is
47
+ # returned by the server)
48
+ # * :rest A Chef::REST object that you have configured the way you like it.
49
+ # If you don't provide this, one will be created using the values
50
+ # in Chef::Config.
51
+ def initialize(cookbook, path, opts={})
52
+ @cookbook, @path, @opts = cookbook, path, opts
53
+ @rest = opts[:rest] || Chef::REST.new(Chef::Config[:chef_server_url])
54
+ end
55
+
56
+ def upload_cookbook
57
+ Thread.abort_on_exception = true
58
+ Chef::Log.info("Saving #{cookbook.name}")
59
+
60
+ # Syntax Check
61
+ validate_cookbook
62
+ # generate checksums of cookbook files and create a sandbox
63
+ checksum_files = cookbook.checksums
64
+ checksums = checksum_files.inject({}){|memo,elt| memo[elt.first]=nil ; memo}
65
+ new_sandbox = rest.post_rest("sandboxes", { :checksums => checksums })
66
+
67
+ Chef::Log.info("Uploading files")
68
+
69
+ self.class.setup_worker_threads
70
+
71
+ checksums_to_upload = Set.new
72
+
73
+ # upload the new checksums and commit the sandbox
74
+ new_sandbox['checksums'].each do |checksum, info|
75
+ if info['needs_upload'] == true
76
+ checksums_to_upload << checksum
77
+ Chef::Log.info("Uploading #{checksum_files[checksum]} (checksum hex = #{checksum}) to #{info['url']}")
78
+ self.class.work_queue << uploader_function_for(checksum_files[checksum], checksum, info['url'], checksums_to_upload)
79
+ else
80
+ Chef::Log.debug("#{checksum_files[checksum]} has not changed")
81
+ end
82
+ end
83
+
84
+ until checksums_to_upload.empty?
85
+ sleep 0.1
86
+ end
87
+
88
+ sandbox_url = new_sandbox['uri']
89
+ Chef::Log.debug("Committing sandbox")
90
+ # Retry if S3 is claims a checksum doesn't exist (the eventual
91
+ # in eventual consistency)
92
+ retries = 0
93
+ begin
94
+ rest.put_rest(sandbox_url, {:is_completed => true})
95
+ rescue Net::HTTPServerException => e
96
+ if e.message =~ /^400/ && (retries += 1) <= 5
97
+ sleep 2
98
+ retry
99
+ else
100
+ raise
101
+ end
102
+ end
103
+ # files are uploaded, so save the manifest
104
+ opts[:force] ? cookbook.force_save : cookbook.save
105
+ Chef::Log.info("Upload complete!")
106
+ end
107
+
108
+ def worker_thread(work_queue)
109
+ end
110
+
111
+ def uploader_function_for(file, checksum, url, checksums_to_upload)
112
+ lambda do
113
+ # Checksum is the hexadecimal representation of the md5,
114
+ # but we need the base64 encoding for the content-md5
115
+ # header
116
+ checksum64 = Base64.encode64([checksum].pack("H*")).strip
117
+ timestamp = Time.now.utc.iso8601
118
+ file_contents = File.open(file, "rb") {|f| f.read}
119
+ # TODO - 5/28/2010, cw: make signing and sending the request streaming
120
+ sign_obj = Mixlib::Authentication::SignedHeaderAuth.signing_object(
121
+ :http_method => :put,
122
+ :path => URI.parse(url).path,
123
+ :body => file_contents,
124
+ :timestamp => timestamp,
125
+ :user_id => rest.client_name
126
+ )
127
+ headers = { 'content-type' => 'application/x-binary', 'content-md5' => checksum64, :accept => 'application/json' }
128
+ headers.merge!(sign_obj.sign(OpenSSL::PKey::RSA.new(rest.signing_key)))
129
+
130
+ begin
131
+ RestClient::Resource.new(url, :headers=>headers, :timeout=>1800, :open_timeout=>1800).put(file_contents)
132
+ checksums_to_upload.delete(checksum)
133
+ rescue RestClient::Exception => e
134
+ ui.error("Failed to upload #@cookbook : #{e.message}\n#{e.response.body}")
135
+ raise
136
+ end
137
+ end
138
+ end
139
+
140
+ def validate_cookbook
141
+ syntax_checker = Chef::Cookbook::SyntaxCheck.for_cookbook(cookbook.name, @user_cookbook_path)
142
+ Chef::Log.info("Validating ruby files")
143
+ exit(1) unless syntax_checker.validate_ruby_files
144
+ Chef::Log.info("Validating templates")
145
+ exit(1) unless syntax_checker.validate_templates
146
+ Chef::Log.info("Syntax OK")
147
+ true
148
+ end
149
+
150
+ end
151
+ end
@@ -0,0 +1,1071 @@
1
+ # Author:: Adam Jacob (<adam@opscode.com>)
2
+ # Author:: Nuo Yan (<nuo@opscode.com>)
3
+ # Author:: Christopher Walters (<cw@opscode.com>)
4
+ # Author:: Tim Hinderliter (<tim@opscode.com>)
5
+ # Author:: Seth Falcon (<seth@opscode.com>)
6
+ # Author:: Daniel DeLeo (<dan@opscode.com>)
7
+ # Copyright:: Copyright 2008-2011 Opscode, Inc.
8
+ # License:: Apache License, Version 2.0
9
+ #
10
+ # Licensed under the Apache License, Version 2.0 (the "License");
11
+ # you may not use this file except in compliance with the License.
12
+ # You may obtain a copy of the License at
13
+ #
14
+ # http://www.apache.org/licenses/LICENSE-2.0
15
+ #
16
+ # Unless required by applicable law or agreed to in writing, software
17
+ # distributed under the License is distributed on an "AS IS" BASIS,
18
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ # See the License for the specific language governing permissions and
20
+ # limitations under the License.
21
+
22
+ require 'chef/log'
23
+ require 'chef/client'
24
+ require 'chef/node'
25
+ require 'chef/resource_definition_list'
26
+ require 'chef/recipe'
27
+ require 'chef/cookbook/file_vendor'
28
+ require 'chef/checksum'
29
+ require 'chef/cookbook/metadata'
30
+ require 'chef/version_class'
31
+
32
+ class Chef
33
+
34
+ #== Chef::MinimalCookbookVersion
35
+ # MinimalCookbookVersion is a duck type of CookbookVersion, used
36
+ # internally by Chef Server as an optimization when determining the
37
+ # optimal cookbook set for a chef-client.
38
+ #
39
+ # MinimalCookbookVersion objects contain only enough information to
40
+ # solve the cookbook collection for a given run list. They *do not*
41
+ # contain enough information to generate the response.
42
+ #
43
+ # See also: Chef::CookbookVersionSelector
44
+ class MinimalCookbookVersion
45
+
46
+ include Comparable
47
+
48
+ ID = "id".freeze
49
+ NAME = 'name'.freeze
50
+ KEY = 'key'.freeze
51
+ VERSION = 'version'.freeze
52
+ VALUE = 'value'.freeze
53
+ DEPS = 'deps'.freeze
54
+
55
+ DEPENDENCIES = 'dependencies'.freeze
56
+
57
+ # Loads the full list of cookbooks, using a couchdb view to fetch
58
+ # only the id, name, version, and dependency constraints. This is
59
+ # enough information to solve for the cookbook collection for a
60
+ # given run list. After solving for the cookbook collection, you
61
+ # need to call +load_full_versions_of+ to convert
62
+ # MinimalCookbookVersion objects to their non-minimal counterparts
63
+ def self.load_all(couchdb)
64
+ # Example:
65
+ # {"id"=>"1a806f1c-b409-4d8e-abab-fa414ff5b96d", "key"=>"activemq", "value"=>{"version"=>"0.3.3", "deps"=>{"java"=>">= 0.0.0", "runit"=>">= 0.0.0"}}}
66
+ couchdb ||= Chef::CouchDB.new
67
+ couchdb.get_view("cookbooks", "all_with_version_and_deps")["rows"].map {|params| self.new(params) }
68
+ end
69
+
70
+ # Loads the non-minimal CookbookVersion objects corresponding to
71
+ # +minimal_cookbook_versions+ from couchdb using a bulk GET.
72
+ def self.load_full_versions_of(minimal_cookbook_versions, couchdb)
73
+ database_ids = Array(minimal_cookbook_versions).map {|mcv| mcv.couchdb_id }
74
+ couchdb ||= Chef::CouchDB.new
75
+ couchdb.bulk_get(*database_ids)
76
+ end
77
+
78
+ attr_reader :couchdb_id
79
+ attr_reader :name
80
+ attr_reader :version
81
+ attr_reader :deps
82
+
83
+ def initialize(params)
84
+ @couchdb_id = params[ID]
85
+ @name = params[KEY]
86
+ @version = params[VALUE][VERSION]
87
+ @deps = params[VALUE][DEPS]
88
+ end
89
+
90
+ # Returns the Cookbook::MinimalMetadata object for this cookbook
91
+ # version.
92
+ def metadata
93
+ @metadata ||= Cookbook::MinimalMetadata.new(@name, DEPENDENCIES => @deps)
94
+ end
95
+
96
+ def legit_version
97
+ @legit_version ||= Chef::Version.new(@version)
98
+ end
99
+
100
+ def <=>(o)
101
+ raise Chef::Exceptions::CookbookVersionNameMismatch if self.name != o.name
102
+ raise "Unexpected comparison to #{o}" unless o.respond_to?(:legit_version)
103
+ legit_version <=> o.legit_version
104
+ end
105
+ end
106
+
107
+ # == Chef::CookbookVersion
108
+ # CookbookVersion is a model object encapsulating the data about a Chef
109
+ # cookbook. Chef supports maintaining multiple versions of a cookbook on a
110
+ # single server; each version is represented by a distinct instance of this
111
+ # class.
112
+ #--
113
+ # TODO: timh/cw: 5-24-2010: mutators for files (e.g., recipe_filenames=,
114
+ # recipe_filenames.insert) should dirty the manifest so it gets regenerated.
115
+ class CookbookVersion
116
+ include Chef::IndexQueue::Indexable
117
+ include Comparable
118
+
119
+ COOKBOOK_SEGMENTS = [ :resources, :providers, :recipes, :definitions, :libraries, :attributes, :files, :templates, :root_files ]
120
+
121
+ DESIGN_DOCUMENT = {
122
+ "version" => 8,
123
+ "language" => "javascript",
124
+ "views" => {
125
+ "all" => {
126
+ "map" => <<-EOJS
127
+ function(doc) {
128
+ if (doc.chef_type == "cookbook_version") {
129
+ emit(doc.name, doc);
130
+ }
131
+ }
132
+ EOJS
133
+ },
134
+ "all_id" => {
135
+ "map" => <<-EOJS
136
+ function(doc) {
137
+ if (doc.chef_type == "cookbook_version") {
138
+ emit(doc.name, doc.name);
139
+ }
140
+ }
141
+ EOJS
142
+ },
143
+ "all_with_version" => {
144
+ "map" => <<-EOJS
145
+ function(doc) {
146
+ if (doc.chef_type == "cookbook_version") {
147
+ emit(doc.cookbook_name, doc.version);
148
+ }
149
+ }
150
+ EOJS
151
+ },
152
+ "all_with_version_and_deps" => {
153
+ "map" => <<-JS
154
+ function(doc) {
155
+ if (doc.chef_type == "cookbook_version") {
156
+ emit(doc.cookbook_name, {version: doc.version, deps: doc.metadata.dependencies});
157
+ }
158
+ }
159
+ JS
160
+ },
161
+ "all_latest_version" => {
162
+ "map" => %q@
163
+ function(doc) {
164
+ if (doc.chef_type == "cookbook_version") {
165
+ emit(doc.cookbook_name, doc.version);
166
+ }
167
+ }
168
+ @,
169
+ "reduce" => %q@
170
+ function(keys, values, rereduce) {
171
+ var result = null;
172
+
173
+ for (var idx in values) {
174
+ var value = values[idx];
175
+
176
+ if (idx == 0) {
177
+ result = value;
178
+ continue;
179
+ }
180
+
181
+ var valueParts = value.split('.').map(function(v) { return parseInt(v); });
182
+ var resultParts = result.split('.').map(function(v) { return parseInt(v); });
183
+
184
+ if (valueParts[0] != resultParts[0]) {
185
+ if (valueParts[0] > resultParts[0]) {
186
+ result = value;
187
+ }
188
+ }
189
+ else if (valueParts[1] != resultParts[1]) {
190
+ if (valueParts[1] > resultParts[1]) {
191
+ result = value;
192
+ }
193
+ }
194
+ else if (valueParts[2] != resultParts[2]) {
195
+ if (valueParts[2] > resultParts[2]) {
196
+ result = value;
197
+ }
198
+ }
199
+ }
200
+ return result;
201
+ }
202
+ @
203
+ },
204
+ "all_latest_version_by_id" => {
205
+ "map" => %q@
206
+ function(doc) {
207
+ if (doc.chef_type == "cookbook_version") {
208
+ emit(doc.cookbook_name, {version: doc.version, id:doc._id});
209
+ }
210
+ }
211
+ @,
212
+ "reduce" => %q@
213
+ function(keys, values, rereduce) {
214
+ var result = null;
215
+
216
+ for (var idx in values) {
217
+ var value = values[idx];
218
+
219
+ if (idx == 0) {
220
+ result = value;
221
+ continue;
222
+ }
223
+
224
+ var valueParts = value.version.split('.').map(function(v) { return parseInt(v); });
225
+ var resultParts = result.version.split('.').map(function(v) { return parseInt(v); });
226
+
227
+ if (valueParts[0] != resultParts[0]) {
228
+ if (valueParts[0] > resultParts[0]) {
229
+ result = value;
230
+ }
231
+ }
232
+ else if (valueParts[1] != resultParts[1]) {
233
+ if (valueParts[1] > resultParts[1]) {
234
+ result = value;
235
+ }
236
+ }
237
+ else if (valueParts[2] != resultParts[2]) {
238
+ if (valueParts[2] > resultParts[2]) {
239
+ result = value;
240
+ }
241
+ }
242
+ }
243
+ return result;
244
+ }
245
+ @
246
+ },
247
+ }
248
+ }
249
+
250
+ attr_accessor :root_dir
251
+ attr_accessor :definition_filenames
252
+ attr_accessor :template_filenames
253
+ attr_accessor :file_filenames
254
+ attr_accessor :library_filenames
255
+ attr_accessor :resource_filenames
256
+ attr_accessor :provider_filenames
257
+ attr_accessor :root_filenames
258
+ attr_accessor :name
259
+ attr_accessor :metadata
260
+ attr_accessor :metadata_filenames
261
+ attr_accessor :status
262
+ attr_accessor :couchdb_rev
263
+ attr_accessor :couchdb
264
+
265
+ attr_reader :couchdb_id
266
+
267
+ # attribute_filenames also has a setter that has non-default
268
+ # functionality.
269
+ attr_reader :attribute_filenames
270
+
271
+ # recipe_filenames also has a setter that has non-default
272
+ # functionality.
273
+ attr_reader :recipe_filenames
274
+
275
+ attr_reader :recipe_filenames_by_name
276
+ attr_reader :attribute_filenames_by_short_filename
277
+
278
+ # This is the one and only method that knows how cookbook files'
279
+ # checksums are generated.
280
+ def self.checksum_cookbook_file(filepath)
281
+ Chef::ChecksumCache.generate_md5_checksum_for_file(filepath)
282
+ rescue Errno::ENOENT
283
+ Chef::Log.debug("File #{filepath} does not exist, so there is no checksum to generate")
284
+ nil
285
+ end
286
+
287
+ # Keep track of the filenames that we use in both eager cookbook
288
+ # downloading (during sync_cookbooks) and lazy (during the run
289
+ # itself, through FileVendor). After the run is over, clean up the
290
+ # cache.
291
+ def self.valid_cache_entries
292
+ @valid_cache_entries ||= {}
293
+ end
294
+
295
+ def self.reset_cache_validity
296
+ @valid_cache_entries = nil
297
+ end
298
+
299
+ def self.cache
300
+ Chef::FileCache
301
+ end
302
+
303
+ # Setup a notification to clear the valid_cache_entries when a Chef client
304
+ # run starts
305
+ Chef::Client.when_run_starts do |run_status|
306
+ reset_cache_validity
307
+ end
308
+
309
+ # Synchronizes all the cookbooks from the chef-server.
310
+ #
311
+ # === Returns
312
+ # true:: Always returns true
313
+ def self.sync_cookbooks(cookbook_hash)
314
+ Chef::Log.info("Loading cookbooks [#{cookbook_hash.keys.sort.join(', ')}]")
315
+ Chef::Log.debug("Cookbooks detail: #{cookbook_hash.inspect}")
316
+
317
+ clear_obsoleted_cookbooks(cookbook_hash)
318
+
319
+ # Synchronize each of the node's cookbooks, and add to the
320
+ # valid_cache_entries hash.
321
+ cookbook_hash.values.each do |cookbook|
322
+ sync_cookbook_file_cache(cookbook)
323
+ end
324
+
325
+ true
326
+ end
327
+
328
+ # Iterates over cached cookbooks' files, removing files belonging to
329
+ # cookbooks that don't appear in +cookbook_hash+
330
+ def self.clear_obsoleted_cookbooks(cookbook_hash)
331
+ # Remove all cookbooks no longer relevant to this node
332
+ cache.find(File.join(%w{cookbooks ** *})).each do |cache_file|
333
+ cache_file =~ /^cookbooks\/([^\/]+)\//
334
+ unless cookbook_hash.has_key?($1)
335
+ Chef::Log.info("Removing #{cache_file} from the cache; its cookbook is no longer needed on this client.")
336
+ cache.delete(cache_file)
337
+ end
338
+ end
339
+ end
340
+
341
+ # Update the file caches for a given cache segment. Takes a segment name
342
+ # and a hash that matches one of the cookbooks/_attribute_files style
343
+ # remote file listings.
344
+ #
345
+ # === Parameters
346
+ # cookbook<Chef::Cookbook>:: The cookbook to update
347
+ # valid_cache_entries<Hash>:: Out-param; Added to this hash are the files that
348
+ # were referred to by this cookbook
349
+ def self.sync_cookbook_file_cache(cookbook)
350
+ Chef::Log.debug("Synchronizing cookbook #{cookbook.name}")
351
+
352
+ # files and templates are lazily loaded, and will be done later.
353
+ eager_segments = COOKBOOK_SEGMENTS.dup
354
+ eager_segments.delete(:files)
355
+ eager_segments.delete(:templates)
356
+
357
+ eager_segments.each do |segment|
358
+ segment_filenames = Array.new
359
+ cookbook.manifest[segment].each do |manifest_record|
360
+ # segment = cookbook segment
361
+ # remote_list = list of file hashes
362
+ #
363
+ # We need the list of known good attribute files, so we can delete any that are
364
+ # just laying about.
365
+
366
+ cache_filename = File.join("cookbooks", cookbook.name, manifest_record['path'])
367
+ valid_cache_entries[cache_filename] = true
368
+
369
+ current_checksum = nil
370
+ if cache.has_key?(cache_filename)
371
+ current_checksum = checksum_cookbook_file(cache.load(cache_filename, false))
372
+ end
373
+
374
+ # If the checksums are different between on-disk (current) and on-server
375
+ # (remote, per manifest), do the update. This will also execute if there
376
+ # is no current checksum.
377
+ if current_checksum != manifest_record['checksum']
378
+ raw_file = chef_server_rest.get_rest(manifest_record[:url], true)
379
+
380
+ Chef::Log.info("Storing updated #{cache_filename} in the cache.")
381
+ cache.move_to(raw_file.path, cache_filename)
382
+ else
383
+ Chef::Log.debug("Not storing #{cache_filename}, as the cache is up to date.")
384
+ end
385
+
386
+ # make the segment filenames a full path.
387
+ full_path_cache_filename = cache.load(cache_filename, false)
388
+ segment_filenames << full_path_cache_filename
389
+ end
390
+
391
+ # replace segment filenames with a full-path one.
392
+ if segment.to_sym == :recipes
393
+ cookbook.recipe_filenames = segment_filenames
394
+ elsif segment.to_sym == :attributes
395
+ cookbook.attribute_filenames = segment_filenames
396
+ else
397
+ cookbook.segment_filenames(segment).replace(segment_filenames)
398
+ end
399
+ end
400
+ end
401
+
402
+ def self.cleanup_file_cache
403
+ unless Chef::Config[:solo]
404
+ # Delete each file in the cache that we didn't encounter in the
405
+ # manifest.
406
+ cache.find(File.join(%w{cookbooks ** *})).each do |cache_filename|
407
+ unless valid_cache_entries[cache_filename]
408
+ Chef::Log.info("Removing #{cache_filename} from the cache; it is no longer needed by chef-client.")
409
+ cache.delete(cache_filename)
410
+ end
411
+ end
412
+ end
413
+ end
414
+
415
+ # Register a notification to cleanup unused files from cookbooks
416
+ Chef::Client.when_run_completes_successfully do |run_status|
417
+ cleanup_file_cache
418
+ end
419
+
420
+ # Creates a new Chef::CookbookVersion object.
421
+ #
422
+ # === Returns
423
+ # object<Chef::CookbookVersion>:: Duh. :)
424
+ def initialize(name, couchdb=nil)
425
+ @name = name
426
+ @frozen = false
427
+ @attribute_filenames = Array.new
428
+ @definition_filenames = Array.new
429
+ @template_filenames = Array.new
430
+ @file_filenames = Array.new
431
+ @recipe_filenames = Array.new
432
+ @recipe_filenames_by_name = Hash.new
433
+ @library_filenames = Array.new
434
+ @resource_filenames = Array.new
435
+ @provider_filenames = Array.new
436
+ @metadata_filenames = Array.new
437
+ @root_dir = nil
438
+ @root_filenames = Array.new
439
+ @couchdb_id = nil
440
+ @couchdb = couchdb || Chef::CouchDB.new
441
+ @couchdb_rev = nil
442
+ @status = :ready
443
+ @manifest = nil
444
+ @file_vendor = nil
445
+ @metadata = Chef::Cookbook::Metadata.new
446
+ end
447
+
448
+ def version
449
+ metadata.version
450
+ end
451
+
452
+ # Indicates if this version is frozen or not. Freezing a coobkook version
453
+ # indicates that a new cookbook with the same name and version number
454
+ # shoule
455
+ def frozen_version?
456
+ @frozen
457
+ end
458
+
459
+ def freeze_version
460
+ @frozen = true
461
+ end
462
+
463
+ def version=(new_version)
464
+ manifest["version"] = new_version
465
+ metadata.version(new_version)
466
+ end
467
+
468
+ # A manifest is a Mash that maps segment names to arrays of manifest
469
+ # records (see #preferred_manifest_record for format of manifest records),
470
+ # as well as describing cookbook metadata. The manifest follows a form
471
+ # like the following:
472
+ #
473
+ # {
474
+ # :cookbook_name = "apache2",
475
+ # :version = "1.0",
476
+ # :name = "Apache 2"
477
+ # :metadata = ???TODO: timh/cw: 5-24-2010: describe this format,
478
+ #
479
+ # :files => [
480
+ # {
481
+ # :name => "afile.rb",
482
+ # :path => "files/ubuntu-9.10/afile.rb",
483
+ # :checksum => "2222",
484
+ # :specificity => "ubuntu-9.10"
485
+ # },
486
+ # ],
487
+ # :templates => [ manifest_record1, ... ],
488
+ # ...
489
+ # }
490
+ def manifest
491
+ unless @manifest
492
+ generate_manifest
493
+ end
494
+ @manifest
495
+ end
496
+
497
+ def manifest=(new_manifest)
498
+ @manifest = Mash.new new_manifest
499
+ @checksums = extract_checksums_from_manifest(@manifest)
500
+ @manifest_records_by_path = extract_manifest_records_by_path(@manifest)
501
+
502
+ COOKBOOK_SEGMENTS.each do |segment|
503
+ next unless @manifest.has_key?(segment)
504
+ filenames = @manifest[segment].map{|manifest_record| manifest_record['name']}
505
+
506
+ if segment == :recipes
507
+ self.recipe_filenames = filenames
508
+ elsif segment == :attributes
509
+ self.attribute_filenames = filenames
510
+ else
511
+ segment_filenames(segment).clear
512
+ filenames.each { |filename| segment_filenames(segment) << filename }
513
+ end
514
+ end
515
+ end
516
+
517
+ # Returns a hash of checksums to either nil or the on disk path (which is
518
+ # done by generate_manifest).
519
+ def checksums
520
+ unless @checksums
521
+ generate_manifest
522
+ end
523
+ @checksums
524
+ end
525
+
526
+ def manifest_records_by_path
527
+ @manifest_records_by_path || generate_manifest
528
+ @manifest_records_by_path
529
+ end
530
+
531
+ def full_name
532
+ "#{name}-#{version}"
533
+ end
534
+
535
+ def attribute_filenames=(*filenames)
536
+ @attribute_filenames = filenames.flatten
537
+ @attribute_filenames_by_short_filename = filenames_by_name(attribute_filenames)
538
+ attribute_filenames
539
+ end
540
+
541
+ ## BACKCOMPAT/DEPRECATED - Remove these and fix breakage before release [DAN - 5/20/2010]##
542
+ alias :attribute_files :attribute_filenames
543
+ alias :attribute_files= :attribute_filenames=
544
+
545
+ # Return recipe names in the form of cookbook_name::recipe_name
546
+ def fully_qualified_recipe_names
547
+ results = Array.new
548
+ recipe_filenames_by_name.each_key do |rname|
549
+ results << "#{name}::#{rname}"
550
+ end
551
+ results
552
+ end
553
+
554
+ def recipe_filenames=(*filenames)
555
+ @recipe_filenames = filenames.flatten
556
+ @recipe_filenames_by_name = filenames_by_name(recipe_filenames)
557
+ recipe_filenames
558
+ end
559
+
560
+ ## BACKCOMPAT/DEPRECATED - Remove these and fix breakage before release [DAN - 5/20/2010]##
561
+ alias :recipe_files :recipe_filenames
562
+ alias :recipe_files= :recipe_filenames=
563
+
564
+ # called from DSL
565
+ def load_recipe(recipe_name, run_context)
566
+ unless recipe_filenames_by_name.has_key?(recipe_name)
567
+ raise ArgumentError, "Cannot find a recipe matching #{recipe_name} in cookbook #{name}"
568
+ end
569
+
570
+ Chef::Log.debug("Found recipe #{recipe_name} in cookbook #{name}")
571
+ recipe = Chef::Recipe.new(name, recipe_name, run_context)
572
+ recipe_filename = recipe_filenames_by_name[recipe_name]
573
+
574
+ unless recipe_filename
575
+ raise Chef::Exceptions::RecipeNotFound, "could not find recipe #{recipe_name} for cookbook #{name}"
576
+ end
577
+
578
+ recipe.from_file(recipe_filename)
579
+ recipe
580
+ end
581
+
582
+ def segment_filenames(segment)
583
+ unless COOKBOOK_SEGMENTS.include?(segment)
584
+ raise ArgumentError, "invalid segment #{segment}: must be one of #{COOKBOOK_SEGMENTS.join(', ')}"
585
+ end
586
+
587
+ case segment.to_sym
588
+ when :resources
589
+ @resource_filenames
590
+ when :providers
591
+ @provider_filenames
592
+ when :recipes
593
+ @recipe_filenames
594
+ when :libraries
595
+ @library_filenames
596
+ when :definitions
597
+ @definition_filenames
598
+ when :attributes
599
+ @attribute_filenames
600
+ when :files
601
+ @file_filenames
602
+ when :templates
603
+ @template_filenames
604
+ when :root_files
605
+ @root_filenames
606
+ end
607
+ end
608
+
609
+ # Determine the most specific manifest record for the given
610
+ # segment/filename, given information in the node. Throws
611
+ # FileNotFound if there is no such segment and filename in the
612
+ # manifest.
613
+ #
614
+ # A manifest record is a Mash that follows the following form:
615
+ # {
616
+ # :name => "example.rb",
617
+ # :path => "files/default/example.rb",
618
+ # :specificity => "default",
619
+ # :checksum => "1234"
620
+ # }
621
+ def preferred_manifest_record(node, segment, filename)
622
+ preferences = preferences_for_path(node, segment, filename)
623
+
624
+ # ensure that we generate the manifest, which will also generate
625
+ # @manifest_records_by_path
626
+ manifest
627
+
628
+ # in order of prefernce, look for the filename in the manifest
629
+ found_pref = preferences.find {|preferred_filename| @manifest_records_by_path[preferred_filename] }
630
+ if found_pref
631
+ @manifest_records_by_path[found_pref]
632
+ else
633
+ raise Chef::Exceptions::FileNotFound, "cookbook #{name} does not contain file #{segment}/#{filename}"
634
+ end
635
+ end
636
+
637
+ def preferred_filename_on_disk_location(node, segment, filename, current_filepath=nil)
638
+ manifest_record = preferred_manifest_record(node, segment, filename)
639
+ if current_filepath && (manifest_record['checksum'] == self.class.checksum_cookbook_file(current_filepath))
640
+ nil
641
+ else
642
+ file_vendor.get_filename(manifest_record['path'])
643
+ end
644
+ end
645
+
646
+ def relative_filenames_in_preferred_directory(node, segment, dirname)
647
+ preferences = preferences_for_path(node, segment, dirname)
648
+ filenames_by_pref = Hash.new
649
+ preferences.each { |pref| filenames_by_pref[pref] = Array.new }
650
+
651
+ manifest[segment].each do |manifest_record|
652
+ manifest_record_path = manifest_record[:path]
653
+
654
+ # find the NON SPECIFIC filenames, but prefer them by filespecificity.
655
+ # For example, if we have a file:
656
+ # 'files/default/somedir/somefile.conf' we only keep
657
+ # 'somedir/somefile.conf'. If there is also
658
+ # 'files/$hostspecific/somedir/otherfiles' that matches the requested
659
+ # hostname specificity, that directory will win, as it is more specific.
660
+ #
661
+ # This is clearly ugly b/c the use case is for remote directory, where
662
+ # we're just going to make cookbook_files out of these and make the
663
+ # cookbook find them by filespecificity again. but it's the shortest
664
+ # path to "success" for now.
665
+ if manifest_record_path =~ /(#{Regexp.escape(segment.to_s)}\/[^\/]+\/#{Regexp.escape(dirname)})\/.+$/
666
+ specificity_dirname = $1
667
+ non_specific_path = manifest_record_path[/#{Regexp.escape(segment.to_s)}\/[^\/]+\/#{Regexp.escape(dirname)}\/(.+)$/, 1]
668
+ # Record the specificity_dirname only if it's in the list of
669
+ # valid preferences
670
+ if filenames_by_pref[specificity_dirname]
671
+ filenames_by_pref[specificity_dirname] << non_specific_path
672
+ end
673
+ end
674
+ end
675
+
676
+ best_pref = preferences.find { |pref| !filenames_by_pref[pref].empty? }
677
+
678
+ raise Chef::Exceptions::FileNotFound, "cookbook #{name} has no directory #{segment}/#{dirname}" unless best_pref
679
+
680
+ filenames_by_pref[best_pref]
681
+
682
+ end
683
+
684
+ # Determine the manifest records from the most specific directory
685
+ # for the given node. See #preferred_manifest_record for a
686
+ # description of entries of the returned Array.
687
+ def preferred_manifest_records_for_directory(node, segment, dirname)
688
+ preferences = preferences_for_path(node, segment, dirname)
689
+ records_by_pref = Hash.new
690
+ preferences.each { |pref| records_by_pref[pref] = Array.new }
691
+
692
+ manifest[segment].each do |manifest_record|
693
+ manifest_record_path = manifest_record[:path]
694
+
695
+ # extract the preference part from the path.
696
+ if manifest_record_path =~ /(#{Regexp.escape(segment.to_s)}\/[^\/]+\/#{Regexp.escape(dirname)})\/.+$/
697
+ # Note the specificy_dirname includes the segment and
698
+ # dirname argument as above, which is what
699
+ # preferences_for_path returns. It could be
700
+ # "files/ubuntu-9.10/dirname", for example.
701
+ specificity_dirname = $1
702
+
703
+ # Record the specificity_dirname only if it's in the list of
704
+ # valid preferences
705
+ if records_by_pref[specificity_dirname]
706
+ records_by_pref[specificity_dirname] << manifest_record
707
+ end
708
+ end
709
+ end
710
+
711
+ best_pref = preferences.find { |pref| !records_by_pref[pref].empty? }
712
+
713
+ raise Chef::Exceptions::FileNotFound, "cookbook #{name} has no directory #{segment}/#{dirname}" unless best_pref
714
+
715
+ records_by_pref[best_pref]
716
+ end
717
+
718
+
719
+ # Given a node, segment and path (filename or directory name),
720
+ # return the priority-ordered list of preference locations to
721
+ # look.
722
+ def preferences_for_path(node, segment, path)
723
+ # only files and templates can be platform-specific
724
+ if segment.to_sym == :files || segment.to_sym == :templates
725
+ begin
726
+ platform, version = Chef::Platform.find_platform_and_version(node)
727
+ rescue ArgumentError => e
728
+ # Skip platform/version if they were not found by find_platform_and_version
729
+ if e.message =~ /Cannot find a (?:platform|version)/
730
+ platform = "/unknown_platform/"
731
+ version = "/unknown_platform_version/"
732
+ else
733
+ raise
734
+ end
735
+ end
736
+
737
+ fqdn = node[:fqdn]
738
+
739
+ # Most specific to least specific places to find the path
740
+ [
741
+ File.join(segment.to_s, "host-#{fqdn}", path),
742
+ File.join(segment.to_s, "#{platform}-#{version}", path),
743
+ File.join(segment.to_s, platform.to_s, path),
744
+ File.join(segment.to_s, "default", path)
745
+ ]
746
+ else
747
+ [File.join(segment, path)]
748
+ end
749
+ end
750
+ private :preferences_for_path
751
+
752
+ def to_hash
753
+ result = manifest.dup
754
+ result['frozen?'] = frozen_version?
755
+ result['chef_type'] = 'cookbook_version'
756
+ result["_rev"] = couchdb_rev if couchdb_rev
757
+ result.to_hash
758
+ end
759
+
760
+ def to_json(*a)
761
+ result = self.to_hash
762
+ result['json_class'] = self.class.name
763
+ result.to_json(*a)
764
+ end
765
+
766
+ def self.json_create(o)
767
+ cookbook_version = new(o["cookbook_name"])
768
+ if o.has_key?('_rev')
769
+ cookbook_version.couchdb_rev = o["_rev"] if o.has_key?("_rev")
770
+ o.delete("_rev")
771
+ end
772
+ if o.has_key?("_id")
773
+ cookbook_version.couchdb_id = o["_id"] if o.has_key?("_id")
774
+ cookbook_version.index_id = cookbook_version.couchdb_id
775
+ o.delete("_id")
776
+ end
777
+ # We want the Chef::Cookbook::Metadata object to always be inflated
778
+ cookbook_version.metadata = Chef::Cookbook::Metadata.from_hash(o["metadata"])
779
+ cookbook_version.manifest = o
780
+
781
+ # We don't need the following step when we decide to stop supporting deprecated operators in the metadata (e.g. <<, >>)
782
+ cookbook_version.manifest["metadata"] = JSON.parse(cookbook_version.metadata.to_json)
783
+
784
+ cookbook_version.freeze_version if o["frozen?"]
785
+ cookbook_version
786
+ end
787
+
788
+ def generate_manifest_with_urls(&url_generator)
789
+ rendered_manifest = manifest.dup
790
+ COOKBOOK_SEGMENTS.each do |segment|
791
+ if rendered_manifest.has_key?(segment)
792
+ rendered_manifest[segment].each do |manifest_record|
793
+ url_options = { :cookbook_name => name.to_s, :cookbook_version => version, :checksum => manifest_record["checksum"] }
794
+ manifest_record["url"] = url_generator.call(url_options)
795
+ end
796
+ end
797
+ end
798
+ rendered_manifest
799
+ end
800
+
801
+ def metadata_json_file
802
+ File.join(root_dir, "metadata.json")
803
+ end
804
+
805
+ def metadata_rb_file
806
+ File.join(root_dir, "metadata.rb")
807
+ end
808
+
809
+ def reload_metadata!
810
+ if File.exists?(metadata_json_file)
811
+ metadata.from_json(IO.read(metadata_json_file))
812
+ end
813
+ end
814
+
815
+ ##
816
+ # REST API
817
+ ##
818
+ def self.chef_server_rest
819
+ Chef::REST.new(Chef::Config[:chef_server_url])
820
+ end
821
+
822
+ def chef_server_rest
823
+ self.class.chef_server_rest
824
+ end
825
+
826
+ # Save this object to the server via the REST api. If there is an existing
827
+ # document on the server and it is marked frozen, a
828
+ # Net::HTTPServerException will be raised for 409 Conflict.
829
+ def save
830
+ chef_server_rest.put_rest("cookbooks/#{name}/#{version}", self)
831
+ self
832
+ end
833
+ alias :create :save
834
+
835
+ # Adds the `force=true` parameter to the upload. This allows the user to
836
+ # overwrite a frozen cookbook (normal #save raises a
837
+ # Net::HTTPServerException for 409 Conflict in this case).
838
+ def force_save
839
+ chef_server_rest.put_rest("cookbooks/#{name}/#{version}?force=true", self)
840
+ self
841
+ end
842
+
843
+ def destroy
844
+ chef_server_rest.delete_rest("cookbooks/#{name}/#{version}")
845
+ self
846
+ end
847
+
848
+ def self.load(name, version="_latest")
849
+ version = "_latest" if version == "latest"
850
+ chef_server_rest.get_rest("cookbooks/#{name}/#{version}")
851
+ end
852
+
853
+ def self.list
854
+ chef_server_rest.get_rest('cookbooks')
855
+ end
856
+
857
+ ##
858
+ # Given a +cookbook_name+, get a list of all versions that exist on the
859
+ # server.
860
+ # ===Returns
861
+ # [String]:: Array of cookbook versions, which are strings like 'x.y.z'
862
+ # nil:: if the cookbook doesn't exist. an error will also be logged.
863
+ def self.available_versions(cookbook_name)
864
+ chef_server_rest.get_rest("cookbooks/#{cookbook_name}")[cookbook_name]["versions"].map do |cb|
865
+ cb["version"]
866
+ end
867
+ rescue Net::HTTPServerException => e
868
+ if e.to_s =~ /^404/
869
+ Chef::Log.error("Cannot find a cookbook named #{cookbook_name}")
870
+ nil
871
+ else
872
+ raise
873
+ end
874
+ end
875
+
876
+ # Get the newest version of all cookbooks
877
+ def self.latest_cookbooks
878
+ chef_server_rest.get_rest('cookbooks/_latest')
879
+ end
880
+
881
+ ##
882
+ # Couchdb
883
+ ##
884
+
885
+ def self.cdb_by_name(cookbook_name, couchdb=nil)
886
+ cdb = (couchdb || Chef::CouchDB.new)
887
+ options = { :startkey => cookbook_name, :endkey => cookbook_name }
888
+ rs = cdb.get_view("cookbooks", "all_with_version", options)
889
+ rs["rows"].inject({}) { |memo, row| memo.has_key?(row["key"]) ? memo[row["key"]] << row["value"] : memo[row["key"]] = [ row["value"] ]; memo }
890
+ end
891
+
892
+ def self.create_design_document(couchdb=nil)
893
+ (couchdb || Chef::CouchDB.new).create_design_document("cookbooks", DESIGN_DOCUMENT)
894
+ end
895
+
896
+ def self.cdb_list_latest(inflate=false, couchdb=nil)
897
+ couchdb ||= Chef::CouchDB.new
898
+ if inflate
899
+ doc_ids = cdb_list_latest_ids.map {|i|i["id"]}
900
+ couchdb.bulk_get(doc_ids)
901
+ else
902
+ results = couchdb.get_view("cookbooks", "all_latest_version", :group=>true)["rows"]
903
+ results.inject({}) { |mapped, row| mapped[row["key"]] = row["value"]; mapped}
904
+ end
905
+ end
906
+
907
+ def self.cdb_list_latest_ids(inflate=false, couchdb=nil)
908
+ couchdb ||= Chef::CouchDB.new
909
+ results = couchdb.get_view("cookbooks", "all_latest_version_by_id", :group=>true)["rows"]
910
+ results.map { |name_and_id| name_and_id["value"]}
911
+ end
912
+
913
+ def self.cdb_list(inflate=false, couchdb=nil)
914
+ couchdb ||= Chef::CouchDB.new
915
+ if inflate
916
+ couchdb.list("cookbooks", true)["rows"].collect{|r| r["value"]}
917
+ else
918
+ # If you modify this, please make sure the desc sorted order on the versions doesn't get broken.
919
+ couchdb.get_view("cookbooks", "all_with_version")["rows"].inject({}) { |mapped, row| mapped[row["key"]]||=Array.new; mapped[row["key"]].push(Chef::Version.new(row["value"])); mapped[row["key"]].sort!.reverse!; mapped}
920
+ end
921
+ end
922
+
923
+ def self.cdb_load(name, version='latest', couchdb=nil)
924
+ cdb = couchdb || Chef::CouchDB.new
925
+ if version == "latest" || version == "_latest"
926
+ rs = cdb.get_view("cookbooks", "all_latest_version", :key => name, :descending => true, :group => true, :reduce => true)["rows"].first
927
+ cdb.load("cookbook_version", "#{rs["key"]}-#{rs["value"]}")
928
+ else
929
+ cdb.load("cookbook_version", "#{name}-#{version}")
930
+ end
931
+ end
932
+
933
+ def cdb_destroy
934
+ (couchdb || Chef::CouchDB.new).delete("cookbook_version", full_name, couchdb_rev)
935
+ end
936
+
937
+ # Runs on Chef Server (API); deletes the cookbook from couchdb and also destroys associated
938
+ # checksum documents
939
+ def purge
940
+ checksums.keys.each do |checksum|
941
+ begin
942
+ Chef::Checksum.cdb_load(checksum, couchdb).purge
943
+ rescue Chef::Exceptions::CouchDBNotFound
944
+ end
945
+ end
946
+ cdb_destroy
947
+ end
948
+
949
+ def cdb_save
950
+ @couchdb_rev = couchdb.store("cookbook_version", full_name, self)["rev"]
951
+ end
952
+
953
+ def couchdb_id=(value)
954
+ @couchdb_id = value
955
+ @index_id = value
956
+ end
957
+
958
+ def <=>(o)
959
+ raise Chef::Exceptions::CookbookVersionNameMismatch if self.name != o.name
960
+ # FIXME: can we change the interface to the Metadata class such
961
+ # that metadata.version returns a Chef::Version instance instead
962
+ # of a string?
963
+ Chef::Version.new(self.version) <=> Chef::Version.new(o.version)
964
+ end
965
+
966
+ private
967
+
968
+ # For each filename, produce a mapping of base filename (i.e. recipe name
969
+ # or attribute file) to on disk location
970
+ def filenames_by_name(filenames)
971
+ filenames.select{|filename| filename =~ /\.rb$/}.inject({}){|memo, filename| memo[File.basename(filename, '.rb')] = filename ; memo }
972
+ end
973
+
974
+ # See #manifest for a description of the manifest return value.
975
+ # See #preferred_manifest_record for a description an individual manifest record.
976
+ def generate_manifest
977
+ manifest = Mash.new({
978
+ :recipes => Array.new,
979
+ :definitions => Array.new,
980
+ :libraries => Array.new,
981
+ :attributes => Array.new,
982
+ :files => Array.new,
983
+ :templates => Array.new,
984
+ :resources => Array.new,
985
+ :providers => Array.new,
986
+ :root_files => Array.new
987
+ })
988
+ checksums_to_on_disk_paths = {}
989
+
990
+ COOKBOOK_SEGMENTS.each do |segment|
991
+ segment_filenames(segment).each do |segment_file|
992
+ next if File.directory?(segment_file)
993
+
994
+ file_name = nil
995
+ path = nil
996
+ specificity = "default"
997
+
998
+ if segment == :root_files
999
+ matcher = segment_file.match(".+/#{Regexp.escape(name.to_s)}/(.+)")
1000
+ file_name = matcher[1]
1001
+ path = file_name
1002
+ elsif segment == :templates || segment == :files
1003
+ matcher = segment_file.match("/#{Regexp.escape(name.to_s)}/(#{Regexp.escape(segment.to_s)}/(.+?)/(.+))")
1004
+ unless matcher
1005
+ Chef::Log.debug("Skipping file #{segment_file}, as it isn't in any of the proper directories (platform-version, platform or default)")
1006
+ Chef::Log.debug("You probably need to move #{segment_file} into the 'default' sub-directory")
1007
+ next
1008
+ end
1009
+ path = matcher[1]
1010
+ specificity = matcher[2]
1011
+ file_name = matcher[3]
1012
+ else
1013
+ matcher = segment_file.match("/#{Regexp.escape(name.to_s)}/(#{Regexp.escape(segment.to_s)}/(.+))")
1014
+ path = matcher[1]
1015
+ file_name = matcher[2]
1016
+ end
1017
+
1018
+ csum = self.class.checksum_cookbook_file(segment_file)
1019
+ checksums_to_on_disk_paths[csum] = segment_file
1020
+ rs = Mash.new({
1021
+ :name => file_name,
1022
+ :path => path,
1023
+ :checksum => csum
1024
+ })
1025
+ rs[:specificity] = specificity
1026
+
1027
+ manifest[segment] << rs
1028
+ end
1029
+ end
1030
+
1031
+ manifest[:cookbook_name] = name.to_s
1032
+ manifest[:metadata] = metadata
1033
+ manifest[:version] = metadata.version
1034
+ manifest[:name] = full_name
1035
+
1036
+ @checksums = checksums_to_on_disk_paths
1037
+ @manifest = manifest
1038
+ @manifest_records_by_path = extract_manifest_records_by_path(manifest)
1039
+ end
1040
+
1041
+ def file_vendor
1042
+ unless @file_vendor
1043
+ @file_vendor = Chef::Cookbook::FileVendor.create_from_manifest(manifest)
1044
+ end
1045
+ @file_vendor
1046
+ end
1047
+
1048
+ def extract_checksums_from_manifest(manifest)
1049
+ checksums = {}
1050
+ COOKBOOK_SEGMENTS.each do |segment|
1051
+ next unless manifest.has_key?(segment)
1052
+ manifest[segment].each do |manifest_record|
1053
+ checksums[manifest_record[:checksum]] = nil
1054
+ end
1055
+ end
1056
+ checksums
1057
+ end
1058
+
1059
+ def extract_manifest_records_by_path(manifest)
1060
+ manifest_records_by_path = {}
1061
+ COOKBOOK_SEGMENTS.each do |segment|
1062
+ next unless manifest.has_key?(segment)
1063
+ manifest[segment].each do |manifest_record|
1064
+ manifest_records_by_path[manifest_record[:path]] = manifest_record
1065
+ end
1066
+ end
1067
+ manifest_records_by_path
1068
+ end
1069
+
1070
+ end
1071
+ end