chef 0.7.10

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of chef might be problematic. Click here for more details.

Files changed (120) hide show
  1. data/LICENSE +201 -0
  2. data/README.rdoc +135 -0
  3. data/bin/chef-client +26 -0
  4. data/bin/chef-solo +26 -0
  5. data/lib/chef.rb +49 -0
  6. data/lib/chef/application.rb +98 -0
  7. data/lib/chef/application/agent.rb +18 -0
  8. data/lib/chef/application/client.rb +209 -0
  9. data/lib/chef/application/indexer.rb +141 -0
  10. data/lib/chef/application/server.rb +18 -0
  11. data/lib/chef/application/solo.rb +214 -0
  12. data/lib/chef/client.rb +396 -0
  13. data/lib/chef/compile.rb +138 -0
  14. data/lib/chef/config.rb +141 -0
  15. data/lib/chef/cookbook.rb +144 -0
  16. data/lib/chef/cookbook/metadata.rb +407 -0
  17. data/lib/chef/cookbook/metadata/version.rb +87 -0
  18. data/lib/chef/cookbook_loader.rb +168 -0
  19. data/lib/chef/couchdb.rb +172 -0
  20. data/lib/chef/daemon.rb +170 -0
  21. data/lib/chef/exceptions.rb +36 -0
  22. data/lib/chef/file_cache.rb +205 -0
  23. data/lib/chef/log.rb +39 -0
  24. data/lib/chef/mixin/check_helper.rb +31 -0
  25. data/lib/chef/mixin/checksum.rb +37 -0
  26. data/lib/chef/mixin/command.rb +351 -0
  27. data/lib/chef/mixin/create_path.rb +56 -0
  28. data/lib/chef/mixin/deep_merge.rb +36 -0
  29. data/lib/chef/mixin/find_preferred_file.rb +99 -0
  30. data/lib/chef/mixin/from_file.rb +36 -0
  31. data/lib/chef/mixin/generate_url.rb +48 -0
  32. data/lib/chef/mixin/language.rb +79 -0
  33. data/lib/chef/mixin/params_validate.rb +197 -0
  34. data/lib/chef/mixin/template.rb +84 -0
  35. data/lib/chef/node.rb +406 -0
  36. data/lib/chef/node/attribute.rb +412 -0
  37. data/lib/chef/openid_registration.rb +181 -0
  38. data/lib/chef/platform.rb +253 -0
  39. data/lib/chef/provider.rb +40 -0
  40. data/lib/chef/provider/cron.rb +137 -0
  41. data/lib/chef/provider/directory.rb +72 -0
  42. data/lib/chef/provider/execute.rb +58 -0
  43. data/lib/chef/provider/file.rb +191 -0
  44. data/lib/chef/provider/group.rb +120 -0
  45. data/lib/chef/provider/group/groupadd.rb +92 -0
  46. data/lib/chef/provider/group/pw.rb +88 -0
  47. data/lib/chef/provider/http_request.rb +102 -0
  48. data/lib/chef/provider/ifconfig.rb +131 -0
  49. data/lib/chef/provider/link.rb +157 -0
  50. data/lib/chef/provider/mount.rb +121 -0
  51. data/lib/chef/provider/mount/mount.rb +208 -0
  52. data/lib/chef/provider/package.rb +160 -0
  53. data/lib/chef/provider/package/apt.rb +110 -0
  54. data/lib/chef/provider/package/dpkg.rb +113 -0
  55. data/lib/chef/provider/package/freebsd.rb +153 -0
  56. data/lib/chef/provider/package/macports.rb +105 -0
  57. data/lib/chef/provider/package/portage.rb +124 -0
  58. data/lib/chef/provider/package/rpm.rb +99 -0
  59. data/lib/chef/provider/package/rubygems.rb +130 -0
  60. data/lib/chef/provider/package/yum-dump.py +104 -0
  61. data/lib/chef/provider/package/yum.rb +175 -0
  62. data/lib/chef/provider/remote_directory.rb +126 -0
  63. data/lib/chef/provider/remote_file.rb +134 -0
  64. data/lib/chef/provider/route.rb +118 -0
  65. data/lib/chef/provider/ruby_block.rb +15 -0
  66. data/lib/chef/provider/script.rb +42 -0
  67. data/lib/chef/provider/service.rb +129 -0
  68. data/lib/chef/provider/service/debian.rb +64 -0
  69. data/lib/chef/provider/service/freebsd.rb +157 -0
  70. data/lib/chef/provider/service/gentoo.rb +54 -0
  71. data/lib/chef/provider/service/init.rb +126 -0
  72. data/lib/chef/provider/service/redhat.rb +62 -0
  73. data/lib/chef/provider/template.rb +141 -0
  74. data/lib/chef/provider/user.rb +170 -0
  75. data/lib/chef/provider/user/pw.rb +113 -0
  76. data/lib/chef/provider/user/useradd.rb +107 -0
  77. data/lib/chef/queue.rb +145 -0
  78. data/lib/chef/recipe.rb +210 -0
  79. data/lib/chef/resource.rb +256 -0
  80. data/lib/chef/resource/apt_package.rb +34 -0
  81. data/lib/chef/resource/bash.rb +33 -0
  82. data/lib/chef/resource/cron.rb +143 -0
  83. data/lib/chef/resource/csh.rb +33 -0
  84. data/lib/chef/resource/directory.rb +76 -0
  85. data/lib/chef/resource/dpkg_package.rb +34 -0
  86. data/lib/chef/resource/execute.rb +127 -0
  87. data/lib/chef/resource/file.rb +84 -0
  88. data/lib/chef/resource/gem_package.rb +41 -0
  89. data/lib/chef/resource/group.rb +68 -0
  90. data/lib/chef/resource/http_request.rb +52 -0
  91. data/lib/chef/resource/ifconfig.rb +134 -0
  92. data/lib/chef/resource/link.rb +78 -0
  93. data/lib/chef/resource/macports_package.rb +29 -0
  94. data/lib/chef/resource/mount.rb +135 -0
  95. data/lib/chef/resource/package.rb +80 -0
  96. data/lib/chef/resource/perl.rb +33 -0
  97. data/lib/chef/resource/portage_package.rb +33 -0
  98. data/lib/chef/resource/python.rb +33 -0
  99. data/lib/chef/resource/remote_directory.rb +91 -0
  100. data/lib/chef/resource/remote_file.rb +60 -0
  101. data/lib/chef/resource/route.rb +135 -0
  102. data/lib/chef/resource/ruby.rb +33 -0
  103. data/lib/chef/resource/ruby_block.rb +20 -0
  104. data/lib/chef/resource/script.rb +51 -0
  105. data/lib/chef/resource/service.rb +134 -0
  106. data/lib/chef/resource/template.rb +60 -0
  107. data/lib/chef/resource/user.rb +98 -0
  108. data/lib/chef/resource_collection.rb +176 -0
  109. data/lib/chef/resource_definition.rb +67 -0
  110. data/lib/chef/rest.rb +238 -0
  111. data/lib/chef/role.rb +231 -0
  112. data/lib/chef/run_list.rb +156 -0
  113. data/lib/chef/runner.rb +123 -0
  114. data/lib/chef/search.rb +88 -0
  115. data/lib/chef/search/result.rb +64 -0
  116. data/lib/chef/search_index.rb +77 -0
  117. data/lib/chef/tasks/chef_repo.rake +345 -0
  118. data/lib/chef/util/file_edit.rb +125 -0
  119. data/lib/chef/util/fileedit.rb +121 -0
  120. metadata +262 -0
