chef 0.9.8.beta.1 → 0.9.8.beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/shef +5 -18
- data/distro/common/man/man8/knife.8 +632 -243
- data/distro/common/markdown/knife.mkd +251 -44
- data/lib/chef/application/knife.rb +4 -0
- data/lib/chef/data_bag.rb +4 -4
- data/lib/chef/data_bag_item.rb +9 -1
- data/lib/chef/knife.rb +15 -6
- data/lib/chef/knife/bootstrap.rb +1 -7
- data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +32 -0
- data/lib/chef/knife/cookbook_create.rb +83 -33
- data/lib/chef/knife/ec2_server_create.rb +25 -3
- data/lib/chef/mixin/language.rb +9 -1
- data/lib/chef/provider/file.rb +1 -0
- data/lib/chef/provider/package/zypper.rb +2 -2
- data/lib/chef/resource/remote_file.rb +1 -1
- data/lib/chef/shef.rb +146 -47
- data/lib/chef/shef/ext.rb +436 -181
- data/lib/chef/shef/model_wrapper.rb +120 -0
- data/lib/chef/shef/shef_rest.rb +28 -0
- data/lib/chef/shef/shef_session.rb +91 -4
- data/lib/chef/version.rb +1 -1
- metadata +6 -3
@@ -0,0 +1,120 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Daniel DeLeo (<dan@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2010 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/convert_to_class_name'
|
20
|
+
require 'chef/mixin/language'
|
21
|
+
|
22
|
+
module Shef
|
23
|
+
class ModelWrapper
|
24
|
+
|
25
|
+
include Chef::Mixin::ConvertToClassName
|
26
|
+
|
27
|
+
attr_reader :model_symbol
|
28
|
+
|
29
|
+
def initialize(model_class, symbol=nil)
|
30
|
+
@model_class = model_class
|
31
|
+
@model_symbol = symbol || convert_to_snake_case(model_class.name, "Chef").to_sym
|
32
|
+
end
|
33
|
+
|
34
|
+
def search(query)
|
35
|
+
return all if query.to_s == "all"
|
36
|
+
results = []
|
37
|
+
Chef::Search::Query.new.search(@model_symbol, format_query(query)) do |obj|
|
38
|
+
if block_given?
|
39
|
+
results << yield(obj)
|
40
|
+
else
|
41
|
+
results << obj
|
42
|
+
end
|
43
|
+
end
|
44
|
+
results
|
45
|
+
end
|
46
|
+
|
47
|
+
alias :find :search
|
48
|
+
|
49
|
+
def all(&block)
|
50
|
+
all_objects = list_objects
|
51
|
+
block_given? ? all_objects.map(&block) : all_objects
|
52
|
+
end
|
53
|
+
|
54
|
+
alias :list :all
|
55
|
+
|
56
|
+
def show(obj_id)
|
57
|
+
@model_class.load(obj_id)
|
58
|
+
end
|
59
|
+
|
60
|
+
alias :load :show
|
61
|
+
|
62
|
+
def transform(what_to_transform, &block)
|
63
|
+
if what_to_transform == :all
|
64
|
+
objects_to_transform = list_objects
|
65
|
+
else
|
66
|
+
objects_to_transform = search(what_to_transform)
|
67
|
+
end
|
68
|
+
objects_to_transform.each do |obj|
|
69
|
+
if result = yield(obj)
|
70
|
+
obj.save
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
alias :bulk_edit :transform
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
# paper over inconsistencies in the model classes APIs, and return the objects
|
80
|
+
# the user wanted instead of the URI=>object stuff
|
81
|
+
def list_objects
|
82
|
+
objects = @model_class.method(:list).arity == 0? @model_class.list : @model_class.list(true)
|
83
|
+
objects.map { |obj| Array(obj).find {|o| o.kind_of?(@model_class)} }
|
84
|
+
end
|
85
|
+
|
86
|
+
def format_query(query)
|
87
|
+
if query.respond_to?(:keys)
|
88
|
+
query.map { |key, value| "#{key}:#{value}" }.join(" AND ")
|
89
|
+
else
|
90
|
+
query
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
class NamedDataBagWrapper < ModelWrapper
|
96
|
+
|
97
|
+
def initialize(databag_name)
|
98
|
+
@model_symbol = @databag_name = databag_name
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
alias :list :all
|
103
|
+
|
104
|
+
def show(item)
|
105
|
+
Chef::DataBagItem.load(@databag_name, item)
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
def list_objects
|
111
|
+
all_items = []
|
112
|
+
Chef::Search::Query.new.search(@databag_name) do |item|
|
113
|
+
all_items << item
|
114
|
+
end
|
115
|
+
all_items
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Daniel DeLeo (<dan@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2010 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
|
+
module Shef
|
20
|
+
class ShefREST < Chef::REST
|
21
|
+
|
22
|
+
alias :get :get_rest
|
23
|
+
alias :put :put_rest
|
24
|
+
alias :post :post_rest
|
25
|
+
alias :delete :delete_rest
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -26,6 +26,11 @@ module Shef
|
|
26
26
|
class ShefSession
|
27
27
|
include Singleton
|
28
28
|
|
29
|
+
def self.session_type(type=nil)
|
30
|
+
@session_type = type if type
|
31
|
+
@session_type
|
32
|
+
end
|
33
|
+
|
29
34
|
attr_accessor :node, :compile, :recipe, :run_context
|
30
35
|
attr_reader :node_attributes, :client
|
31
36
|
def initialize
|
@@ -40,10 +45,12 @@ module Shef
|
|
40
45
|
loading do
|
41
46
|
rebuild_node
|
42
47
|
@node = client.node
|
48
|
+
shorten_node_inspect
|
49
|
+
Shef::Extensions.extend_context_node(@node)
|
43
50
|
rebuild_context
|
44
51
|
node.consume_attributes(node_attributes) if node_attributes
|
45
|
-
shorten_node_inspect
|
46
52
|
@recipe = Chef::Recipe.new(nil, nil, run_context)
|
53
|
+
Shef::Extensions.extend_context_recipe(@recipe)
|
47
54
|
@node_built = true
|
48
55
|
end
|
49
56
|
end
|
@@ -122,6 +129,8 @@ module Shef
|
|
122
129
|
end
|
123
130
|
|
124
131
|
class StandAloneSession < ShefSession
|
132
|
+
|
133
|
+
session_type :standalone
|
125
134
|
|
126
135
|
def rebuild_context
|
127
136
|
@run_context = Chef::RunContext.new(@node, {}) # no recipes
|
@@ -133,12 +142,14 @@ module Shef
|
|
133
142
|
Chef::Config[:solo] = true
|
134
143
|
@client = Chef::Client.new
|
135
144
|
@client.run_ohai
|
136
|
-
@client.build_node
|
145
|
+
@client.build_node
|
137
146
|
end
|
138
147
|
|
139
148
|
end
|
140
149
|
|
141
150
|
class SoloSession < ShefSession
|
151
|
+
|
152
|
+
session_type :solo
|
142
153
|
|
143
154
|
def definitions
|
144
155
|
@run_context.definitions
|
@@ -155,12 +166,14 @@ module Shef
|
|
155
166
|
Chef::Config[:solo] = true
|
156
167
|
@client = Chef::Client.new
|
157
168
|
@client.run_ohai
|
158
|
-
@client.build_node
|
169
|
+
@client.build_node
|
159
170
|
end
|
160
171
|
|
161
172
|
end
|
162
173
|
|
163
174
|
class ClientSession < SoloSession
|
175
|
+
|
176
|
+
session_type :solo
|
164
177
|
|
165
178
|
def save_node
|
166
179
|
@client.save_node
|
@@ -174,10 +187,84 @@ module Shef
|
|
174
187
|
@client = Chef::Client.new
|
175
188
|
@client.run_ohai
|
176
189
|
@client.register
|
177
|
-
@client.build_node
|
190
|
+
@client.build_node
|
178
191
|
|
179
192
|
@client.sync_cookbooks({})
|
180
193
|
end
|
181
194
|
|
182
195
|
end
|
196
|
+
|
197
|
+
class DoppelGangerClient < Chef::Client
|
198
|
+
|
199
|
+
attr_reader :node_name
|
200
|
+
|
201
|
+
def initialize(node_name)
|
202
|
+
@node_name = node_name
|
203
|
+
@ohai = Ohai::System.new
|
204
|
+
end
|
205
|
+
|
206
|
+
# Run the very smallest amount of ohai we can get away with and still
|
207
|
+
# hope to have things work. Otherwise we're not very good doppelgangers
|
208
|
+
def run_ohai
|
209
|
+
@ohai.require_plugin('os')
|
210
|
+
end
|
211
|
+
|
212
|
+
# DoppelGanger implementation of build_node. preserves as many of the node's
|
213
|
+
# attributes, and does not save updates to the server
|
214
|
+
def build_node
|
215
|
+
Chef::Log.debug("Building node object for #{@node_name}")
|
216
|
+
|
217
|
+
@node = Chef::Node.find_or_create(node_name)
|
218
|
+
|
219
|
+
ohai_data = @ohai.data.merge(@node.automatic_attrs)
|
220
|
+
|
221
|
+
@node.process_external_attrs(ohai_data,nil)
|
222
|
+
@node.reset_defaults_and_overrides
|
223
|
+
|
224
|
+
@node
|
225
|
+
end
|
226
|
+
|
227
|
+
def register
|
228
|
+
@rest = Chef::REST.new(Chef::Config[:chef_server_url], Chef::Config[:node_name], Chef::Config[:client_key])
|
229
|
+
end
|
230
|
+
|
231
|
+
end
|
232
|
+
|
233
|
+
class DoppelGangerSession < ClientSession
|
234
|
+
|
235
|
+
session_type "doppelganger client"
|
236
|
+
|
237
|
+
def save_node
|
238
|
+
puts "A doppelganger should think twice before saving the node"
|
239
|
+
end
|
240
|
+
|
241
|
+
def assume_identity(node_name)
|
242
|
+
Chef::Config[:doppelganger] = @node_name = node_name
|
243
|
+
reset!
|
244
|
+
rescue Exception => e
|
245
|
+
puts "#{e.class.name}: #{e.message}"
|
246
|
+
puts Array(e.backtrace).join("\n")
|
247
|
+
puts
|
248
|
+
puts "* " * 40
|
249
|
+
puts "failed to assume the identity of node '#{node_name}', resetting"
|
250
|
+
puts "* " * 40
|
251
|
+
puts
|
252
|
+
Chef::Config[:doppelganger] = false
|
253
|
+
@node_built = false
|
254
|
+
Shef.session
|
255
|
+
end
|
256
|
+
|
257
|
+
def rebuild_node
|
258
|
+
# Make sure the client knows this is not chef solo
|
259
|
+
Chef::Config[:solo] = false
|
260
|
+
@client = DoppelGangerClient.new(@node_name)
|
261
|
+
@client.run_ohai
|
262
|
+
@client.register
|
263
|
+
@client.build_node
|
264
|
+
|
265
|
+
@client.sync_cookbooks({})
|
266
|
+
end
|
267
|
+
|
268
|
+
end
|
269
|
+
|
183
270
|
end
|
data/lib/chef/version.rb
CHANGED
metadata
CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
|
|
7
7
|
- 9
|
8
8
|
- 8
|
9
9
|
- beta
|
10
|
-
-
|
11
|
-
version: 0.9.8.beta.
|
10
|
+
- 2
|
11
|
+
version: 0.9.8.beta.2
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Adam Jacob
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-07-
|
19
|
+
date: 2010-07-29 00:00:00 -07:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -308,6 +308,7 @@ files:
|
|
308
308
|
- lib/chef/index_queue.rb
|
309
309
|
- lib/chef/knife/bootstrap/centos5-gems.erb
|
310
310
|
- lib/chef/knife/bootstrap/fedora13-gems.erb
|
311
|
+
- lib/chef/knife/bootstrap/ubuntu10.04-apt.erb
|
311
312
|
- lib/chef/knife/bootstrap/ubuntu10.04-gems.erb
|
312
313
|
- lib/chef/knife/bootstrap.rb
|
313
314
|
- lib/chef/knife/client_bulk_delete.rb
|
@@ -539,6 +540,8 @@ files:
|
|
539
540
|
- lib/chef/sandbox.rb
|
540
541
|
- lib/chef/search/query.rb
|
541
542
|
- lib/chef/shef/ext.rb
|
543
|
+
- lib/chef/shef/model_wrapper.rb
|
544
|
+
- lib/chef/shef/shef_rest.rb
|
542
545
|
- lib/chef/shef/shef_session.rb
|
543
546
|
- lib/chef/shef.rb
|
544
547
|
- lib/chef/shell_out.rb
|