chef 0.7.16 → 0.8.2
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.
- data/README.rdoc +11 -10
- data/bin/chef-client +2 -2
- data/bin/chef-solo +1 -1
- data/bin/knife +27 -0
- data/bin/shef +49 -0
- data/distro/README +2 -0
- data/distro/{debian → common}/man/man1/chef-indexer.1 +0 -0
- data/distro/{debian → common}/man/man1/chef-server.1 +0 -0
- data/distro/{debian → common}/man/man8/chef-client.8 +0 -0
- data/distro/{debian → common}/man/man8/chef-solo.8 +0 -0
- data/distro/common/man/man8/knife.8 +375 -0
- data/distro/redhat/etc/init.d/chef-client +8 -4
- data/distro/redhat/etc/init.d/chef-server +16 -15
- data/distro/redhat/etc/init.d/chef-server-webui +78 -0
- data/distro/redhat/etc/init.d/chef-solr +76 -0
- data/distro/redhat/etc/init.d/chef-solr-indexer +75 -0
- data/distro/redhat/etc/sysconfig/chef-client +10 -0
- data/distro/redhat/etc/sysconfig/chef-server +10 -0
- data/distro/redhat/etc/sysconfig/chef-server-webui +10 -0
- data/distro/redhat/etc/sysconfig/chef-solr +9 -0
- data/distro/redhat/etc/sysconfig/chef-solr-indexer +7 -0
- data/distro/suse/etc/init.d/chef-client +121 -0
- data/lib/chef.rb +1 -1
- data/lib/chef/api_client.rb +263 -0
- data/lib/chef/application.rb +1 -1
- data/lib/chef/application/client.rb +21 -3
- data/lib/chef/application/knife.rb +144 -0
- data/lib/chef/application/server.rb +2 -1
- data/lib/chef/application/solo.rb +9 -2
- data/lib/chef/cache.rb +61 -0
- data/lib/chef/cache/checksum.rb +70 -0
- data/lib/chef/certificate.rb +154 -0
- data/lib/chef/client.rb +123 -220
- data/lib/chef/compile.rb +9 -21
- data/lib/chef/config.rb +67 -10
- data/lib/chef/cookbook.rb +49 -22
- data/lib/chef/cookbook/metadata.rb +85 -5
- data/lib/chef/cookbook_loader.rb +4 -4
- data/lib/chef/couchdb.rb +99 -30
- data/lib/chef/daemon.rb +1 -1
- data/lib/chef/data_bag.rb +215 -0
- data/lib/chef/data_bag_item.rb +219 -0
- data/lib/chef/exceptions.rb +3 -0
- data/lib/chef/index_queue.rb +29 -0
- data/lib/chef/index_queue/amqp_client.rb +106 -0
- data/lib/chef/index_queue/consumer.rb +76 -0
- data/lib/chef/index_queue/indexable.rb +74 -0
- data/lib/chef/knife.rb +309 -0
- data/lib/chef/knife/client_bulk_delete.rb +40 -0
- data/lib/chef/knife/client_create.rb +62 -0
- data/lib/chef/knife/client_delete.rb +37 -0
- data/lib/chef/knife/client_edit.rb +37 -0
- data/lib/chef/knife/client_list.rb +40 -0
- data/lib/chef/knife/client_reregister.rb +48 -0
- data/lib/chef/knife/client_show.rb +42 -0
- data/lib/chef/knife/configure.rb +123 -0
- data/lib/chef/knife/cookbook_bulk_delete.rb +46 -0
- data/lib/chef/knife/cookbook_delete.rb +41 -0
- data/lib/chef/knife/cookbook_download.rb +57 -0
- data/lib/chef/knife/cookbook_list.rb +41 -0
- data/lib/chef/knife/cookbook_metadata.rb +87 -0
- data/lib/chef/knife/cookbook_show.rb +75 -0
- data/lib/chef/knife/cookbook_upload.rb +179 -0
- data/lib/chef/knife/data_bag_create.rb +43 -0
- data/lib/chef/knife/data_bag_delete.rb +43 -0
- data/lib/chef/knife/data_bag_edit.rb +49 -0
- data/lib/chef/knife/data_bag_list.rb +42 -0
- data/lib/chef/knife/data_bag_show.rb +40 -0
- data/lib/chef/knife/ec2_instance_data.rb +46 -0
- data/lib/chef/knife/index_rebuild.rb +51 -0
- data/lib/chef/knife/node_bulk_delete.rb +43 -0
- data/lib/chef/knife/node_create.rb +39 -0
- data/lib/chef/knife/node_delete.rb +36 -0
- data/lib/chef/knife/node_edit.rb +36 -0
- data/lib/chef/knife/node_from_file.rb +42 -0
- data/lib/chef/knife/node_list.rb +41 -0
- data/lib/chef/knife/node_run_list_add.rb +64 -0
- data/lib/chef/knife/node_run_list_remove.rb +45 -0
- data/lib/chef/knife/node_show.rb +46 -0
- data/lib/chef/knife/role_bulk_delete.rb +44 -0
- data/lib/chef/knife/role_create.rb +44 -0
- data/lib/chef/knife/role_delete.rb +36 -0
- data/lib/chef/knife/role_edit.rb +37 -0
- data/lib/chef/knife/role_from_file.rb +46 -0
- data/lib/chef/knife/role_list.rb +40 -0
- data/lib/chef/knife/role_show.rb +43 -0
- data/lib/chef/knife/search.rb +94 -0
- data/lib/chef/knife/ssh.rb +170 -0
- data/lib/chef/log.rb +30 -8
- data/lib/chef/mixin/checksum.rb +2 -7
- data/lib/chef/mixin/command.rb +32 -13
- data/lib/chef/mixin/convert_to_class_name.rb +15 -0
- data/lib/chef/mixin/deep_merge.rb +199 -11
- data/lib/chef/mixin/generate_url.rb +18 -9
- data/lib/chef/mixin/language.rb +29 -1
- data/lib/chef/mixin/language_include_attribute.rb +56 -0
- data/lib/chef/mixin/language_include_recipe.rb +53 -0
- data/lib/chef/mixin/params_validate.rb +25 -12
- data/lib/chef/mixin/recipe_definition_dsl_core.rb +2 -0
- data/lib/chef/mixin/template.rb +11 -1
- data/lib/chef/mixin/xml_escape.rb +87 -0
- data/lib/chef/node.rb +144 -122
- data/lib/chef/openid_registration.rb +12 -5
- data/lib/chef/platform.rb +89 -47
- data/lib/chef/provider/breakpoint.rb +36 -0
- data/lib/chef/provider/cron.rb +5 -6
- data/lib/chef/provider/deploy.rb +43 -10
- data/lib/chef/provider/deploy/revision.rb +2 -3
- data/lib/chef/provider/erl_call.rb +72 -0
- data/lib/chef/provider/file.rb +8 -4
- data/lib/chef/provider/git.rb +10 -5
- data/lib/chef/provider/group/dscl.rb +128 -0
- data/lib/chef/provider/http_request.rb +6 -2
- data/lib/chef/provider/ifconfig.rb +1 -0
- data/lib/chef/provider/link.rb +1 -1
- data/lib/chef/provider/log.rb +53 -0
- data/lib/chef/provider/mdadm.rb +88 -0
- data/lib/chef/provider/mount/mount.rb +1 -1
- data/lib/chef/provider/package.rb +1 -1
- data/lib/chef/provider/package/easy_install.rb +106 -0
- data/lib/chef/provider/package/pacman.rb +101 -0
- data/lib/chef/provider/package/portage.rb +1 -1
- data/lib/chef/provider/package/rpm.rb +10 -8
- data/lib/chef/provider/package/yum-dump.py +22 -3
- data/lib/chef/provider/package/yum.rb +32 -8
- data/lib/chef/provider/package/zypper.rb +132 -0
- data/lib/chef/provider/remote_directory.rb +58 -49
- data/lib/chef/provider/remote_file.rb +1 -1
- data/lib/chef/provider/route.rb +136 -80
- data/lib/chef/provider/ruby_block.rb +18 -1
- data/lib/chef/provider/service/arch.rb +109 -0
- data/lib/chef/provider/service/freebsd.rb +0 -1
- data/lib/chef/provider/service/simple.rb +2 -3
- data/lib/chef/provider/service/upstart.rb +191 -0
- data/lib/chef/provider/subversion.rb +12 -4
- data/lib/chef/provider/template.rb +85 -53
- data/lib/chef/provider/user.rb +1 -1
- data/lib/chef/provider/user/dscl.rb +277 -0
- data/lib/chef/provider/user/useradd.rb +1 -0
- data/lib/chef/recipe.rb +2 -41
- data/lib/chef/resource.rb +9 -3
- data/lib/chef/resource/breakpoint.rb +35 -0
- data/lib/chef/resource/deploy.rb +16 -2
- data/lib/chef/resource/easy_install_package.rb +41 -0
- data/lib/chef/resource/erl_call.rb +83 -0
- data/lib/chef/resource/freebsd_package.rb +35 -0
- data/lib/chef/resource/log.rb +62 -0
- data/lib/chef/resource/mdadm.rb +82 -0
- data/lib/chef/resource/pacman_package.rb +33 -0
- data/lib/chef/resource/ruby_block.rb +21 -2
- data/lib/chef/resource/scm.rb +8 -0
- data/lib/chef/resource/subversion.rb +1 -0
- data/lib/chef/resource/user.rb +5 -2
- data/lib/chef/resource/yum_package.rb +36 -0
- data/lib/chef/resource_collection.rb +17 -9
- data/lib/chef/resource_collection/stepable_iterator.rb +124 -0
- data/lib/chef/rest.rb +166 -81
- data/lib/chef/role.rb +114 -38
- data/lib/chef/run_list.rb +15 -6
- data/lib/chef/runner.rb +13 -11
- data/lib/chef/search/query.rb +60 -0
- data/lib/chef/shef.rb +220 -0
- data/lib/chef/shef/ext.rb +297 -0
- data/lib/chef/shef/shef_session.rb +175 -0
- data/lib/chef/streaming_cookbook_uploader.rb +187 -0
- data/lib/chef/tasks/chef_repo.rake +53 -155
- data/lib/chef/util/file_edit.rb +94 -96
- data/lib/chef/webui_user.rb +233 -0
- metadata +219 -63
- data/distro/debian/etc/init.d/chef-indexer +0 -175
- data/distro/redhat/etc/chef/client.rb +0 -16
- data/distro/redhat/etc/chef/indexer.rb +0 -10
- data/distro/redhat/etc/chef/server.rb +0 -22
- data/distro/redhat/etc/init.d/chef-indexer +0 -76
- data/lib/chef/application/indexer.rb +0 -141
- data/lib/chef/queue.rb +0 -145
- data/lib/chef/search.rb +0 -88
- data/lib/chef/search/result.rb +0 -64
- data/lib/chef/search_index.rb +0 -77
- data/lib/chef/util/fileedit.rb +0 -121
@@ -0,0 +1,297 @@
|
|
1
|
+
# Author:: Daniel DeLeo (<dan@kallistec.com>)
|
2
|
+
# Copyright:: Copyright (c) 2009 Daniel DeLeo
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
module Shef
|
19
|
+
module Extensions
|
20
|
+
|
21
|
+
# Extensions to be included in object. These are methods that have to be
|
22
|
+
# defined on object but are not part of the user interface. Methods that
|
23
|
+
# are part of the user interface should have help text defined with the
|
24
|
+
# +desc+ macro, and need to be defined directly on Object in ext.rb
|
25
|
+
module Object
|
26
|
+
|
27
|
+
def ensure_session_select_defined
|
28
|
+
# irb breaks if you prematurely define IRB::JobMangager
|
29
|
+
# so these methods need to be defined at the latest possible time.
|
30
|
+
unless jobs.respond_to?(:select_session_by_context)
|
31
|
+
def jobs.select_session_by_context(&block)
|
32
|
+
@jobs.select { |job| block.call(job[1].context.main)}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
unless jobs.respond_to?(:session_select)
|
37
|
+
def jobs.select_shef_session(target_context)
|
38
|
+
session = if target_context.kind_of?(Class)
|
39
|
+
select_session_by_context { |main| main.kind_of?(target_context) }
|
40
|
+
else
|
41
|
+
select_session_by_context { |main| main.equal?(target_context) }
|
42
|
+
end
|
43
|
+
Array(session.first)[1]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def find_or_create_session_for(context_obj)
|
49
|
+
ensure_session_select_defined
|
50
|
+
if subsession = jobs.select_shef_session(context_obj)
|
51
|
+
jobs.switch(subsession)
|
52
|
+
else
|
53
|
+
irb(context_obj)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def help_banner(title=nil)
|
58
|
+
banner = []
|
59
|
+
banner << ""
|
60
|
+
banner << title if title
|
61
|
+
banner << "".ljust(80, "=")
|
62
|
+
banner << "| " + "Command".ljust(25) + "| " + "Description"
|
63
|
+
banner << "".ljust(80, "=")
|
64
|
+
self.class.all_help_descriptions.each do |cmd, description|
|
65
|
+
banner << "| " + cmd.ljust(25) + "| " + description
|
66
|
+
end
|
67
|
+
banner << "".ljust(80, "=")
|
68
|
+
banner << "\n"
|
69
|
+
banner.join("\n")
|
70
|
+
end
|
71
|
+
|
72
|
+
# helpfully returns +:on+ so we can have sugary syntax like `tracing on'
|
73
|
+
def on
|
74
|
+
:on
|
75
|
+
end
|
76
|
+
|
77
|
+
# returns +:off+ so you can just do `tracing off'
|
78
|
+
def off
|
79
|
+
:off
|
80
|
+
end
|
81
|
+
|
82
|
+
module ClassMethods
|
83
|
+
|
84
|
+
def help_descriptions
|
85
|
+
@help_descriptions ||= []
|
86
|
+
end
|
87
|
+
|
88
|
+
def all_help_descriptions
|
89
|
+
if sc = superclass
|
90
|
+
help_descriptions + sc.help_descriptions
|
91
|
+
else
|
92
|
+
help_descriptions
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def desc(help_text)
|
97
|
+
@desc = help_text
|
98
|
+
end
|
99
|
+
|
100
|
+
def subcommands(subcommand_help={})
|
101
|
+
@subcommand_help = subcommand_help
|
102
|
+
end
|
103
|
+
|
104
|
+
def method_added(mname)
|
105
|
+
if @desc
|
106
|
+
help_descriptions << [mname.to_s, @desc.to_s]
|
107
|
+
@desc = nil
|
108
|
+
end
|
109
|
+
if @subcommand_help
|
110
|
+
@subcommand_help.each do |subcommand, text|
|
111
|
+
help_descriptions << ["#{mname}.#{subcommand}", text.to_s]
|
112
|
+
end
|
113
|
+
end
|
114
|
+
@subcommand_help = {}
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
module String
|
122
|
+
def on_off_to_bool
|
123
|
+
case self
|
124
|
+
when "on"
|
125
|
+
true
|
126
|
+
when "off"
|
127
|
+
false
|
128
|
+
else
|
129
|
+
self
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
module Symbol
|
135
|
+
def on_off_to_bool
|
136
|
+
self.to_s.on_off_to_bool
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
module TrueClass
|
141
|
+
def to_on_off_str
|
142
|
+
"on"
|
143
|
+
end
|
144
|
+
|
145
|
+
def on_off_to_bool
|
146
|
+
self
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
module FalseClass
|
151
|
+
def to_on_off_str
|
152
|
+
"off"
|
153
|
+
end
|
154
|
+
|
155
|
+
def on_off_to_bool
|
156
|
+
self
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
class String
|
164
|
+
include Shef::Extensions::String
|
165
|
+
end
|
166
|
+
|
167
|
+
class Symbol
|
168
|
+
include Shef::Extensions::Symbol
|
169
|
+
end
|
170
|
+
|
171
|
+
class TrueClass
|
172
|
+
include Shef::Extensions::TrueClass
|
173
|
+
end
|
174
|
+
|
175
|
+
class FalseClass
|
176
|
+
include Shef::Extensions::FalseClass
|
177
|
+
end
|
178
|
+
|
179
|
+
class Object
|
180
|
+
extend Shef::Extensions::Object::ClassMethods
|
181
|
+
include Shef::Extensions::Object
|
182
|
+
include FileUtils
|
183
|
+
|
184
|
+
desc "prints this help message"
|
185
|
+
def shef_help(title="Help: Shef")
|
186
|
+
#puts Shef::Extensions::Object.help_banner("Shef Help")
|
187
|
+
puts help_banner(title)
|
188
|
+
:ucanhaz_halp
|
189
|
+
end
|
190
|
+
alias :halp :shef_help
|
191
|
+
|
192
|
+
desc "prints information about chef"
|
193
|
+
def version
|
194
|
+
puts "This is shef, the Chef shell.\n" +
|
195
|
+
" Chef Version: #{::Chef::VERSION}\n" +
|
196
|
+
" http://www.opscode.com/chef\n" +
|
197
|
+
" http://wiki.opscode.com/display/chef/Home"
|
198
|
+
:ucanhaz_automation
|
199
|
+
end
|
200
|
+
alias :shef :version
|
201
|
+
|
202
|
+
desc "switch to recipe mode"
|
203
|
+
def recipe
|
204
|
+
find_or_create_session_for Shef.session.recipe
|
205
|
+
:recipe
|
206
|
+
end
|
207
|
+
|
208
|
+
desc "switch to attributes mode"
|
209
|
+
def attributes
|
210
|
+
find_or_create_session_for Shef.session.node
|
211
|
+
:attributes
|
212
|
+
end
|
213
|
+
|
214
|
+
desc "returns the current node (i.e., this host)"
|
215
|
+
def node
|
216
|
+
Shef.session.node
|
217
|
+
end
|
218
|
+
|
219
|
+
desc "pretty print the node's attributes"
|
220
|
+
def ohai(key=nil)
|
221
|
+
pp(key ? node.attribute[key] : node.attribute)
|
222
|
+
end
|
223
|
+
|
224
|
+
desc "run chef using the current recipe"
|
225
|
+
def run_chef
|
226
|
+
Chef::Log.level = :debug
|
227
|
+
session = Shef.session
|
228
|
+
session.rebuild_collection
|
229
|
+
runrun = Chef::Runner.new(node, session.collection, session.definitions, session.cookbook_loader).converge
|
230
|
+
Chef::Log.level = :info
|
231
|
+
runrun
|
232
|
+
end
|
233
|
+
|
234
|
+
desc "returns an object to control a paused chef run"
|
235
|
+
subcommands :resume => "resume the chef run",
|
236
|
+
:step => "run only the next resource",
|
237
|
+
:skip_back => "move back in the run list",
|
238
|
+
:skip_forward => "move forward in the run list"
|
239
|
+
def chef_run
|
240
|
+
Shef.session.collection.iterator
|
241
|
+
end
|
242
|
+
|
243
|
+
desc "resets the current recipe"
|
244
|
+
def reset
|
245
|
+
Shef.session.reset!
|
246
|
+
end
|
247
|
+
|
248
|
+
desc "turns printout of return values on or off"
|
249
|
+
def echo(on_or_off)
|
250
|
+
conf.echo = on_or_off.on_off_to_bool
|
251
|
+
end
|
252
|
+
|
253
|
+
desc "says if echo is on or off"
|
254
|
+
def echo?
|
255
|
+
puts "echo is #{conf.echo.to_on_off_str}"
|
256
|
+
end
|
257
|
+
|
258
|
+
desc "turns on or off tracing of execution. *verbose*"
|
259
|
+
def tracing(on_or_off)
|
260
|
+
conf.use_tracer = on_or_off.on_off_to_bool
|
261
|
+
tracing?
|
262
|
+
end
|
263
|
+
alias :trace :tracing
|
264
|
+
|
265
|
+
desc "says if tracing is on or off"
|
266
|
+
def tracing?
|
267
|
+
puts "tracing is #{conf.use_tracer.to_on_off_str}"
|
268
|
+
end
|
269
|
+
alias :trace? :tracing?
|
270
|
+
|
271
|
+
desc "simple ls style command"
|
272
|
+
def ls(directory)
|
273
|
+
Dir.entries(directory)
|
274
|
+
end
|
275
|
+
|
276
|
+
end
|
277
|
+
|
278
|
+
class Chef
|
279
|
+
class Recipe
|
280
|
+
|
281
|
+
def shef_help
|
282
|
+
super("Help: Shef/Recipe")
|
283
|
+
end
|
284
|
+
|
285
|
+
alias :original_resources :resources
|
286
|
+
|
287
|
+
desc "list all the resources on the current recipe"
|
288
|
+
def resources(*args)
|
289
|
+
if args.empty?
|
290
|
+
pp collection.instance_variable_get(:@resources_by_name).keys
|
291
|
+
else
|
292
|
+
pp resources = original_resources(*args)
|
293
|
+
resources
|
294
|
+
end
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
@@ -0,0 +1,175 @@
|
|
1
|
+
# Author:: Daniel DeLeo (<dan@kallistec.com>)
|
2
|
+
# Copyright:: Copyright (c) 2009 Daniel DeLeo
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
module Shef
|
19
|
+
class ShefSession
|
20
|
+
include Singleton
|
21
|
+
|
22
|
+
attr_accessor :node, :compile, :recipe
|
23
|
+
attr_reader :node_attributes, :client
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
@node_built = false
|
27
|
+
end
|
28
|
+
|
29
|
+
def node_built?
|
30
|
+
!!@node_built
|
31
|
+
end
|
32
|
+
|
33
|
+
def reset!
|
34
|
+
loading do
|
35
|
+
rebuild_node
|
36
|
+
@node = client.node
|
37
|
+
node.consume_attributes(node_attributes) if node_attributes
|
38
|
+
shorten_node_inspect
|
39
|
+
@recipe = Chef::Recipe.new(nil, nil, @node)
|
40
|
+
@node_built = true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def node_attributes=(attrs)
|
45
|
+
@node_attributes = attrs
|
46
|
+
@node.consume_attributes(@node_attributes)
|
47
|
+
end
|
48
|
+
|
49
|
+
def collection
|
50
|
+
@collection || rebuild_collection
|
51
|
+
end
|
52
|
+
|
53
|
+
def definitions
|
54
|
+
nil
|
55
|
+
end
|
56
|
+
|
57
|
+
def cookbook_loader
|
58
|
+
nil
|
59
|
+
end
|
60
|
+
|
61
|
+
def save_node
|
62
|
+
raise "Not Supported! #{self.class.name} doesn't support #save_node, maybe you need to run shef in client mode?"
|
63
|
+
end
|
64
|
+
|
65
|
+
def rebuild_collection
|
66
|
+
raise "Not Implemented! :rebuild_collection should be implemented by subclasses"
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def loading
|
72
|
+
show_loading_progress
|
73
|
+
begin
|
74
|
+
yield
|
75
|
+
rescue => e
|
76
|
+
loading_complete(false)
|
77
|
+
raise e
|
78
|
+
else
|
79
|
+
loading_complete(true)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def show_loading_progress
|
84
|
+
print "Loading"
|
85
|
+
@loading = true
|
86
|
+
@dot_printer = Thread.new do
|
87
|
+
while @loading
|
88
|
+
print "."
|
89
|
+
sleep 0.5
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def loading_complete(success)
|
95
|
+
@loading = false
|
96
|
+
@dot_printer.join
|
97
|
+
msg = success ? "done.\n\n" : "epic fail!\n\n"
|
98
|
+
print msg
|
99
|
+
end
|
100
|
+
|
101
|
+
def shorten_node_inspect
|
102
|
+
def @node.inspect
|
103
|
+
"<Chef::Node:0x#{self.object_id.to_s(16)} @name=\"#{self.name}\">"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def rebuild_node
|
108
|
+
raise "Not Implemented! :rebuild_node should be implemented by subclasses"
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
class StandAloneSession < ShefSession
|
114
|
+
|
115
|
+
def rebuild_collection
|
116
|
+
@collection = @recipe.collection
|
117
|
+
end
|
118
|
+
|
119
|
+
private
|
120
|
+
|
121
|
+
def rebuild_node
|
122
|
+
@client = Chef::Client.new
|
123
|
+
@client.determine_node_name
|
124
|
+
@client.build_node(@client.node_name, true)
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
class SoloSession < ShefSession
|
130
|
+
|
131
|
+
def definitions
|
132
|
+
@compile.definitions
|
133
|
+
end
|
134
|
+
|
135
|
+
def cookbook_loader
|
136
|
+
@compile.cookbook_loader
|
137
|
+
end
|
138
|
+
|
139
|
+
def rebuild_collection
|
140
|
+
@compile = Chef::Compile.new(@client.node)
|
141
|
+
|
142
|
+
@collection = @compile.collection
|
143
|
+
@collection << @recipe.collection.all_resources
|
144
|
+
@collection
|
145
|
+
end
|
146
|
+
|
147
|
+
private
|
148
|
+
|
149
|
+
def rebuild_node
|
150
|
+
@client = Chef::Client.new
|
151
|
+
@client.determine_node_name
|
152
|
+
@client.build_node(@client.node_name, true)
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
class ClientSession < SoloSession
|
158
|
+
|
159
|
+
def save_node
|
160
|
+
@client.save_node
|
161
|
+
end
|
162
|
+
|
163
|
+
private
|
164
|
+
|
165
|
+
def rebuild_node
|
166
|
+
@client = Chef::Client.new
|
167
|
+
@client.determine_node_name
|
168
|
+
@client.register
|
169
|
+
@client.build_node(@client.node_name, false)
|
170
|
+
|
171
|
+
@client.sync_cookbooks
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
end
|