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
data/lib/chef/knife.rb
ADDED
@@ -0,0 +1,309 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Author:: Christopher Brown (<cb@opscode.com>)
|
4
|
+
# Copyright:: Copyright (c) 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 'mixlib/cli'
|
21
|
+
require 'chef/mixin/convert_to_class_name'
|
22
|
+
|
23
|
+
class Chef
|
24
|
+
class Knife
|
25
|
+
include Mixlib::CLI
|
26
|
+
extend Chef::Mixin::ConvertToClassName
|
27
|
+
|
28
|
+
attr_accessor :name_args
|
29
|
+
|
30
|
+
# Load all the sub-commands
|
31
|
+
def self.load_commands
|
32
|
+
@sub_classes = Hash.new
|
33
|
+
Dir[
|
34
|
+
File.expand_path(File.join(File.dirname(__FILE__), 'knife', '*.rb'))
|
35
|
+
].each do |knife_file|
|
36
|
+
require knife_file
|
37
|
+
snake_case_file_name = File.basename(knife_file).sub(/\.rb$/, '')
|
38
|
+
@sub_classes[snake_case_file_name] = convert_to_class_name(snake_case_file_name)
|
39
|
+
end
|
40
|
+
@sub_classes
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.list_commands
|
44
|
+
load_commands
|
45
|
+
@sub_classes.keys.sort.each do |snake_case|
|
46
|
+
klass_instance = build_sub_class(snake_case)
|
47
|
+
klass_instance.parse_options
|
48
|
+
puts klass_instance.opt_parser
|
49
|
+
puts
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.build_sub_class(snake_case, merge_opts=nil)
|
54
|
+
klass = Chef::Knife.const_get(@sub_classes[snake_case])
|
55
|
+
klass.options.merge!(merge_opts) if merge_opts
|
56
|
+
klass.new
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.find_command(args=ARGV, merge_opts={})
|
60
|
+
load_commands
|
61
|
+
|
62
|
+
non_dash_args = Array.new
|
63
|
+
args.each do |arg|
|
64
|
+
non_dash_args << arg if arg =~ /^([[:alnum:]]|_)+$/
|
65
|
+
end
|
66
|
+
|
67
|
+
to_try = non_dash_args.length
|
68
|
+
klass_instance = nil
|
69
|
+
cli_bits = nil
|
70
|
+
|
71
|
+
while(to_try >= 0)
|
72
|
+
cli_bits = non_dash_args[0..to_try]
|
73
|
+
snake_case_class_name = cli_bits.join("_")
|
74
|
+
|
75
|
+
if @sub_classes.has_key?(snake_case_class_name)
|
76
|
+
klass_instance = build_sub_class(snake_case_class_name, merge_opts)
|
77
|
+
break
|
78
|
+
end
|
79
|
+
|
80
|
+
to_try = to_try - 1
|
81
|
+
end
|
82
|
+
|
83
|
+
unless klass_instance
|
84
|
+
Chef::Log.fatal("Cannot find sub command for: #{args.join(' ')}")
|
85
|
+
Chef::Knife.list_commands
|
86
|
+
exit 10
|
87
|
+
end
|
88
|
+
|
89
|
+
extra = klass_instance.parse_options(args)
|
90
|
+
if klass_instance.config[:help]
|
91
|
+
puts klass_instance.opt_parser
|
92
|
+
exit 1
|
93
|
+
end
|
94
|
+
klass_instance.name_args = extra.inject([]) { |c, i| cli_bits.include?(i) ? cli_bits.delete(i) : c << i; c }
|
95
|
+
klass_instance.configure_chef
|
96
|
+
klass_instance
|
97
|
+
end
|
98
|
+
|
99
|
+
def ask_question(q)
|
100
|
+
print q
|
101
|
+
a = STDIN.readline
|
102
|
+
a.chomp!
|
103
|
+
a
|
104
|
+
end
|
105
|
+
|
106
|
+
def configure_chef
|
107
|
+
if !config[:config_file].nil? && File.exists?(config[:config_file]) && File.readable?(config[:config_file])
|
108
|
+
Chef::Config.from_file(config[:config_file])
|
109
|
+
end
|
110
|
+
|
111
|
+
Chef::Config[:log_level] = config[:log_level] if config[:log_level]
|
112
|
+
Chef::Config[:log_location] = config[:log_location] if config[:log_location]
|
113
|
+
Chef::Config[:node_name] = config[:node_name] if config[:node_name]
|
114
|
+
Chef::Config[:client_key] = config[:client_key] if config[:client_key]
|
115
|
+
Chef::Config[:chef_server_url] = config[:chef_server_url] if config[:chef_server_url]
|
116
|
+
Mixlib::Log::Formatter.show_time = false
|
117
|
+
Chef::Log.init(Chef::Config[:log_location])
|
118
|
+
Chef::Log.level(Chef::Config[:log_level])
|
119
|
+
|
120
|
+
if Chef::Config[:node_name].nil?
|
121
|
+
raise ArgumentError, "No user specified, pass via -u or specifiy 'node_name' in #{config[:config_file] ? config[:config_file] : "~/.chef/knife.rb"}"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def pretty_print(data)
|
126
|
+
puts data
|
127
|
+
end
|
128
|
+
|
129
|
+
def json_pretty_print(data)
|
130
|
+
puts JSON.pretty_generate(data)
|
131
|
+
end
|
132
|
+
|
133
|
+
def format_list_for_display(list)
|
134
|
+
config[:with_uri] ? list : list.keys.sort { |a,b| a <=> b }
|
135
|
+
end
|
136
|
+
|
137
|
+
def format_for_display(item)
|
138
|
+
data = item.kind_of?(Chef::DataBagItem) ? item.raw_data : item
|
139
|
+
|
140
|
+
if config[:attribute]
|
141
|
+
config[:attribute].split(".").each do |attr|
|
142
|
+
if data.respond_to?(:[])
|
143
|
+
data = data[attr]
|
144
|
+
else
|
145
|
+
data = data.send(attr.to_sym)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
{ config[:attribute] => data.kind_of?(Chef::Node::Attribute) ? data.to_hash: data }
|
149
|
+
elsif config[:run_list]
|
150
|
+
data = data.run_list.run_list
|
151
|
+
{ "run_list" => data }
|
152
|
+
elsif config[:id_only]
|
153
|
+
data.respond_to?(:name) ? data.name : data["id"]
|
154
|
+
else
|
155
|
+
data
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def edit_data(data, parse_output=true)
|
160
|
+
output = JSON.pretty_generate(data)
|
161
|
+
|
162
|
+
if (!config[:no_editor])
|
163
|
+
filename = "knife-edit-"
|
164
|
+
0.upto(20) { filename += rand(9).to_s }
|
165
|
+
filename << ".js"
|
166
|
+
filename = File.join(Dir.tmpdir, filename)
|
167
|
+
tf = File.open(filename, "w")
|
168
|
+
tf.sync = true
|
169
|
+
tf.puts output
|
170
|
+
tf.close
|
171
|
+
raise "Please set EDITOR environment variable" unless system("#{config[:editor]} #{tf.path}")
|
172
|
+
tf = File.open(filename, "r")
|
173
|
+
output = tf.gets(nil)
|
174
|
+
tf.close
|
175
|
+
File.unlink(filename)
|
176
|
+
end
|
177
|
+
|
178
|
+
parse_output ? JSON.parse(output) : output
|
179
|
+
end
|
180
|
+
|
181
|
+
def confirm(question)
|
182
|
+
return true if config[:yes]
|
183
|
+
|
184
|
+
print "#{question}? (Y/N) "
|
185
|
+
answer = STDIN.readline
|
186
|
+
answer.chomp!
|
187
|
+
case answer
|
188
|
+
when "Y", "y"
|
189
|
+
true
|
190
|
+
when "N", "n"
|
191
|
+
Chef::Log.info("You said no, so I'm done here.")
|
192
|
+
exit 3
|
193
|
+
else
|
194
|
+
Chef::Log.error("I have no idea what to do with #{answer}")
|
195
|
+
Chef::Log.error("Just say Y or N, please.")
|
196
|
+
confirm(question)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def load_from_file(klass, from_file)
|
201
|
+
from_file = @name_args[0]
|
202
|
+
relative_file = File.expand_path(File.join(Dir.pwd, 'roles', from_file))
|
203
|
+
filename = nil
|
204
|
+
|
205
|
+
if file_exists_and_is_readable?(from_file)
|
206
|
+
filename = from_file
|
207
|
+
elsif file_exists_and_is_readable?(relative_file)
|
208
|
+
filename = relative_file
|
209
|
+
else
|
210
|
+
Chef::Log.fatal("Cannot find file #{from_file}")
|
211
|
+
exit 30
|
212
|
+
end
|
213
|
+
|
214
|
+
case from_file
|
215
|
+
when /\.(js|json)$/
|
216
|
+
JSON.parse(IO.read(filename))
|
217
|
+
when /\.rb$/
|
218
|
+
r = klass.new
|
219
|
+
r.from_file(filename)
|
220
|
+
r
|
221
|
+
else
|
222
|
+
Chef::Log.fatal("File must end in .js, .json, or .rb")
|
223
|
+
exit 30
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
def file_exists_and_is_readable?(file)
|
228
|
+
File.exists?(file) && File.readable?(file)
|
229
|
+
end
|
230
|
+
|
231
|
+
def edit_object(klass, name)
|
232
|
+
object = klass.load(name)
|
233
|
+
|
234
|
+
output = edit_data(object)
|
235
|
+
|
236
|
+
output.save
|
237
|
+
|
238
|
+
Chef::Log.info("Saved #{output}")
|
239
|
+
|
240
|
+
json_pretty_print(format_for_display(object)) if config[:print_after]
|
241
|
+
end
|
242
|
+
|
243
|
+
def create_object(object, pretty_name=nil, &block)
|
244
|
+
output = edit_data(object)
|
245
|
+
|
246
|
+
if Kernel.block_given?
|
247
|
+
output = block.call(output)
|
248
|
+
else
|
249
|
+
output.save
|
250
|
+
end
|
251
|
+
|
252
|
+
pretty_name ||= output
|
253
|
+
|
254
|
+
Chef::Log.info("Created (or updated) #{pretty_name}")
|
255
|
+
|
256
|
+
json_pretty_print(output) if config[:print_after]
|
257
|
+
end
|
258
|
+
|
259
|
+
def delete_object(klass, name, delete_name=nil, &block)
|
260
|
+
confirm("Do you really want to delete #{name}")
|
261
|
+
|
262
|
+
if Kernel.block_given?
|
263
|
+
object = block.call
|
264
|
+
else
|
265
|
+
object = klass.load(name)
|
266
|
+
object.destroy
|
267
|
+
end
|
268
|
+
|
269
|
+
json_pretty_print(format_for_display(object)) if config[:print_after]
|
270
|
+
|
271
|
+
obj_name = delete_name ? "#{delete_name}[#{name}]" : object
|
272
|
+
Chef::Log.warn("Deleted #{obj_name}!")
|
273
|
+
end
|
274
|
+
|
275
|
+
def bulk_delete(klass, fancy_name, delete_name=nil, list=nil, regex=nil, &block)
|
276
|
+
object_list = list ? list : klass.list(true)
|
277
|
+
|
278
|
+
if regex
|
279
|
+
to_delete = Hash.new
|
280
|
+
object_list.each_key do |object|
|
281
|
+
next if regex && object !~ /#{regex}/
|
282
|
+
to_delete[object] = object_list[object]
|
283
|
+
end
|
284
|
+
else
|
285
|
+
to_delete = object_list
|
286
|
+
end
|
287
|
+
|
288
|
+
json_pretty_print(format_list_for_display(to_delete))
|
289
|
+
|
290
|
+
confirm("Do you really want to delete the above items")
|
291
|
+
|
292
|
+
to_delete.each do |name, object|
|
293
|
+
if Kernel.block_given?
|
294
|
+
block.call(name, object)
|
295
|
+
else
|
296
|
+
object.destroy
|
297
|
+
end
|
298
|
+
json_pretty_print(format_for_display(object)) if config[:print_after]
|
299
|
+
Chef::Log.warn("Deleted #{fancy_name} #{name}")
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
def rest
|
304
|
+
@rest ||= Chef::REST.new(Chef::Config[:chef_server_url])
|
305
|
+
end
|
306
|
+
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2009 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/knife'
|
20
|
+
require 'chef/api_client'
|
21
|
+
require 'json'
|
22
|
+
|
23
|
+
class Chef
|
24
|
+
class Knife
|
25
|
+
class ClientBulkDelete < Knife
|
26
|
+
|
27
|
+
banner "Sub-Command: client bulk delete REGEX (options)"
|
28
|
+
|
29
|
+
def run
|
30
|
+
if @name_args.length < 1
|
31
|
+
Chef::Log.fatal("You must supply a regular expression to match the results against")
|
32
|
+
exit 42
|
33
|
+
else
|
34
|
+
bulk_delete(Chef::ApiClient, "client", nil, nil, @name_args[0])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2009 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/knife'
|
20
|
+
require 'chef/api_client'
|
21
|
+
require 'json'
|
22
|
+
|
23
|
+
class Chef
|
24
|
+
class Knife
|
25
|
+
class ClientCreate < Knife
|
26
|
+
|
27
|
+
option :file,
|
28
|
+
:short => "-f FILE",
|
29
|
+
:long => "--file FILE",
|
30
|
+
:description => "Write the key to a file"
|
31
|
+
|
32
|
+
option :admin,
|
33
|
+
:short => "-a",
|
34
|
+
:long => "--admin",
|
35
|
+
:description => "Create the client as an admin",
|
36
|
+
:boolean => true
|
37
|
+
|
38
|
+
banner "Sub-Command: client create CLIENT (options)"
|
39
|
+
|
40
|
+
def run
|
41
|
+
client = Chef::ApiClient.new
|
42
|
+
client.name(@name_args[0])
|
43
|
+
client.admin(config[:admin])
|
44
|
+
|
45
|
+
output = edit_data(client)
|
46
|
+
|
47
|
+
key = output.save
|
48
|
+
|
49
|
+
Chef::Log.info("Created (or updated) #{output}")
|
50
|
+
|
51
|
+
if config[:file]
|
52
|
+
File.open(config[:file], "w") do |f|
|
53
|
+
f.print(key['private_key'])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
puts key['private_key']
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2009 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/knife'
|
20
|
+
require 'chef/api_client'
|
21
|
+
require 'json'
|
22
|
+
|
23
|
+
class Chef
|
24
|
+
class Knife
|
25
|
+
class ClientDelete < Knife
|
26
|
+
|
27
|
+
banner "Sub-Command: client delete CLIENT (options)"
|
28
|
+
|
29
|
+
def run
|
30
|
+
delete_object(Chef::ApiClient, @name_args[0])
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|