chef 0.9.18 → 0.10.0.beta.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +0 -3
- data/distro/arch/etc/rc.d/chef-server +0 -4
- data/distro/arch/etc/rc.d/chef-server-webui +0 -4
- data/distro/arch/etc/rc.d/chef-solr +0 -4
- data/distro/arch/etc/rc.d/chef-solr-indexer +0 -4
- data/lib/chef.rb +3 -3
- data/lib/chef/api_client.rb +1 -1
- data/lib/chef/application.rb +11 -1
- data/lib/chef/application/client.rb +18 -22
- data/lib/chef/application/knife.rb +28 -29
- data/lib/chef/application/solo.rb +14 -12
- data/lib/chef/client.rb +112 -54
- data/lib/chef/config.rb +4 -0
- data/lib/chef/cookbook/chefignore.rb +66 -0
- data/lib/chef/cookbook/cookbook_collection.rb +6 -5
- data/lib/chef/cookbook/cookbook_version_loader.rb +151 -0
- data/lib/chef/cookbook/file_system_file_vendor.rb +10 -8
- data/lib/chef/cookbook/metadata.rb +200 -108
- data/lib/chef/cookbook_loader.rb +39 -163
- data/lib/chef/cookbook_uploader.rb +100 -78
- data/lib/chef/cookbook_version.rb +92 -47
- data/lib/chef/cookbook_version_selector.rb +163 -0
- data/lib/chef/couchdb.rb +9 -1
- data/lib/chef/data_bag.rb +1 -1
- data/lib/chef/data_bag_item.rb +1 -1
- data/lib/chef/encrypted_data_bag_item.rb +126 -0
- data/lib/chef/environment.rb +386 -0
- data/lib/chef/exceptions.rb +82 -1
- data/lib/chef/index_queue/amqp_client.rb +15 -12
- data/lib/chef/index_queue/indexable.rb +38 -4
- data/lib/chef/json_compat.rb +3 -3
- data/lib/chef/knife.rb +97 -202
- data/lib/chef/knife/bootstrap.rb +27 -61
- data/lib/chef/knife/bootstrap/archlinux-gems.erb +4 -2
- data/lib/chef/knife/bootstrap/centos5-gems.erb +6 -15
- data/lib/chef/knife/bootstrap/fedora13-gems.erb +3 -4
- data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +2 -2
- data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +6 -5
- data/lib/chef/knife/client_bulk_delete.rb +6 -3
- data/lib/chef/knife/client_create.rb +13 -10
- data/lib/chef/knife/client_delete.rb +10 -7
- data/lib/chef/knife/client_edit.rb +9 -6
- data/lib/chef/knife/client_list.rb +8 -5
- data/lib/chef/knife/client_reregister.rb +9 -6
- data/lib/chef/knife/client_show.rb +9 -6
- data/lib/chef/knife/configure.rb +15 -19
- data/lib/chef/knife/configure_client.rb +4 -4
- data/lib/chef/knife/cookbook_bulk_delete.rb +11 -8
- data/lib/chef/knife/cookbook_create.rb +120 -55
- data/lib/chef/knife/cookbook_delete.rb +18 -12
- data/lib/chef/knife/cookbook_download.rb +10 -6
- data/lib/chef/knife/cookbook_list.rb +15 -6
- data/lib/chef/knife/cookbook_metadata.rb +41 -21
- data/lib/chef/knife/cookbook_metadata_from_file.rb +4 -0
- data/lib/chef/knife/cookbook_show.rb +16 -5
- data/lib/chef/knife/cookbook_site_download.rb +2 -2
- data/lib/chef/knife/cookbook_site_share.rb +18 -13
- data/lib/chef/knife/cookbook_site_unshare.rb +7 -4
- data/lib/chef/knife/cookbook_site_vendor.rb +21 -18
- data/lib/chef/knife/cookbook_test.rb +14 -14
- data/lib/chef/knife/cookbook_upload.rb +91 -40
- data/lib/chef/knife/data_bag_create.rb +41 -6
- data/lib/chef/knife/data_bag_delete.rb +5 -3
- data/lib/chef/knife/data_bag_edit.rb +55 -11
- data/lib/chef/knife/data_bag_from_file.rb +47 -7
- data/lib/chef/knife/data_bag_list.rb +4 -1
- data/lib/chef/knife/data_bag_show.rb +44 -4
- data/lib/chef/knife/environment_create.rb +53 -0
- data/lib/chef/knife/environment_delete.rb +45 -0
- data/lib/chef/knife/environment_edit.rb +45 -0
- data/lib/chef/knife/environment_from_file.rb +39 -0
- data/lib/chef/knife/environment_list.rb +42 -0
- data/lib/chef/knife/environment_show.rb +46 -0
- data/lib/chef/knife/exec.rb +1 -1
- data/lib/chef/knife/index_rebuild.rb +8 -9
- data/lib/chef/knife/node_bulk_delete.rb +9 -6
- data/lib/chef/knife/node_create.rb +9 -6
- data/lib/chef/knife/node_delete.rb +10 -7
- data/lib/chef/knife/node_edit.rb +129 -10
- data/lib/chef/knife/node_from_file.rb +10 -7
- data/lib/chef/knife/node_list.rb +11 -6
- data/lib/chef/knife/node_run_list_add.rb +10 -7
- data/lib/chef/knife/node_run_list_remove.rb +9 -6
- data/lib/chef/knife/node_show.rb +15 -7
- data/lib/chef/knife/recipe_list.rb +4 -3
- data/lib/chef/knife/role_bulk_delete.rb +9 -6
- data/lib/chef/knife/role_create.rb +9 -6
- data/lib/chef/knife/role_delete.rb +10 -7
- data/lib/chef/knife/role_edit.rb +11 -8
- data/lib/chef/knife/role_from_file.rb +10 -7
- data/lib/chef/knife/role_list.rb +8 -5
- data/lib/chef/knife/role_show.rb +11 -8
- data/lib/chef/knife/search.rb +33 -10
- data/lib/chef/knife/ssh.rb +33 -61
- data/lib/chef/knife/status.rb +7 -4
- data/lib/chef/knife/subcommand_loader.rb +101 -0
- data/lib/chef/knife/tag_create.rb +31 -0
- data/lib/chef/knife/tag_delete.rb +31 -0
- data/lib/chef/knife/tag_list.rb +29 -0
- data/lib/chef/knife/ui.rb +229 -0
- data/lib/chef/knife/windows_bootstrap.rb +8 -5
- data/lib/chef/log.rb +5 -59
- data/lib/chef/mash.rb +211 -0
- data/lib/chef/mixins.rb +1 -2
- data/lib/chef/nil_argument.rb +3 -0
- data/lib/chef/node.rb +96 -34
- data/lib/chef/platform.rb +27 -0
- data/lib/chef/provider/cookbook_file.rb +21 -20
- data/lib/chef/provider/deploy/revision.rb +3 -0
- data/lib/chef/provider/file.rb +20 -11
- data/lib/chef/provider/git.rb +26 -26
- data/lib/chef/provider/group/aix.rb +70 -0
- data/lib/chef/provider/group/groupadd.rb +7 -4
- data/lib/chef/provider/group/usermod.rb +1 -1
- data/lib/chef/provider/package.rb +28 -28
- data/lib/chef/provider/package/dpkg.rb +1 -1
- data/lib/chef/provider/package/portage.rb +50 -39
- data/lib/chef/provider/package/rubygems.rb +1 -1
- data/lib/chef/provider/package/zypper.rb +3 -20
- data/lib/chef/provider/remote_directory.rb +0 -2
- data/lib/chef/provider/remote_file.rb +2 -3
- data/lib/chef/provider/service/arch.rb +28 -35
- data/lib/chef/provider/service/simple.rb +1 -1
- data/lib/chef/provider/subversion.rb +22 -22
- data/lib/chef/providers.rb +1 -0
- data/lib/chef/recipe.rb +10 -12
- data/lib/chef/resource.rb +49 -42
- data/lib/chef/resource/gem_package.rb +7 -3
- data/lib/chef/resource/git.rb +5 -5
- data/lib/chef/resource/package.rb +7 -7
- data/lib/chef/resource/scm.rb +2 -1
- data/lib/chef/resource/solaris_package.rb +0 -1
- data/lib/chef/resource/yum_package.rb +0 -1
- data/lib/chef/rest.rb +7 -16
- data/lib/chef/rest/rest_request.rb +0 -16
- data/lib/chef/role.rb +67 -13
- data/lib/chef/run_context.rb +37 -21
- data/lib/chef/run_list.rb +30 -15
- data/lib/chef/run_list/run_list_expansion.rb +41 -20
- data/lib/chef/run_list/run_list_item.rb +20 -6
- data/lib/chef/run_list/versioned_recipe_list.rb +68 -0
- data/lib/chef/runner.rb +7 -15
- data/lib/chef/search/query.rb +12 -7
- data/lib/chef/shef.rb +6 -7
- data/lib/chef/shef/shef_session.rb +40 -35
- data/lib/chef/shell_out.rb +22 -201
- data/lib/chef/shell_out/unix.rb +224 -0
- data/lib/chef/shell_out/windows.rb +95 -0
- data/lib/chef/solr_query.rb +187 -0
- data/lib/chef/solr_query/lucene.treetop +145 -0
- data/lib/chef/solr_query/lucene_nodes.rb +285 -0
- data/lib/chef/solr_query/query_transform.rb +65 -0
- data/lib/chef/solr_query/solr_http_request.rb +118 -0
- data/lib/chef/version.rb +4 -2
- data/lib/chef/version_class.rb +70 -0
- data/lib/chef/version_constraint.rb +116 -0
- metadata +68 -37
- data/lib/chef/cookbook/metadata/version.rb +0 -87
- data/lib/chef/knife/bluebox_images_list.rb +0 -54
- data/lib/chef/knife/bluebox_server_create.rb +0 -157
- data/lib/chef/knife/bluebox_server_delete.rb +0 -63
- data/lib/chef/knife/bluebox_server_list.rb +0 -59
- data/lib/chef/knife/ec2_instance_data.rb +0 -46
- data/lib/chef/knife/ec2_server_create.rb +0 -218
- data/lib/chef/knife/ec2_server_delete.rb +0 -87
- data/lib/chef/knife/ec2_server_list.rb +0 -89
- data/lib/chef/knife/rackspace_server_create.rb +0 -184
- data/lib/chef/knife/rackspace_server_delete.rb +0 -57
- data/lib/chef/knife/rackspace_server_list.rb +0 -59
- data/lib/chef/knife/slicehost_images_list.rb +0 -53
- data/lib/chef/knife/slicehost_server_create.rb +0 -103
- data/lib/chef/knife/slicehost_server_delete.rb +0 -61
- data/lib/chef/knife/slicehost_server_list.rb +0 -64
- data/lib/chef/knife/terremark_server_create.rb +0 -152
- data/lib/chef/knife/terremark_server_delete.rb +0 -87
- data/lib/chef/knife/terremark_server_list.rb +0 -77
- data/lib/chef/mixin/find_preferred_file.rb +0 -92
@@ -6,9 +6,9 @@
|
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
8
8
|
# You may obtain a copy of the License at
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# Unless required by applicable law or agreed to in writing, software
|
13
13
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
14
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@@ -21,7 +21,11 @@ require 'chef/knife'
|
|
21
21
|
class Chef
|
22
22
|
class Knife
|
23
23
|
class CookbookDelete < Knife
|
24
|
-
|
24
|
+
|
25
|
+
deps do
|
26
|
+
require 'chef/cookbook_version'
|
27
|
+
end
|
28
|
+
|
25
29
|
option :all, :short => '-a', :long => '--all', :boolean => true, :description => 'delete all versions'
|
26
30
|
|
27
31
|
option :purge, :short => '-p', :long => '--purge', :boolean => true, :description => 'Permanently remove files from backing data store'
|
@@ -39,7 +43,7 @@ class Chef
|
|
39
43
|
delete_without_explicit_version
|
40
44
|
elsif @cookbook_name.nil?
|
41
45
|
show_usage
|
42
|
-
|
46
|
+
ui.fatal("You must provide the name of the cookbook to delete")
|
43
47
|
exit(1)
|
44
48
|
end
|
45
49
|
end
|
@@ -79,10 +83,12 @@ class Chef
|
|
79
83
|
end
|
80
84
|
|
81
85
|
def available_versions
|
82
|
-
@available_versions ||= rest.get_rest("cookbooks/#{@cookbook_name}").
|
86
|
+
@available_versions ||= rest.get_rest("cookbooks/#{@cookbook_name}").map do |name, url_and_version|
|
87
|
+
url_and_version["versions"].map {|url_by_version| url_by_version["version"]}
|
88
|
+
end.flatten
|
83
89
|
rescue Net::HTTPServerException => e
|
84
90
|
if e.to_s =~ /^404/
|
85
|
-
|
91
|
+
ui.error("Cannot find a cookbook named #{@cookbook_name} to delete")
|
86
92
|
nil
|
87
93
|
else
|
88
94
|
raise
|
@@ -99,16 +105,16 @@ class Chef
|
|
99
105
|
valid_responses[(available_versions.size + 1).to_s] = :all
|
100
106
|
question << "#{available_versions.size + 1}. All versions\n\n"
|
101
107
|
responses = ask_question(question).split(',').map { |response| response.strip }
|
102
|
-
|
108
|
+
|
103
109
|
if responses.empty?
|
104
|
-
|
110
|
+
ui.error("No versions specified, exiting")
|
105
111
|
exit(1)
|
106
112
|
end
|
107
113
|
versions = responses.map do |response|
|
108
114
|
if version = valid_responses[response]
|
109
115
|
version
|
110
116
|
else
|
111
|
-
|
117
|
+
ui.error("#{response} is not a valid choice, skipping it")
|
112
118
|
end
|
113
119
|
end
|
114
120
|
versions.compact
|
@@ -117,7 +123,7 @@ class Chef
|
|
117
123
|
def delete_version_without_confirmation(version)
|
118
124
|
object = delete_request("cookbooks/#{@cookbook_name}/#{version}")
|
119
125
|
output(format_for_display(object)) if config[:print_after]
|
120
|
-
|
126
|
+
ui.info("Deleted cookbook[#{@cookbook_name}][#{version}]")
|
121
127
|
end
|
122
128
|
|
123
129
|
def delete_versions_without_confirmation(versions)
|
@@ -130,9 +136,9 @@ class Chef
|
|
130
136
|
end
|
131
137
|
end
|
132
138
|
end
|
133
|
-
|
139
|
+
|
134
140
|
private
|
135
|
-
|
141
|
+
|
136
142
|
def delete_request(path)
|
137
143
|
path += "?purge=true" if config[:purge]
|
138
144
|
rest.delete_rest(path)
|
@@ -23,6 +23,10 @@ class Chef
|
|
23
23
|
class Knife
|
24
24
|
class CookbookDownload < Knife
|
25
25
|
|
26
|
+
deps do
|
27
|
+
require 'chef/cookbook_version'
|
28
|
+
end
|
29
|
+
|
26
30
|
banner "knife cookbook download COOKBOOK [VERSION] (options)"
|
27
31
|
|
28
32
|
option :latest,
|
@@ -50,13 +54,13 @@ class Chef
|
|
50
54
|
|
51
55
|
if @cookbook_name.nil?
|
52
56
|
show_usage
|
53
|
-
|
57
|
+
ui.fatal("You must specify a cookbook name")
|
54
58
|
exit 1
|
55
59
|
elsif @version.nil?
|
56
60
|
determine_version
|
57
61
|
end
|
58
62
|
|
59
|
-
|
63
|
+
ui.info("Downloading #{@cookbook_name} cookbook version #{@version}")
|
60
64
|
|
61
65
|
cookbook = rest.get_rest("cookbooks/#{@cookbook_name}/#{@version}")
|
62
66
|
manifest = cookbook.manifest
|
@@ -67,14 +71,14 @@ class Chef
|
|
67
71
|
Chef::Log.debug("Deleting #{basedir}")
|
68
72
|
FileUtils.rm_rf(basedir)
|
69
73
|
else
|
70
|
-
|
74
|
+
ui.fatal("Directory #{basedir} exists, use --force to overwrite")
|
71
75
|
exit
|
72
76
|
end
|
73
77
|
end
|
74
78
|
|
75
79
|
Chef::CookbookVersion::COOKBOOK_SEGMENTS.each do |segment|
|
76
80
|
next unless manifest.has_key?(segment)
|
77
|
-
|
81
|
+
ui.info("Downloading #{segment}")
|
78
82
|
manifest[segment].each do |segment_file|
|
79
83
|
dest = File.join(basedir, segment_file['path'].gsub('/', File::SEPARATOR))
|
80
84
|
Chef::Log.debug("Downloading #{segment_file['path']} to #{dest}")
|
@@ -84,7 +88,7 @@ class Chef
|
|
84
88
|
FileUtils.mv(tempfile.path, dest)
|
85
89
|
end
|
86
90
|
end
|
87
|
-
|
91
|
+
ui.info("Cookbook downloaded to #{basedir}")
|
88
92
|
end
|
89
93
|
|
90
94
|
def determine_version
|
@@ -120,7 +124,7 @@ class Chef
|
|
120
124
|
response = ask_question(question).strip
|
121
125
|
|
122
126
|
unless @version = valid_responses[response]
|
123
|
-
|
127
|
+
ui.error("'#{response}' is not a valid value.")
|
124
128
|
exit(1)
|
125
129
|
end
|
126
130
|
end
|
@@ -1,14 +1,15 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
-
#
|
3
|
+
# Author:: Nuo Yan (<nuo@opscode.com>)
|
4
|
+
# Copyright:: Copyright (c) 2009, 2010, 2011 Opscode, Inc.
|
4
5
|
# License:: Apache License, Version 2.0
|
5
6
|
#
|
6
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
8
|
# you may not use this file except in compliance with the License.
|
8
9
|
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
+
#
|
10
11
|
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
+
#
|
12
13
|
# Unless required by applicable law or agreed to in writing, software
|
13
14
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
15
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@@ -17,7 +18,6 @@
|
|
17
18
|
#
|
18
19
|
|
19
20
|
require 'chef/knife'
|
20
|
-
require 'chef/json_compat'
|
21
21
|
|
22
22
|
class Chef
|
23
23
|
class Knife
|
@@ -30,8 +30,17 @@ class Chef
|
|
30
30
|
:long => "--with-uri",
|
31
31
|
:description => "Show corresponding URIs"
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
option :all_versions,
|
34
|
+
:short => "-a",
|
35
|
+
:long => "--show-all-versions",
|
36
|
+
:description => "Show all available versions."
|
37
|
+
|
38
|
+
def run
|
39
|
+
env = config[:environment]
|
40
|
+
num_versions = config[:all_versions] ? "num_versions=all" : "num_versions=1"
|
41
|
+
api_endpoint = env ? "/environments/#{env}/cookbooks?#{num_versions}" : "/cookbooks?#{num_versions}"
|
42
|
+
ui.info("Showing latest versions. Use --show-all to list all available versions.") unless config[:all_versions]
|
43
|
+
output(format_cookbook_list_for_display(rest.get_rest(api_endpoint)))
|
35
44
|
end
|
36
45
|
end
|
37
46
|
end
|
@@ -23,6 +23,10 @@ class Chef
|
|
23
23
|
class Knife
|
24
24
|
class CookbookMetadata < Knife
|
25
25
|
|
26
|
+
deps do
|
27
|
+
require 'chef/cookbook/metadata'
|
28
|
+
end
|
29
|
+
|
26
30
|
banner "knife cookbook metadata COOKBOOK (options)"
|
27
31
|
|
28
32
|
option :cookbook_path,
|
@@ -37,14 +41,10 @@ class Chef
|
|
37
41
|
:description => "Generate metadata for all cookbooks, rather than just a single cookbook"
|
38
42
|
|
39
43
|
def run
|
40
|
-
|
41
|
-
Chef::Config[:cookbook_path] = config[:cookbook_path]
|
42
|
-
else
|
43
|
-
config[:cookbook_path] = Chef::Config[:cookbook_path]
|
44
|
-
end
|
44
|
+
config[:cookbook_path] ||= Chef::Config[:cookbook_path]
|
45
45
|
|
46
46
|
if config[:all]
|
47
|
-
cl = Chef::CookbookLoader.new
|
47
|
+
cl = Chef::CookbookLoader.new(config[:cookbook_path])
|
48
48
|
cl.each do |cname, cookbook|
|
49
49
|
generate_metadata(cname.to_s)
|
50
50
|
end
|
@@ -54,29 +54,49 @@ class Chef
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def generate_metadata(cookbook)
|
57
|
-
|
57
|
+
ui.info("Generating Metadata")
|
58
58
|
Array(config[:cookbook_path]).reverse.each do |path|
|
59
59
|
file = File.expand_path(File.join(path, cookbook, 'metadata.rb'))
|
60
|
-
|
60
|
+
if File.exists?(file)
|
61
|
+
generate_metadata_from_file(cookbook, file)
|
62
|
+
else
|
63
|
+
validate_metadata_json(path, cookbook)
|
64
|
+
end
|
61
65
|
end
|
62
66
|
end
|
63
67
|
|
64
68
|
def generate_metadata_from_file(cookbook, file)
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
f.write(Chef::JSONCompat.to_json_pretty(md))
|
73
|
-
end
|
74
|
-
generated = true
|
75
|
-
Chef::Log.debug("Generated #{json_file}")
|
76
|
-
else
|
77
|
-
Chef::Log.debug("No #{file} found; skipping!")
|
69
|
+
Chef::Log.debug("Generating metadata for #{cookbook} from #{file}")
|
70
|
+
md = Chef::Cookbook::Metadata.new
|
71
|
+
md.name(cookbook)
|
72
|
+
md.from_file(file)
|
73
|
+
json_file = File.join(File.dirname(file), 'metadata.json')
|
74
|
+
File.open(json_file, "w") do |f|
|
75
|
+
f.write(Chef::JSONCompat.to_json_pretty(md))
|
78
76
|
end
|
77
|
+
generated = true
|
78
|
+
Chef::Log.debug("Generated #{json_file}")
|
79
|
+
rescue Exceptions::ObsoleteDependencySyntax, Exceptions::InvalidVersionConstraint => e
|
80
|
+
STDERR.puts "ERROR: The cookbook '#{cookbook}' contains invalid or obsolete metadata syntax."
|
81
|
+
STDERR.puts "in #{file}:"
|
82
|
+
STDERR.puts
|
83
|
+
STDERR.puts e.message
|
84
|
+
exit 1
|
79
85
|
end
|
86
|
+
|
87
|
+
def validate_metadata_json(path, cookbook)
|
88
|
+
json_file = File.join(path, cookbook, 'metadata.json')
|
89
|
+
if File.exist?(json_file)
|
90
|
+
Chef::Cookbook::Metadata.validate_json(IO.read(json_file))
|
91
|
+
end
|
92
|
+
rescue Exceptions::ObsoleteDependencySyntax, Exceptions::InvalidVersionConstraint => e
|
93
|
+
STDERR.puts "ERROR: The cookbook '#{cookbook}' contains invalid or obsolete metadata syntax."
|
94
|
+
STDERR.puts "in #{json_file}:"
|
95
|
+
STDERR.puts
|
96
|
+
STDERR.puts e.message
|
97
|
+
exit 1
|
98
|
+
end
|
99
|
+
|
80
100
|
end
|
81
101
|
end
|
82
102
|
end
|
@@ -17,13 +17,16 @@
|
|
17
17
|
#
|
18
18
|
|
19
19
|
require 'chef/knife'
|
20
|
-
require 'chef/json_compat'
|
21
|
-
require 'uri'
|
22
20
|
|
23
21
|
class Chef
|
24
22
|
class Knife
|
25
23
|
class CookbookShow < Knife
|
26
24
|
|
25
|
+
deps do
|
26
|
+
require 'chef/json_compat'
|
27
|
+
require 'uri'
|
28
|
+
end
|
29
|
+
|
27
30
|
banner "knife cookbook show COOKBOOK [VERSION] [PART] [FILENAME] (options)"
|
28
31
|
|
29
32
|
option :fqdn,
|
@@ -41,6 +44,11 @@ class Chef
|
|
41
44
|
:long => "--platform-version VERSION",
|
42
45
|
:description => "The platform version to see the file for"
|
43
46
|
|
47
|
+
option :with_uri,
|
48
|
+
:short => "-w",
|
49
|
+
:long => "--with-uri",
|
50
|
+
:description => "Show corresponding URIs"
|
51
|
+
|
44
52
|
def run
|
45
53
|
case @name_args.length
|
46
54
|
when 4 # We are showing a specific file
|
@@ -73,11 +81,14 @@ class Chef
|
|
73
81
|
when 2 # We are showing the whole cookbook data
|
74
82
|
cookbook_version = @name_args[1] == 'latest' ? '_latest' : @name_args[1]
|
75
83
|
output(rest.get_rest("cookbooks/#{@name_args[0]}/#{cookbook_version}"))
|
76
|
-
when 1 # We are showing the cookbook versions
|
77
|
-
|
84
|
+
when 1 # We are showing the cookbook versions (all of them)
|
85
|
+
cookbook_name = @name_args[0]
|
86
|
+
env = config[:environment]
|
87
|
+
api_endpoint = env ? "environments/#{env}/cookbooks/#{cookbook_name}" : "cookbooks/#{cookbook_name}"
|
88
|
+
output(format_cookbook_list_for_display(rest.get_rest(api_endpoint)))
|
78
89
|
when 0
|
79
90
|
show_usage
|
80
|
-
|
91
|
+
ui.fatal("You must specify a cookbook name")
|
81
92
|
exit 1
|
82
93
|
end
|
83
94
|
end
|
@@ -41,14 +41,14 @@ class Chef
|
|
41
41
|
|
42
42
|
@version = cookbook_data['version']
|
43
43
|
|
44
|
-
|
44
|
+
ui.info("Downloading #{@name_args[0]} from the cookbooks site at version #{cookbook_data['version']}")
|
45
45
|
rest.sign_on_redirect = false
|
46
46
|
tf = rest.get_rest(cookbook_data["file"], true)
|
47
47
|
unless config[:file]
|
48
48
|
config[:file] = File.join(Dir.pwd, "#{@name_args[0]}-#{cookbook_data['version']}.tar.gz")
|
49
49
|
end
|
50
50
|
FileUtils.cp(tf.path, config[:file])
|
51
|
-
|
51
|
+
ui.info("Cookbook saved: #{config[:file]}")
|
52
52
|
end
|
53
53
|
|
54
54
|
end
|
@@ -17,13 +17,16 @@
|
|
17
17
|
#
|
18
18
|
|
19
19
|
require 'chef/knife'
|
20
|
-
require 'chef/cookbook_uploader'
|
21
|
-
require 'chef/cookbook_site_streaming_uploader'
|
22
20
|
|
23
21
|
class Chef
|
24
22
|
class Knife
|
25
23
|
class CookbookSiteShare < Knife
|
26
24
|
|
25
|
+
deps do
|
26
|
+
require 'chef/cookbook_uploader'
|
27
|
+
require 'chef/cookbook_site_streaming_uploader'
|
28
|
+
end
|
29
|
+
|
27
30
|
banner "knife cookbook site share COOKBOOK CATEGORY (options)"
|
28
31
|
category "cookbook site"
|
29
32
|
|
@@ -36,40 +39,42 @@ class Chef
|
|
36
39
|
def run
|
37
40
|
if @name_args.length < 2
|
38
41
|
show_usage
|
39
|
-
|
42
|
+
ui.fatal("You must specify the cookbook name and the category you want to share this cookbook to.")
|
40
43
|
exit 1
|
41
44
|
end
|
42
45
|
|
46
|
+
config[:cookbook_path] ||= Chef::Config[:cookbook_path]
|
47
|
+
|
43
48
|
cookbook_name = @name_args[0]
|
44
49
|
category = @name_args[1]
|
45
|
-
cl = Chef::CookbookLoader.new
|
50
|
+
cl = Chef::CookbookLoader.new(config[:cookbook_path])
|
46
51
|
if cl.cookbook_exists?(cookbook_name)
|
47
52
|
cookbook = cl[cookbook_name]
|
48
53
|
Chef::CookbookUploader.validate_cookbook(cookbook)
|
49
54
|
tmp_cookbook_dir = Chef::CookbookSiteStreamingUploader.create_build_dir(cookbook)
|
50
55
|
begin
|
51
56
|
Chef::Log.debug("temp cookbook directory is #{tmp_cookbook_dir.inspect}")
|
52
|
-
|
57
|
+
ui.info("Making tarball #{cookbook_name}.tgz")
|
53
58
|
Chef::Mixin::Command.run_command(:command => "tar -czf #{cookbook_name}.tgz #{cookbook_name}", :cwd => tmp_cookbook_dir)
|
54
59
|
rescue => e
|
55
|
-
|
60
|
+
ui.error("Error making tarball #{cookbook_name}.tgz: #{e.message}. Set log level to debug (-l debug) for more information.")
|
56
61
|
Chef::Log.debug("\n#{e.backtrace.join("\n")}")
|
57
62
|
exit(1)
|
58
63
|
end
|
59
64
|
|
60
65
|
begin
|
61
66
|
do_upload("#{tmp_cookbook_dir}/#{cookbook_name}.tgz", category, Chef::Config[:node_name], Chef::Config[:client_key])
|
62
|
-
|
67
|
+
ui.info("Upload complete!")
|
63
68
|
Chef::Log.debug("Removing local staging directory at #{tmp_cookbook_dir}")
|
64
69
|
FileUtils.rm_rf tmp_cookbook_dir
|
65
70
|
rescue => e
|
66
|
-
|
71
|
+
ui.error("Error uploading cookbook #{cookbook_name} to the Opscode Cookbook Site: #{e.message}. Set log level to debug (-l debug) for more information.")
|
67
72
|
Chef::Log.debug("\n#{e.backtrace.join("\n")}")
|
68
73
|
exit(1)
|
69
74
|
end
|
70
75
|
|
71
76
|
else
|
72
|
-
|
77
|
+
ui.error("Could not find cookbook #{cookbook_name} in your cookbook path.")
|
73
78
|
exit(1)
|
74
79
|
end
|
75
80
|
|
@@ -89,15 +94,15 @@ class Chef
|
|
89
94
|
if http_resp.code.to_i != 201
|
90
95
|
if res['error_messages']
|
91
96
|
if res['error_messages'][0] =~ /Version already exists/
|
92
|
-
|
97
|
+
ui.error "The same version of this cookbook already exists on the Opscode Cookbook Site."
|
93
98
|
exit(1)
|
94
99
|
else
|
95
|
-
|
100
|
+
ui.error "#{res['error_messages'][0]}"
|
96
101
|
exit(1)
|
97
102
|
end
|
98
103
|
else
|
99
|
-
|
100
|
-
|
104
|
+
ui.error "Unknown error while sharing cookbook"
|
105
|
+
ui.error "Server response: #{http_resp.body}"
|
101
106
|
exit(1)
|
102
107
|
end
|
103
108
|
end
|