runa-chef 0.8.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (216) hide show
  1. data/LICENSE +201 -0
  2. data/README.rdoc +136 -0
  3. data/bin/chef-client +26 -0
  4. data/bin/chef-solo +26 -0
  5. data/bin/knife +27 -0
  6. data/bin/shef +45 -0
  7. data/distro/README +2 -0
  8. data/distro/common/man/man1/chef-indexer.1 +42 -0
  9. data/distro/common/man/man1/chef-server.1 +108 -0
  10. data/distro/common/man/man8/chef-client.8 +61 -0
  11. data/distro/common/man/man8/chef-solo.8 +58 -0
  12. data/distro/common/man/man8/knife.8 +359 -0
  13. data/distro/debian/etc/init.d/chef-client +175 -0
  14. data/distro/debian/etc/init.d/chef-indexer +175 -0
  15. data/distro/debian/etc/init.d/chef-server +120 -0
  16. data/distro/redhat/etc/init.d/chef-client +78 -0
  17. data/distro/redhat/etc/init.d/chef-indexer +76 -0
  18. data/distro/redhat/etc/init.d/chef-server +78 -0
  19. data/distro/redhat/etc/sysconfig/chef-client +10 -0
  20. data/distro/redhat/etc/sysconfig/chef-indexer +8 -0
  21. data/distro/redhat/etc/sysconfig/chef-server +10 -0
  22. data/distro/suse/etc/init.d/chef-client +121 -0
  23. data/lib/chef.rb +49 -0
  24. data/lib/chef/api_client.rb +269 -0
  25. data/lib/chef/application.rb +98 -0
  26. data/lib/chef/application/agent.rb +18 -0
  27. data/lib/chef/application/client.rb +214 -0
  28. data/lib/chef/application/knife.rb +138 -0
  29. data/lib/chef/application/server.rb +19 -0
  30. data/lib/chef/application/solo.rb +214 -0
  31. data/lib/chef/cache.rb +61 -0
  32. data/lib/chef/cache/checksum.rb +70 -0
  33. data/lib/chef/certificate.rb +154 -0
  34. data/lib/chef/client.rb +323 -0
  35. data/lib/chef/compile.rb +158 -0
  36. data/lib/chef/config.rb +195 -0
  37. data/lib/chef/cookbook.rb +198 -0
  38. data/lib/chef/cookbook/metadata.rb +487 -0
  39. data/lib/chef/cookbook/metadata/version.rb +87 -0
  40. data/lib/chef/cookbook_loader.rb +180 -0
  41. data/lib/chef/couchdb.rb +273 -0
  42. data/lib/chef/daemon.rb +170 -0
  43. data/lib/chef/data_bag.rb +216 -0
  44. data/lib/chef/data_bag_item.rb +227 -0
  45. data/lib/chef/exceptions.rb +39 -0
  46. data/lib/chef/file_cache.rb +205 -0
  47. data/lib/chef/knife.rb +300 -0
  48. data/lib/chef/knife/client_bulk_delete.rb +41 -0
  49. data/lib/chef/knife/client_create.rb +55 -0
  50. data/lib/chef/knife/client_delete.rb +37 -0
  51. data/lib/chef/knife/client_edit.rb +37 -0
  52. data/lib/chef/knife/client_list.rb +40 -0
  53. data/lib/chef/knife/client_reregister.rb +48 -0
  54. data/lib/chef/knife/client_show.rb +42 -0
  55. data/lib/chef/knife/configure.rb +84 -0
  56. data/lib/chef/knife/cookbook_bulk_delete.rb +47 -0
  57. data/lib/chef/knife/cookbook_delete.rb +41 -0
  58. data/lib/chef/knife/cookbook_download.rb +57 -0
  59. data/lib/chef/knife/cookbook_list.rb +41 -0
  60. data/lib/chef/knife/cookbook_metadata.rb +87 -0
  61. data/lib/chef/knife/cookbook_show.rb +75 -0
  62. data/lib/chef/knife/cookbook_upload.rb +173 -0
  63. data/lib/chef/knife/data_bag_create.rb +43 -0
  64. data/lib/chef/knife/data_bag_delete.rb +43 -0
  65. data/lib/chef/knife/data_bag_edit.rb +49 -0
  66. data/lib/chef/knife/data_bag_list.rb +42 -0
  67. data/lib/chef/knife/data_bag_show.rb +40 -0
  68. data/lib/chef/knife/ec2_instance_data.rb +46 -0
  69. data/lib/chef/knife/node_bulk_delete.rb +44 -0
  70. data/lib/chef/knife/node_create.rb +39 -0
  71. data/lib/chef/knife/node_delete.rb +36 -0
  72. data/lib/chef/knife/node_edit.rb +36 -0
  73. data/lib/chef/knife/node_from_file.rb +42 -0
  74. data/lib/chef/knife/node_list.rb +41 -0
  75. data/lib/chef/knife/node_run_list_add.rb +64 -0
  76. data/lib/chef/knife/node_run_list_remove.rb +45 -0
  77. data/lib/chef/knife/node_show.rb +46 -0
  78. data/lib/chef/knife/role_bulk_delete.rb +45 -0
  79. data/lib/chef/knife/role_create.rb +44 -0
  80. data/lib/chef/knife/role_delete.rb +36 -0
  81. data/lib/chef/knife/role_edit.rb +37 -0
  82. data/lib/chef/knife/role_from_file.rb +46 -0
  83. data/lib/chef/knife/role_list.rb +40 -0
  84. data/lib/chef/knife/role_show.rb +43 -0
  85. data/lib/chef/knife/search.rb +94 -0
  86. data/lib/chef/log.rb +39 -0
  87. data/lib/chef/mixin/check_helper.rb +31 -0
  88. data/lib/chef/mixin/checksum.rb +32 -0
  89. data/lib/chef/mixin/command.rb +390 -0
  90. data/lib/chef/mixin/convert_to_class_name.rb +57 -0
  91. data/lib/chef/mixin/create_path.rb +56 -0
  92. data/lib/chef/mixin/deep_merge.rb +33 -0
  93. data/lib/chef/mixin/find_preferred_file.rb +92 -0
  94. data/lib/chef/mixin/from_file.rb +50 -0
  95. data/lib/chef/mixin/generate_url.rb +58 -0
  96. data/lib/chef/mixin/language.rb +107 -0
  97. data/lib/chef/mixin/language_include_attribute.rb +56 -0
  98. data/lib/chef/mixin/language_include_recipe.rb +53 -0
  99. data/lib/chef/mixin/params_validate.rb +197 -0
  100. data/lib/chef/mixin/recipe_definition_dsl_core.rb +79 -0
  101. data/lib/chef/mixin/template.rb +94 -0
  102. data/lib/chef/nanite.rb +100 -0
  103. data/lib/chef/node.rb +463 -0
  104. data/lib/chef/node/attribute.rb +412 -0
  105. data/lib/chef/openid_registration.rb +181 -0
  106. data/lib/chef/platform.rb +268 -0
  107. data/lib/chef/provider.rb +101 -0
  108. data/lib/chef/provider/breakpoint.rb +36 -0
  109. data/lib/chef/provider/cron.rb +184 -0
  110. data/lib/chef/provider/deploy.rb +314 -0
  111. data/lib/chef/provider/deploy/revision.rb +70 -0
  112. data/lib/chef/provider/deploy/timestamped.rb +33 -0
  113. data/lib/chef/provider/directory.rb +72 -0
  114. data/lib/chef/provider/erl_call.rb +72 -0
  115. data/lib/chef/provider/execute.rb +58 -0
  116. data/lib/chef/provider/file.rb +195 -0
  117. data/lib/chef/provider/git.rb +203 -0
  118. data/lib/chef/provider/group.rb +120 -0
  119. data/lib/chef/provider/group/dscl.rb +128 -0
  120. data/lib/chef/provider/group/gpasswd.rb +50 -0
  121. data/lib/chef/provider/group/groupadd.rb +78 -0
  122. data/lib/chef/provider/group/pw.rb +88 -0
  123. data/lib/chef/provider/group/usermod.rb +57 -0
  124. data/lib/chef/provider/http_request.rb +106 -0
  125. data/lib/chef/provider/ifconfig.rb +131 -0
  126. data/lib/chef/provider/link.rb +157 -0
  127. data/lib/chef/provider/mdadm.rb +88 -0
  128. data/lib/chef/provider/mount.rb +117 -0
  129. data/lib/chef/provider/mount/mount.rb +208 -0
  130. data/lib/chef/provider/package.rb +160 -0
  131. data/lib/chef/provider/package/apt.rb +110 -0
  132. data/lib/chef/provider/package/dpkg.rb +109 -0
  133. data/lib/chef/provider/package/easy_install.rb +106 -0
  134. data/lib/chef/provider/package/freebsd.rb +153 -0
  135. data/lib/chef/provider/package/macports.rb +105 -0
  136. data/lib/chef/provider/package/portage.rb +124 -0
  137. data/lib/chef/provider/package/rpm.rb +99 -0
  138. data/lib/chef/provider/package/rubygems.rb +136 -0
  139. data/lib/chef/provider/package/yum-dump.py +125 -0
  140. data/lib/chef/provider/package/yum.rb +175 -0
  141. data/lib/chef/provider/package/zypper.rb +132 -0
  142. data/lib/chef/provider/remote_directory.rb +126 -0
  143. data/lib/chef/provider/remote_file.rb +141 -0
  144. data/lib/chef/provider/route.rb +118 -0
  145. data/lib/chef/provider/ruby_block.rb +33 -0
  146. data/lib/chef/provider/script.rb +42 -0
  147. data/lib/chef/provider/service.rb +135 -0
  148. data/lib/chef/provider/service/debian.rb +64 -0
  149. data/lib/chef/provider/service/freebsd.rb +156 -0
  150. data/lib/chef/provider/service/gentoo.rb +54 -0
  151. data/lib/chef/provider/service/init.rb +71 -0
  152. data/lib/chef/provider/service/redhat.rb +62 -0
  153. data/lib/chef/provider/service/simple.rb +114 -0
  154. data/lib/chef/provider/subversion.rb +156 -0
  155. data/lib/chef/provider/template.rb +175 -0
  156. data/lib/chef/provider/user.rb +170 -0
  157. data/lib/chef/provider/user/dscl.rb +280 -0
  158. data/lib/chef/provider/user/pw.rb +113 -0
  159. data/lib/chef/provider/user/useradd.rb +108 -0
  160. data/lib/chef/recipe.rb +105 -0
  161. data/lib/chef/resource.rb +380 -0
  162. data/lib/chef/resource/apt_package.rb +34 -0
  163. data/lib/chef/resource/bash.rb +33 -0
  164. data/lib/chef/resource/breakpoint.rb +35 -0
  165. data/lib/chef/resource/cron.rb +179 -0
  166. data/lib/chef/resource/csh.rb +33 -0
  167. data/lib/chef/resource/deploy.rb +359 -0
  168. data/lib/chef/resource/deploy_revision.rb +35 -0
  169. data/lib/chef/resource/directory.rb +76 -0
  170. data/lib/chef/resource/dpkg_package.rb +34 -0
  171. data/lib/chef/resource/easy_install_package.rb +41 -0
  172. data/lib/chef/resource/erl_call.rb +83 -0
  173. data/lib/chef/resource/execute.rb +127 -0
  174. data/lib/chef/resource/file.rb +84 -0
  175. data/lib/chef/resource/gem_package.rb +41 -0
  176. data/lib/chef/resource/git.rb +36 -0
  177. data/lib/chef/resource/group.rb +70 -0
  178. data/lib/chef/resource/http_request.rb +52 -0
  179. data/lib/chef/resource/ifconfig.rb +134 -0
  180. data/lib/chef/resource/link.rb +78 -0
  181. data/lib/chef/resource/macports_package.rb +29 -0
  182. data/lib/chef/resource/mdadm.rb +82 -0
  183. data/lib/chef/resource/mount.rb +135 -0
  184. data/lib/chef/resource/package.rb +80 -0
  185. data/lib/chef/resource/perl.rb +33 -0
  186. data/lib/chef/resource/portage_package.rb +33 -0
  187. data/lib/chef/resource/python.rb +33 -0
  188. data/lib/chef/resource/remote_directory.rb +91 -0
  189. data/lib/chef/resource/remote_file.rb +60 -0
  190. data/lib/chef/resource/route.rb +135 -0
  191. data/lib/chef/resource/ruby.rb +33 -0
  192. data/lib/chef/resource/ruby_block.rb +39 -0
  193. data/lib/chef/resource/scm.rb +137 -0
  194. data/lib/chef/resource/script.rb +51 -0
  195. data/lib/chef/resource/service.rb +134 -0
  196. data/lib/chef/resource/subversion.rb +34 -0
  197. data/lib/chef/resource/template.rb +60 -0
  198. data/lib/chef/resource/timestamped_deploy.rb +31 -0
  199. data/lib/chef/resource/user.rb +101 -0
  200. data/lib/chef/resource_collection.rb +212 -0
  201. data/lib/chef/resource_collection/stepable_iterator.rb +124 -0
  202. data/lib/chef/resource_definition.rb +67 -0
  203. data/lib/chef/rest.rb +298 -0
  204. data/lib/chef/role.rb +301 -0
  205. data/lib/chef/run_list.rb +164 -0
  206. data/lib/chef/runner.rb +130 -0
  207. data/lib/chef/search/query.rb +71 -0
  208. data/lib/chef/shef.rb +220 -0
  209. data/lib/chef/shef/ext.rb +297 -0
  210. data/lib/chef/shef/shef_session.rb +175 -0
  211. data/lib/chef/streaming_cookbook_uploader.rb +185 -0
  212. data/lib/chef/tasks/chef_repo.rake +245 -0
  213. data/lib/chef/util/file_edit.rb +125 -0
  214. data/lib/chef/util/fileedit.rb +121 -0
  215. data/lib/chef/webui_user.rb +231 -0
  216. metadata +398 -0