@@ -0,0 +1,256 @@
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/mixin/params_validate'
20
+ require 'chef/mixin/check_helper'
21
+ require 'chef/mixin/language'
22
+ require 'chef/resource_collection'
23
+ require 'chef/node'
24
+
25
+ class Chef
26
+ class Resource
27
+
28
+ include Chef::Mixin::CheckHelper
29
+ include Chef::Mixin::ParamsValidate
30
+ include Chef::Mixin::Language
31
+
32
+ attr_accessor :actions, :params, :provider, :updated, :allowed_actions, :collection, :cookbook_name, :recipe_name
33
+ attr_reader :resource_name, :source_line, :node
34
+
35
+ def initialize(name, collection=nil, node=nil)
36
+ @name = name
37
+ if collection
38
+ @collection = collection
39
+ else
40
+ @collection = Chef::ResourceCollection.new()
41
+ end
42
+ @node = node ? node : Chef::Node.new
43
+ @noop = nil
44
+ @before = nil
45
+ @actions = Hash.new
46
+ @params = Hash.new
47
+ @provider = nil
48
+ @allowed_actions = [ :nothing ]
49
+ @action = :nothing
50
+ @updated = false
51
+ @supports = {}
52
+ @ignore_failure = false
53
+ @not_if = nil
54
+ @only_if = nil
55
+ sline = caller(4).shift
56
+ if sline
57
+ @source_line = sline.gsub!(/^(.+):(.+):.+$/, '\1 line \2')
58
+ @source_line = ::File.expand_path(@source_line) if @source_line
59
+ end
60
+ end
61
+
62
+ def load_prior_resource
63
+ begin
64
+ prior_resource = @collection.lookup(self.to_s)
65
+ Chef::Log.debug("Setting #{self.to_s} to the state of the prior #{self.to_s}")
66
+ prior_resource.instance_variables.each do |iv|
67
+ unless iv == "@source_line" || iv == "@action"
68
+ self.instance_variable_set(iv, prior_resource.instance_variable_get(iv))
69
+ end
70
+ end
71
+ true
72
+ rescue ArgumentError => e
73
+ true
74
+ end
75
+ end
76
+
77
+ def supports(args={})
78
+ if args.any?
79
+ @supports = args
80
+ else
81
+ @supports
82
+ end
83
+ end
84
+
85
+ def provider(arg=nil)
86
+ set_or_return(
87
+ :provider,
88
+ arg,
89
+ :kind_of => [ Class ]
90
+ )
91
+ end
92
+
93
+ def action(arg=nil)
94
+ if arg
95
+ action_list = arg.kind_of?(Array) ? arg : [ arg ]
96
+ action_list = action_list.collect { |a| a.to_sym }
97
+ action_list.each do |action|
98
+ validate(
99
+ {
100
+ :action => action,
101
+ },
102
+ {
103
+ :action => { :kind_of => Symbol, :equal_to => @allowed_actions },
104
+ }
105
+ )
106
+ end
107
+ @action = action_list
108
+ else
109
+ @action
110
+ end
111
+ end
112
+
113
+ def name(name=nil)
114
+ set_if_args(@name, name) do
115
+ raise ArgumentError, "name must be a string!" unless name.kind_of?(String)
116
+ @name = name
117
+ end
118
+ end
119
+
120
+ def noop(tf=nil)
121
+ set_if_args(@noop, tf) do
122
+ raise ArgumentError, "noop must be true or false!" unless tf == true || tf == false
123
+ @noop = tf
124
+ end
125
+ end
126
+
127
+ def ignore_failure(arg=nil)
128
+ set_or_return(
129
+ :ignore_failure,
130
+ arg,
131
+ :kind_of => [ TrueClass, FalseClass ]
132
+ )
133
+ end
134
+
135
+ def epic_fail(arg=nil)
136
+ ignore_failure(arg)
137
+ end
138
+
139
+ def notifies(*args)
140
+ raise ArgumentError, "Wrong number of arguments (should be 1, 2, or 3)" unless ( args.size > 0 && args.size < 4)
141
+ if args.size > 1
142
+ notifies_helper(*args)
143
+ else
144
+ resources_array = *args
145
+ resources_array.each do |resource|
146
+ resource.each do |key, value|
147
+ notifies_helper(value[0], key, value[1])
148
+ end
149
+ end
150
+ end
151
+ end
152
+
153
+ def resources(*args)
154
+ @collection.resources(*args)
155
+ end
156
+
157
+ def subscribes(action, resources, timing=:delayed)
158
+ timing = check_timing(timing)
159
+ rarray = resources.kind_of?(Array) ? resources : [ resources ]
160
+ rarray.each do |resource|
161
+ action_sym = action.to_sym
162
+ if resource.actions.has_key?(action_sym)
163
+ resource.actions[action_sym][timing] << self
164
+ else
165
+ resource.actions[action_sym] = Hash.new
166
+ resource.actions[action_sym][:delayed] = Array.new
167
+ resource.actions[action_sym][:immediate] = Array.new
168
+ resource.actions[action_sym][timing] << self
169
+ end
170
+ end
171
+ true
172
+ end
173
+
174
+ def is(*args)
175
+ return *args
176
+ end
177
+
178
+ def to_s
179
+ "#{@resource_name}[#{@name}]"
180
+ end
181
+
182
+ # Serialize this object as a hash
183
+ def to_json(*a)
184
+ instance_vars = Hash.new
185
+ self.instance_variables.each do |iv|
186
+ instance_vars[iv] = self.instance_variable_get(iv) unless iv == "@collection"
187
+ end
188
+ results = {
189
+ 'json_class' => self.class.name,
190
+ 'instance_vars' => instance_vars
191
+ }
192
+ results.to_json(*a)
193
+ end
194
+
195
+ def self.json_create(o)
196
+ resource = self.new(o["instance_vars"]["@name"])
197
+ o["instance_vars"].each do |k,v|
198
+ resource.instance_variable_set(k.to_sym, v)
199
+ end
200
+ resource
201
+ end
202
+
203
+ def only_if(arg=nil, &blk)
204
+ if Kernel.block_given?
205
+ @only_if = blk
206
+ else
207
+ @only_if = arg if arg
208
+ end
209
+ @only_if
210
+ end
211
+
212
+ def not_if(arg=nil, &blk)
213
+ if Kernel.block_given?
214
+ @not_if = blk
215
+ else
216
+ @not_if = arg if arg
217
+ end
218
+ @not_if
219
+ end
220
+
221
+ def run_action(action)
222
+ provider = Chef::Platform.provider_for_node(@node, self)
223
+ provider.load_current_resource
224
+ provider.send("action_#{action}")
225
+ end
226
+
227
+ private
228
+
229
+ def check_timing(timing)
230
+ unless timing == :delayed || timing == :immediate || timing == :immediately
231
+ raise ArgumentError, "Timing must be :delayed or :immediate(ly), you said #{timing}"
232
+ end
233
+ if timing == :immediately
234
+ timing = :immediate
235
+ end
236
+ timing
237
+ end
238
+
239
+ def notifies_helper(action, resources, timing=:delayed)
240
+ timing = check_timing(timing)
241
+ rarray = resources.kind_of?(Array) ? resources : [ resources ]
242
+ rarray.each do |resource|
243
+ action_sym = action.to_sym
244
+ if @actions.has_key?(action_sym)
245
+ @actions[action_sym][timing] << resource
246
+ else
247
+ @actions[action_sym] = Hash.new
248
+ @actions[action_sym][:delayed] = Array.new
249
+ @actions[action_sym][:immediate] = Array.new
250
+ @actions[action_sym][timing] << resource
251
+ end
252
+ end
253
+ true
254
+ end
255
+ end
256
+ end
@@ -0,0 +1,34 @@
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/resource/package'
20
+ require 'chef/provider/package/apt'
21
+
22
+ class Chef
23
+ class Resource
24
+ class AptPackage < Chef::Resource::Package
25
+
26
+ def initialize(name, collection=nil, node=nil)
27
+ super(name, collection, node)
28
+ @resource_name = :apt_package
29
+ @provider = Chef::Provider::Package::Apt
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,33 @@
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/resource/script'
20
+
21
+ class Chef
22
+ class Resource
23
+ class Bash < Chef::Resource::Script
24
+
25
+ def initialize(name, collection=nil, node=nil)
26
+ super(name, collection, node)
27
+ @resource_name = :bash
28
+ @interpreter = "bash"
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,143 @@
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/resource'
20
+
21
+ class Chef
22
+ class Resource
23
+ class Cron < Chef::Resource
24
+
25
+ def initialize(name, collection=nil, node=nil)
26
+ super(name, collection, node)
27
+ @resource_name = :cron
28
+ @action = :create
29
+ @allowed_actions.push(:create, :delete)
30
+ @minute = "*"
31
+ @hour = "*"
32
+ @day = "*"
33
+ @month = "*"
34
+ @weekday = "*"
35
+ @command = nil
36
+ @user = "root"
37
+ end
38
+
39
+ def minute(arg=nil)
40
+ if arg.is_a?(Integer)
41
+ converted_arg = arg.to_s
42
+ else
43
+ converted_arg = arg
44
+ end
45
+ begin
46
+ if Integer(arg) > 59 then raise RangeError end
47
+ rescue ArgumentError
48
+ end
49
+ set_or_return(
50
+ :minute,
51
+ converted_arg,
52
+ :kind_of => String
53
+ )
54
+ end
55
+
56
+ def hour(arg=nil)
57
+ if arg.is_a?(Integer)
58
+ converted_arg = arg.to_s
59
+ else
60
+ converted_arg = arg
61
+ end
62
+ begin
63
+ if Integer(arg) > 23 then raise RangeError end
64
+ rescue ArgumentError
65
+ end
66
+ set_or_return(
67
+ :hour,
68
+ converted_arg,
69
+ :kind_of => String
70
+ )
71
+ end
72
+
73
+ def day(arg=nil)
74
+ if arg.is_a?(Integer)
75
+ converted_arg = arg.to_s
76
+ else
77
+ converted_arg = arg
78
+ end
79
+ begin
80
+ if Integer(arg) > 31 then raise RangeError end
81
+ rescue ArgumentError
82
+ end
83
+ set_or_return(
84
+ :day,
85
+ converted_arg,
86
+ :kind_of => String
87
+ )
88
+ end
89
+
90
+ def month(arg=nil)
91
+ if arg.is_a?(Integer)
92
+ converted_arg = arg.to_s
93
+ else
94
+ converted_arg = arg
95
+ end
96
+ begin
97
+ if Integer(arg) > 12 then raise RangeError end
98
+ rescue ArgumentError
99
+ end
100
+ set_or_return(
101
+ :month,
102
+ converted_arg,
103
+ :kind_of => String
104
+ )
105
+ end
106
+
107
+ def weekday(arg=nil)
108
+ if arg.is_a?(Integer)
109
+ converted_arg = arg.to_s
110
+ else
111
+ converted_arg = arg
112
+ end
113
+ begin
114
+ if Integer(arg) > 7 then raise RangeError end
115
+ rescue ArgumentError
116
+ end
117
+ set_or_return(
118
+ :weekday,
119
+ converted_arg,
120
+ :kind_of => String
121
+ )
122
+ end
123
+
124
+ def command(arg=nil)
125
+ set_or_return(
126
+ :command,
127
+ arg,
128
+ :kind_of => String
129
+ )
130
+ end
131
+
132
+ def user(arg=nil)
133
+ set_or_return(
134
+ :user,
135
+ arg,
136
+ :kind_of => String
137
+ )
138
+ end
139
+ end
140
+ end
141
+ end
142
+
143
+