@@ -0,0 +1,268 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'chef/config'
20
+ require 'chef/log'
21
+ require 'chef/mixin/params_validate'
22
+ require 'chef/platform'
23
+ require 'chef/resource'
24
+ Dir[File.join(File.dirname(__FILE__), 'provider/**/*.rb')].sort.each { |lib| require lib }
25
+
26
+ class Chef
27
+ class Platform
28
+
29
+ @platforms = {
30
+ :mac_os_x => {
31
+ :default => {
32
+ :package => Chef::Provider::Package::Macports,
33
+ :user => Chef::Provider::User::Dscl,
34
+ :group => Chef::Provider::Group::Dscl
35
+ }
36
+ },
37
+ :freebsd => {
38
+ :default => {
39
+ :group => Chef::Provider::Group::Pw,
40
+ :package => Chef::Provider::Package::Freebsd,
41
+ :service => Chef::Provider::Service::Freebsd,
42
+ :user => Chef::Provider::User::Pw,
43
+ :cron => Chef::Provider::Cron
44
+ }
45
+ },
46
+ :ubuntu => {
47
+ :default => {
48
+ :package => Chef::Provider::Package::Apt,
49
+ :service => Chef::Provider::Service::Debian,
50
+ :cron => Chef::Provider::Cron,
51
+ :mdadm => Chef::Provider::Mdadm
52
+ }
53
+ },
54
+ :debian => {
55
+ :default => {
56
+ :package => Chef::Provider::Package::Apt,
57
+ :service => Chef::Provider::Service::Debian,
58
+ :cron => Chef::Provider::Cron,
59
+ :mdadm => Chef::Provider::Mdadm
60
+ }
61
+ },
62
+ :centos => {
63
+ :default => {
64
+ :service => Chef::Provider::Service::Redhat,
65
+ :cron => Chef::Provider::Cron,
66
+ :package => Chef::Provider::Package::Yum,
67
+ :mdadm => Chef::Provider::Mdadm
68
+ }
69
+ },
70
+ :suse => {
71
+ :default => {
72
+ :service => Chef::Provider::Service::Redhat,
73
+ :cron => Chef::Provider::Cron,
74
+ :package => Chef::Provider::Package::Zypper
75
+ }
76
+ },
77
+ :redhat => {
78
+ :default => {
79
+ :service => Chef::Provider::Service::Redhat,
80
+ :cron => Chef::Provider::Cron,
81
+ :package => Chef::Provider::Package::Yum,
82
+ :mdadm => Chef::Provider::Mdadm
83
+ }
84
+ },
85
+ :gentoo => {
86
+ :default => {
87
+ :package => Chef::Provider::Package::Portage,
88
+ :service => Chef::Provider::Service::Gentoo,
89
+ :cron => Chef::Provider::Cron,
90
+ :mdadm => Chef::Provider::Mdadm
91
+ }
92
+ },
93
+ :solaris => {},
94
+ :default => {
95
+ :file => Chef::Provider::File,
96
+ :directory => Chef::Provider::Directory,
97
+ :link => Chef::Provider::Link,
98
+ :template => Chef::Provider::Template,
99
+ :remote_file => Chef::Provider::RemoteFile,
100
+ :remote_directory => Chef::Provider::RemoteDirectory,
101
+ :execute => Chef::Provider::Execute,
102
+ :mount => Chef::Provider::Mount::Mount,
103
+ :script => Chef::Provider::Script,
104
+ :service => Chef::Provider::Service::Init,
105
+ :perl => Chef::Provider::Script,
106
+ :python => Chef::Provider::Script,
107
+ :ruby => Chef::Provider::Script,
108
+ :bash => Chef::Provider::Script,
109
+ :csh => Chef::Provider::Script,
110
+ :user => Chef::Provider::User::Useradd,
111
+ :group => Chef::Provider::Group::Gpasswd,
112
+ :http_request => Chef::Provider::HttpRequest,
113
+ :route => Chef::Provider::Route,
114
+ :ifconfig => Chef::Provider::Ifconfig,
115
+ :ruby_block => Chef::Provider::RubyBlock,
116
+ :erl_call => Chef::Provider::ErlCall
117
+ }
118
+ }
119
+
120
+ class << self
121
+ attr_accessor :platforms
122
+
123
+ include Chef::Mixin::ParamsValidate
124
+
125
+ def find(name, version)
126
+ provider_map = @platforms[:default].clone
127
+
128
+ name_sym = name
129
+ if name.kind_of?(String)
130
+ name.downcase!
131
+ name.gsub!(/\s/, "_")
132
+ name_sym = name.to_sym
133
+ end
134
+
135
+ if @platforms.has_key?(name_sym)
136
+ if @platforms[name_sym].has_key?(version)
137
+ Chef::Log.debug("Platform #{name.to_s} version #{version} found")
138
+ if @platforms[name_sym].has_key?(:default)
139
+ provider_map.merge!(@platforms[name_sym][:default])
140
+ end
141
+ provider_map.merge!(@platforms[name_sym][version])
142
+ elsif @platforms[name_sym].has_key?(:default)
143
+ provider_map.merge!(@platforms[name_sym][:default])
144
+ end
145
+ else
146
+ Chef::Log.debug("Platform #{name} not found, using all defaults. (Unsupported platform?)")
147
+ end
148
+ provider_map
149
+ end
150
+
151
+ def find_provider(platform, version, resource_type)
152
+ pmap = Chef::Platform.find(platform, version)
153
+ rtkey = resource_type
154
+ if resource_type.kind_of?(Chef::Resource)
155
+ return resource_type.provider if resource_type.provider
156
+ rtkey = resource_type.resource_name.to_sym
157
+ end
158
+ if pmap.has_key?(rtkey)
159
+ pmap[rtkey]
160
+ else
161
+ raise(
162
+ ArgumentError,
163
+ "Cannot find a provider for #{resource_type} on #{platform} version #{version}"
164
+ )
165
+ end
166
+ end
167
+
168
+ def find_platform_and_version(node)
169
+ platform = nil
170
+ version = nil
171
+
172
+ if node[:platform]
173
+ platform = node[:platform]
174
+ elsif node.attribute?("os")
175
+ platform = node[:os]
176
+ end
177
+
178
+ raise ArgumentError, "Cannot find a platform for #{node}" unless platform
179
+
180
+ if node[:platform_version]
181
+ version = node[:platform_version]
182
+ elsif node[:os_version]
183
+ version = node[:os_version]
184
+ elsif node[:os_release]
185
+ version = node[:os_release]
186
+ end
187
+
188
+ raise ArgumentError, "Cannot find a version for #{node}" unless version
189
+
190
+ return platform, version
191
+ end
192
+
193
+ def provider_for_node(node, resource_type)
194
+ find_provider_for_node(node, resource_type).new(node, resource_type)
195
+ end
196
+
197
+ def find_provider_for_node(node, resource_type)
198
+ platform, version = find_platform_and_version(node)
199
+ provider = find_provider(platform, version, resource_type)
200
+ end
201
+
202
+ def set(args)
203
+ validate(
204
+ args,
205
+ {
206
+ :platform => {
207
+ :kind_of => Symbol,
208
+ :required => false,
209
+ },
210
+ :version => {
211
+ :kind_of => String,
212
+ :required => false,
213
+ },
214
+ :resource => {
215
+ :kind_of => Symbol,
216
+ },
217
+ :provider => {
218
+ :kind_of => [ String, Symbol, Class ],
219
+ }
220
+ }
221
+ )
222
+ if args.has_key?(:platform)
223
+ if args.has_key?(:version)
224
+ if @platforms.has_key?(args[:platform])
225
+ if @platforms[args[:platform]].has_key?(args[:version])
226
+ @platforms[args[:platform]][args[:version]][args[:resource].to_sym] = args[:provider]
227
+ else
228
+ @platforms[args[:platform]][args[:version]] = {
229
+ args[:resource].to_sym => args[:provider]
230
+ }
231
+ end
232
+ else
233
+ @platforms[args[:platform]] = {
234
+ args[:version] => {
235
+ args[:resource].to_sym => args[:provider]
236
+ }
237
+ }
238
+ end
239
+ else
240
+ if @platforms.has_key?(args[:platform])
241
+ if @platforms[args[:platform]].has_key?(:default)
242
+ @platforms[args[:platform]][:default][args[:resource].to_sym] = args[:provider]
243
+ else
244
+ @platforms[args[:platform]] = { :default => { args[:resource].to_sym => args[:provider] } }
245
+ end
246
+ else
247
+ @platforms[args[:platform]] = {
248
+ :default => {
249
+ args[:resource].to_sym => args[:provider]
250
+ }
251
+ }
252
+ end
253
+ end
254
+ else
255
+ if @platforms.has_key?(:default)
256
+ @platforms[:default][args[:resource].to_sym] = args[:provider]
257
+ else
258
+ @platforms[:default] = {
259
+ args[:resource].to_sym => args[:provider]
260
+ }
261
+ end
262
+ end
263
+ end
264
+
265
+ end
266
+
267
+ end
268
+ end
@@ -0,0 +1,101 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Author:: Christopher Walters (<cw@opscode.com>)
4
+ # Copyright:: Copyright (c) 2008, 2009 Opscode, Inc.
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ require 'chef/mixin/from_file'
21
+ require 'chef/mixin/convert_to_class_name'
22
+ require 'chef/mixin/recipe_definition_dsl_core'
23
+
24
+ class Chef
25
+ class Provider
26
+
27
+ include Chef::Mixin::RecipeDefinitionDSLCore
28
+
29
+ attr_accessor :node, :new_resource, :current_resource
30
+
31
+ def initialize(node, new_resource, collection=nil, definitions={}, cookbook_loader=nil)
32
+ @node = node
33
+ @new_resource = new_resource
34
+ @current_resource = nil
35
+ @collection = collection
36
+ @definitions = definitions
37
+ @cookbook_loader = cookbook_loader
38
+ @cookbook_name = @new_resource.cookbook_name
39
+ end
40
+
41
+ def load_current_resource
42
+ raise Chef::Exceptions::Override, "You must override load_current_resource in #{self.to_s}"
43
+ end
44
+
45
+ def action_nothing
46
+ Chef::Log.debug("Doing nothing for #{@new_resource.to_s}")
47
+ true
48
+ end
49
+
50
+ protected
51
+
52
+ def recipe_eval(*args, &block)
53
+ provider_collection, @collection = @collection, Chef::ResourceCollection.new
54
+
55
+ instance_eval(*args, &block)
56
+ Chef::Runner.new(@node, @collection).converge
57
+
58
+ @collection = provider_collection
59
+ end
60
+
61
+ public
62
+
63
+ class << self
64
+ include Chef::Mixin::ConvertToClassName
65
+
66
+ def build_from_file(cookbook_name, filename)
67
+ pname = filename_to_qualified_string(cookbook_name, filename)
68
+
69
+ new_provider_class = Class.new self do |cls|
70
+
71
+ def load_current_resource
72
+ # silence Chef::Exceptions::Override exception
73
+ end
74
+
75
+ class << cls
76
+ include Chef::Mixin::FromFile
77
+
78
+ # setup DSL's shortcut methods
79
+ def action(name, &block)
80
+ define_method("action_#{name.to_s}") do
81
+ instance_eval(&block)
82
+ end
83
+ end
84
+ end
85
+
86
+ # load provider definition from file
87
+ cls.class_from_file(filename)
88
+ end
89
+
90
+ # register new class as a Chef::Provider
91
+ pname = filename_to_qualified_string(cookbook_name, filename)
92
+ class_name = convert_to_class_name(pname)
93
+ Chef::Provider.const_set(class_name, new_provider_class)
94
+ Chef::Log.debug("Loaded contents of #{filename} into a provider named #{pname} defined in Chef::Provider::#{class_name}")
95
+
96
+ new_provider_class
97
+ end
98
+ end
99
+
100
+ end
101
+ end
@@ -0,0 +1,36 @@
1
+ #
2
+ # Author:: Daniel DeLeo (<dan@kallistec.com>)
3
+ # Copyright:: Copyright (c) 2008 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ class Chef
20
+ class Provider
21
+ class Breakpoint < Chef::Provider
22
+
23
+ def load_current_resource
24
+ end
25
+
26
+ def action_break
27
+ if defined?(Shef) && Shef.running?
28
+ @collection.iterator.pause
29
+ @new_resource.updated = true
30
+ @collection.iterator
31
+ end
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,184 @@
1
+ #
2
+ # Author:: Bryan McLellan (btm@loftninjas.org)
3
+ # Copyright:: Copyright (c) 2009 Bryan McLellan
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'chef/log'
20
+ require 'chef/mixin/command'
21
+ require 'chef/provider'
22
+
23
+ class Chef
24
+ class Provider
25
+ class Cron < Chef::Provider
26
+ include Chef::Mixin::Command
27
+
28
+ def initialize(node, new_resource, collection=nil, definitions=nil, cookbook_loader=nil)
29
+ super(node, new_resource, collection, definitions, cookbook_loader)
30
+ @cron_exists = false
31
+ @cron_empty = false
32
+ end
33
+ attr_accessor :cron_exists, :cron_empty
34
+
35
+ def load_current_resource
36
+ crontab = String.new
37
+ @current_resource = Chef::Resource::Cron.new(@new_resource.name)
38
+ @current_resource.user(@new_resource.user)
39
+ status = popen4("crontab -l -u #{@new_resource.user}") do |pid, stdin, stdout, stderr|
40
+ stdout.each { |line| crontab << line }
41
+ end
42
+ if status.exitstatus > 1
43
+ raise Chef::Exceptions::Cron, "Error determining state of #{@new_resource.name}, exit: #{status.exitstatus}"
44
+ elsif status.exitstatus == 0
45
+ cron_found = false
46
+ crontab.each do |line|
47
+ case line
48
+ when /^# Chef Name: #{@new_resource.name}/
49
+ Chef::Log.debug("Found cron '#{@new_resource.name}'")
50
+ cron_found = true
51
+ @cron_exists = true
52
+ next
53
+ when /^MAILTO=(\S*)/
54
+ @current_resource.mailto($1) if cron_found
55
+ next
56
+ when /^PATH=(\S*)/
57
+ @current_resource.path($1) if cron_found
58
+ next
59
+ when /^SHELL=(\S*)/
60
+ @current_resource.shell($1) if cron_found
61
+ next
62
+ when /^HOME=(\S*)/
63
+ @current_resource.home($1) if cron_found
64
+ next
65
+ when /([0-9\*]+)\s*([0-9\*]+)\s*([0-9\*]+)\s*([0-9\*]+)\s*([0-9\*]+)\s*(.*)/
66
+ if cron_found
67
+ @current_resource.minute($1)
68
+ @current_resource.hour($2)
69
+ @current_resource.day($3)
70
+ @current_resource.month($4)
71
+ @current_resource.weekday($5)
72
+ @current_resource.command($6)
73
+ cron_found=false
74
+ end
75
+ next
76
+ else
77
+ next
78
+ end
79
+ end
80
+ Chef::Log.debug("Cron '#{@new_resource.name}' not found") unless @cron_exists
81
+ elsif status.exitstatus == 1
82
+ Chef::Log.debug("Cron empty for '#{@new_resource.user}'")
83
+ @cron_empty = true
84
+ end
85
+
86
+ @current_resource
87
+ end
88
+
89
+ def compare_cron
90
+ [ :minute, :hour, :day, :month, :weekday, :command, :mailto, :path, :shell, :home ].any? do |cron_var|
91
+ !@new_resource.send(cron_var).nil? && @new_resource.send(cron_var) != @current_resource.send(cron_var)
92
+ end
93
+ end
94
+
95
+ def action_create
96
+ crontab = String.new
97
+ newcron = String.new
98
+ cron_found = false
99
+
100
+ newcron << "# Chef Name: #{new_resource.name}\n"
101
+ [ :mailto, :path, :shell, :home ].each do |v|
102
+ newcron << "#{v.to_s.upcase}=#{@new_resource.send(v)}\n" if @new_resource.send(v)
103
+ end
104
+ newcron << "#{@new_resource.minute} #{@new_resource.hour} #{@new_resource.day} #{@new_resource.month} #{@new_resource.weekday} #{@new_resource.command}\n"
105
+
106
+ if @cron_exists
107
+ unless compare_cron
108
+ Chef::Log.debug("Skipping existing cron entry '#{@new_resource.name}'")
109
+ return
110
+ end
111
+ status = popen4("crontab -l -u #{@new_resource.user}") do |pid, stdin, stdout, stderr|
112
+ stdout.each_line do |line|
113
+ case line
114
+ when /^# Chef Name: #{@new_resource.name}\n/
115
+ cron_found = true
116
+ next
117
+ when /([0-9\*]+)\s*([0-9\*]+)\s*([0-9\*]+)\s*([0-9\*]+)\s*([0-9\*]+)\s*(.*)/
118
+ if cron_found
119
+ cron_found = false
120
+ crontab << newcron
121
+ next
122
+ end
123
+ else
124
+ next if cron_found
125
+ end
126
+ crontab << line
127
+ end
128
+ end
129
+
130
+ status = popen4("crontab -u #{@new_resource.user} -", :waitlast => true) do |pid, stdin, stdout, stderr|
131
+ crontab.each { |line| stdin.puts "#{line}" }
132
+ end
133
+ Chef::Log.info("Updated cron '#{@new_resource.name}'")
134
+ @new_resource.updated = true
135
+ else
136
+ unless @cron_empty
137
+ status = popen4("crontab -l -u #{@new_resource.user}") do |pid, stdin, stdout, stderr|
138
+ stdout.each { |line| crontab << line }
139
+ end
140
+ end
141
+
142
+ crontab << newcron
143
+
144
+ status = popen4("crontab -u #{@new_resource.user} -", :waitlast => true) do |pid, stdin, stdout, stderr|
145
+ crontab.each { |line| stdin.puts "#{line}" }
146
+ end
147
+ Chef::Log.info("Added cron '#{@new_resource.name}'")
148
+ @new_resource.updated = true
149
+ end
150
+ end
151
+
152
+ def action_delete
153
+ if @cron_exists
154
+ crontab = String.new
155
+ cron_found = false
156
+ status = popen4("crontab -l -u #{@new_resource.user}") do |pid, stdin, stdout, stderr|
157
+ stdout.each_line do |line|
158
+ case line
159
+ when /^# Chef Name: #{@new_resource.name}\n/
160
+ cron_found = true
161
+ next
162
+ when /([0-9\*]+)\s*([0-9\*]+)\s*([0-9\*]+)\s*([0-9\*]+)\s*([0-9\*]+)\s*(.*)/
163
+ if cron_found
164
+ cron_found = false
165
+ next
166
+ end
167
+ else
168
+ next if cron_found
169
+ end
170
+ crontab << line
171
+ end
172
+ end
173
+
174
+ status = popen4("crontab -u #{@new_resource.user} -", :waitlast => true) do |pid, stdin, stdout, stderr|
175
+ crontab.each { |line| stdin.puts "#{line}" }
176
+ end
177
+ Chef::Log.debug("Deleted cron '#{@new_resource.name}'")
178
+ @new_resource.updated = true
179
+ end
180
+ end
181
+
182
+ end
183
+ end
184
+ end