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
@@ -18,12 +18,15 @@
|
|
18
18
|
#
|
19
19
|
|
20
20
|
require 'chef/knife'
|
21
|
-
require 'chef/json_compat'
|
22
21
|
|
23
22
|
class Chef
|
24
23
|
class Knife
|
25
24
|
class CookbookSiteUnshare < Knife
|
26
25
|
|
26
|
+
deps do
|
27
|
+
require 'chef/json_compat'
|
28
|
+
end
|
29
|
+
|
27
30
|
banner "knife cookbook site unshare COOKBOOK"
|
28
31
|
category "cookbook site"
|
29
32
|
|
@@ -31,7 +34,7 @@ class Chef
|
|
31
34
|
@cookbook_name = @name_args[0]
|
32
35
|
if @cookbook_name.nil?
|
33
36
|
show_usage
|
34
|
-
|
37
|
+
ui.fatal "You must provide the name of the cookbook to unshare"
|
35
38
|
exit 1
|
36
39
|
end
|
37
40
|
|
@@ -41,11 +44,11 @@ class Chef
|
|
41
44
|
rest.delete_rest "http://cookbooks.opscode.com/api/v1/cookbooks/#{@name_args[0]}"
|
42
45
|
rescue Net::HTTPServerException => e
|
43
46
|
raise e unless e.message =~ /Forbidden/
|
44
|
-
|
47
|
+
ui.error "Forbidden: You must be the maintainer of #{@cookbook_name} to unshare it."
|
45
48
|
exit 1
|
46
49
|
end
|
47
50
|
|
48
|
-
|
51
|
+
ui.info "Unshared cookbook #{@cookbook_name}"
|
49
52
|
end
|
50
53
|
|
51
54
|
end
|
@@ -17,12 +17,15 @@
|
|
17
17
|
#
|
18
18
|
|
19
19
|
require 'chef/knife'
|
20
|
-
require 'chef/cookbook/metadata'
|
21
20
|
|
22
21
|
class Chef
|
23
22
|
class Knife
|
24
23
|
class CookbookSiteVendor < Knife
|
25
24
|
|
25
|
+
deps do
|
26
|
+
require 'chef/cookbook/metadata'
|
27
|
+
end
|
28
|
+
|
26
29
|
banner "knife cookbook site vendor COOKBOOK [VERSION] (options)"
|
27
30
|
category "cookbook site"
|
28
31
|
|
@@ -53,7 +56,7 @@ class Chef
|
|
53
56
|
|
54
57
|
# Check to ensure we have a valid source of cookbooks before continuing
|
55
58
|
unless File.directory?(config[:cookbook_path].first)
|
56
|
-
|
59
|
+
ui.error( File.join(config[:cookbook_path].first, " doesn't exist!. Make sure you have cookbook_path configured correctly"))
|
57
60
|
exit 1
|
58
61
|
end
|
59
62
|
|
@@ -67,49 +70,49 @@ class Chef
|
|
67
70
|
download.name_args = name_args
|
68
71
|
download.run
|
69
72
|
|
70
|
-
|
73
|
+
ui.info("Checking out the #{config[:branch_default]} branch.")
|
71
74
|
Chef::Mixin::Command.run_command(:command => "git checkout #{config[:branch_default]}", :cwd => vendor_path)
|
72
|
-
|
75
|
+
ui.info("Checking the status of the vendor branch.")
|
73
76
|
status, branch_output, branch_error = Chef::Mixin::Command.output_of_command("git branch --no-color | grep #{branch_name}", :cwd => vendor_path)
|
74
77
|
if branch_output =~ /#{Regexp.escape(branch_name)}$/m
|
75
|
-
|
78
|
+
ui.info("Vendor branch found.")
|
76
79
|
Chef::Mixin::Command.run_command(:command => "git checkout #{branch_name}", :cwd => vendor_path)
|
77
80
|
else
|
78
|
-
|
81
|
+
ui.info("Creating vendor branch.")
|
79
82
|
Chef::Mixin::Command.run_command(:command => "git checkout -b #{branch_name}", :cwd => vendor_path)
|
80
83
|
end
|
81
|
-
|
84
|
+
ui.info("Removing pre-existing version.")
|
82
85
|
Chef::Mixin::Command.run_command(:command => "rm -r #{cookbook_path}", :cwd => vendor_path) if File.directory?(cookbook_path)
|
83
|
-
|
86
|
+
ui.info("Uncompressing #{name_args[0]} version #{download.version}.")
|
84
87
|
Chef::Mixin::Command.run_command(:command => "tar zxvf #{upstream_file}", :cwd => vendor_path)
|
85
88
|
Chef::Mixin::Command.run_command(:command => "rm #{upstream_file}", :cwd => vendor_path)
|
86
|
-
|
89
|
+
ui.info("Adding changes.")
|
87
90
|
Chef::Mixin::Command.run_command(:command => "git add #{name_args[0]}", :cwd => vendor_path)
|
88
91
|
|
89
|
-
|
92
|
+
ui.info("Committing changes.")
|
90
93
|
changes = true
|
91
94
|
begin
|
92
95
|
Chef::Mixin::Command.run_command(:command => "git commit -a -m 'Import #{name_args[0]} version #{download.version}'", :cwd => vendor_path)
|
93
96
|
rescue Chef::Exceptions::Exec => e
|
94
|
-
|
95
|
-
|
97
|
+
ui.warn("Checking out the #{config[:branch_default]} branch.")
|
98
|
+
ui.warn("No changes from current vendor #{name_args[0]}")
|
96
99
|
Chef::Mixin::Command.run_command(:command => "git checkout #{config[:branch_default]}", :cwd => vendor_path)
|
97
100
|
changes = false
|
98
101
|
end
|
99
102
|
|
100
103
|
if changes
|
101
|
-
|
104
|
+
ui.info("Creating tag chef-vendor-#{name_args[0]}-#{download.version}.")
|
102
105
|
Chef::Mixin::Command.run_command(:command => "git tag -f chef-vendor-#{name_args[0]}-#{download.version}", :cwd => vendor_path)
|
103
|
-
|
106
|
+
ui.info("Checking out the #{config[:branch_default]} branch.")
|
104
107
|
Chef::Mixin::Command.run_command(:command => "git checkout #{config[:branch_default]}", :cwd => vendor_path)
|
105
|
-
|
108
|
+
ui.info("Merging changes from #{name_args[0]} version #{download.version}.")
|
106
109
|
|
107
110
|
Dir.chdir(vendor_path) do
|
108
111
|
if system("git merge #{branch_name}")
|
109
|
-
|
112
|
+
ui.info("Cookbook #{name_args[0]} version #{download.version} successfully vendored!")
|
110
113
|
else
|
111
|
-
|
112
|
-
|
114
|
+
ui.error("You have merge conflicts - please resolve manually!")
|
115
|
+
ui.error("(Hint: cd #{vendor_path}; git status)")
|
113
116
|
exit 1
|
114
117
|
end
|
115
118
|
end
|
@@ -9,9 +9,9 @@
|
|
9
9
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
10
10
|
# you may not use this file except in compliance with the License.
|
11
11
|
# You may obtain a copy of the License at
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# http://www.apache.org/licenses/LICENSE-2.0
|
14
|
-
#
|
14
|
+
#
|
15
15
|
# Unless required by applicable law or agreed to in writing, software
|
16
16
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
17
17
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@@ -19,12 +19,16 @@
|
|
19
19
|
# limitations under the License.
|
20
20
|
#
|
21
21
|
require 'chef/knife'
|
22
|
-
require 'chef/checksum_cache'
|
23
22
|
|
24
23
|
class Chef
|
25
24
|
class Knife
|
26
25
|
class CookbookTest < Knife
|
27
26
|
|
27
|
+
deps do
|
28
|
+
require 'chef/checksum_cache'
|
29
|
+
require 'chef/cookbook/syntax_check'
|
30
|
+
end
|
31
|
+
|
28
32
|
banner "knife cookbook test [COOKBOOKS...] (options)"
|
29
33
|
|
30
34
|
option :cookbook_path,
|
@@ -38,15 +42,11 @@ class Chef
|
|
38
42
|
:long => "--all",
|
39
43
|
:description => "Test all cookbooks, rather than just a single cookbook"
|
40
44
|
|
41
|
-
def run
|
42
|
-
|
43
|
-
Chef::Config[:cookbook_path] = config[:cookbook_path]
|
44
|
-
else
|
45
|
-
config[:cookbook_path] = Chef::Config[:cookbook_path]
|
46
|
-
end
|
45
|
+
def run
|
46
|
+
config[:cookbook_path] ||= Chef::Config[:cookbook_path]
|
47
47
|
|
48
48
|
if config[:all]
|
49
|
-
cl = Chef::CookbookLoader.new
|
49
|
+
cl = Chef::CookbookLoader.new(config[:cookbook_path])
|
50
50
|
cl.each do |key, cookbook|
|
51
51
|
test_cookbook(key)
|
52
52
|
end
|
@@ -58,7 +58,7 @@ class Chef
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def test_cookbook(cookbook)
|
61
|
-
|
61
|
+
ui.info("Running syntax check on #{cookbook}")
|
62
62
|
Array(config[:cookbook_path]).reverse.each do |path|
|
63
63
|
syntax_checker = Chef::Cookbook::SyntaxCheck.for_cookbook(cookbook, path)
|
64
64
|
test_ruby(syntax_checker)
|
@@ -68,12 +68,12 @@ class Chef
|
|
68
68
|
|
69
69
|
|
70
70
|
def test_ruby(syntax_checker)
|
71
|
-
|
71
|
+
ui.info("Validating ruby files")
|
72
72
|
exit(1) unless syntax_checker.validate_ruby_files
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
def test_templates(syntax_checker)
|
76
|
-
|
76
|
+
ui.info("Validating templates")
|
77
77
|
exit(1) unless syntax_checker.validate_templates
|
78
78
|
end
|
79
79
|
|
@@ -18,13 +18,16 @@
|
|
18
18
|
#
|
19
19
|
|
20
20
|
require 'chef/knife'
|
21
|
-
require 'chef/cookbook_loader'
|
22
|
-
require 'chef/cookbook_uploader'
|
23
21
|
|
24
22
|
class Chef
|
25
23
|
class Knife
|
26
24
|
class CookbookUpload < Knife
|
27
|
-
|
25
|
+
|
26
|
+
deps do
|
27
|
+
require 'chef/exceptions'
|
28
|
+
require 'chef/cookbook_loader'
|
29
|
+
require 'chef/cookbook_uploader'
|
30
|
+
end
|
28
31
|
|
29
32
|
banner "knife cookbook upload [COOKBOOKS...] (options)"
|
30
33
|
|
@@ -34,61 +37,109 @@ class Chef
|
|
34
37
|
:description => "A colon-separated path to look for cookbooks in",
|
35
38
|
:proc => lambda { |o| o.split(":") }
|
36
39
|
|
40
|
+
option :freeze,
|
41
|
+
:long => '--freeze',
|
42
|
+
:description => 'Freeze this version of the cookbook so that it cannot be overwritten',
|
43
|
+
:boolean => true
|
44
|
+
|
37
45
|
option :all,
|
38
46
|
:short => "-a",
|
39
47
|
:long => "--all",
|
40
48
|
:description => "Upload all cookbooks, rather than just a single cookbook"
|
41
49
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
config[:cookbook_path] = Chef::Config[:cookbook_path]
|
47
|
-
end
|
50
|
+
option :force,
|
51
|
+
:long => '--force',
|
52
|
+
:boolean => true,
|
53
|
+
:description => "Update cookbook versions even if they have been frozen"
|
48
54
|
|
49
|
-
|
55
|
+
option :environment,
|
56
|
+
:short => '-E',
|
57
|
+
:long => '--environment ENVIRONMENT',
|
58
|
+
:description => "Set ENVIRONMENT's version dependency match the version you're uploading."
|
50
59
|
|
51
|
-
|
60
|
+
def run
|
61
|
+
config[:cookbook_path] ||= Chef::Config[:cookbook_path]
|
52
62
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
63
|
+
assert_environment_valid!
|
64
|
+
version_constraints_to_update = {}
|
65
|
+
|
66
|
+
if config[:all]
|
67
|
+
cookbook_repo.each do |cookbook_name, cookbook|
|
68
|
+
cookbook.freeze_version if config[:freeze]
|
69
|
+
upload(cookbook)
|
70
|
+
version_constraints_to_update[cookbook_name] = cookbook.version
|
71
|
+
end
|
72
|
+
else
|
73
|
+
if @name_args.empty?
|
74
|
+
show_usage
|
75
|
+
Chef::Log.fatal("You must specify the --all flag or at least one cookbook name")
|
76
|
+
exit 1
|
77
|
+
end
|
78
|
+
@name_args.each do |cookbook_name|
|
79
|
+
begin
|
80
|
+
cookbook = cookbook_repo[cookbook_name]
|
81
|
+
cookbook.freeze_version if config[:freeze]
|
82
|
+
upload(cookbook)
|
83
|
+
version_constraints_to_update[cookbook_name] = cookbook.version
|
84
|
+
rescue Exceptions::CookbookNotFoundInRepo => e
|
85
|
+
Log.error("Could not find cookbook #{cookbook_name} in your cookbook path, skipping it")
|
86
|
+
Log.debug(e)
|
71
87
|
end
|
72
88
|
end
|
73
89
|
end
|
90
|
+
|
91
|
+
update_version_constraints(version_constraints_to_update) if config[:environment]
|
92
|
+
end
|
93
|
+
|
94
|
+
def cookbook_repo
|
95
|
+
@cookbook_loader ||= begin
|
96
|
+
Chef::Cookbook::FileVendor.on_create { |manifest| Chef::Cookbook::FileSystemFileVendor.new(manifest, config[:cookbook_path]) }
|
97
|
+
Chef::CookbookLoader.new(config[:cookbook_path])
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def update_version_constraints(new_version_constraints)
|
102
|
+
new_version_constraints.each do |cookbook_name, version|
|
103
|
+
environment.cookbook_versions[cookbook_name] = "= #{version}"
|
104
|
+
end
|
105
|
+
environment.save
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
def environment
|
110
|
+
@environment ||= Environment.load(config[:environment])
|
74
111
|
end
|
75
112
|
|
76
113
|
private
|
77
114
|
|
78
|
-
def
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
raise
|
88
|
-
end
|
115
|
+
def assert_environment_valid!
|
116
|
+
environment
|
117
|
+
rescue Net::HTTPServerException => e
|
118
|
+
if e.response.code.to_s == "404"
|
119
|
+
Log.error "The environment #{config[:environment]} does not exist on the server"
|
120
|
+
Log.debug(e)
|
121
|
+
exit 1
|
122
|
+
else
|
123
|
+
raise
|
89
124
|
end
|
90
125
|
end
|
91
126
|
|
127
|
+
def upload(cookbook)
|
128
|
+
Chef::Log.info("** #{cookbook.name} **")
|
129
|
+
Chef::CookbookUploader.new(cookbook, config[:cookbook_path], :force => config[:force]).upload_cookbook
|
130
|
+
rescue Net::HTTPServerException => e
|
131
|
+
case e.response.code
|
132
|
+
when "401"
|
133
|
+
Log.error "Request failed due to authentication (#{e}), check your client configuration (username, key)"
|
134
|
+
Log.debug(e)
|
135
|
+
exit 18
|
136
|
+
when "409"
|
137
|
+
Log.error "Version #{cookbook.version} of cookbook #{cookbook.name} is frozen. Use --force to override."
|
138
|
+
Log.debug(e)
|
139
|
+
else
|
140
|
+
raise
|
141
|
+
end
|
142
|
+
end
|
92
143
|
|
93
144
|
end
|
94
145
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
-
#
|
3
|
+
# Author:: Seth Falcon (<seth@opscode.com>)
|
4
|
+
# Copyright:: Copyright (c) 2009-2010 Opscode, Inc.
|
4
5
|
# License:: Apache License, Version 2.0
|
5
6
|
#
|
6
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -17,37 +18,71 @@
|
|
17
18
|
#
|
18
19
|
|
19
20
|
require 'chef/knife'
|
20
|
-
require 'chef/data_bag'
|
21
21
|
|
22
22
|
class Chef
|
23
23
|
class Knife
|
24
24
|
class DataBagCreate < Knife
|
25
25
|
|
26
|
+
deps do
|
27
|
+
require 'chef/data_bag'
|
28
|
+
end
|
29
|
+
|
26
30
|
banner "knife data bag create BAG [ITEM] (options)"
|
27
31
|
category "data bag"
|
28
32
|
|
33
|
+
option :secret,
|
34
|
+
:short => "-s SECRET",
|
35
|
+
:long => "--secret ",
|
36
|
+
:description => "The secret key to use to encrypt data bag item values"
|
37
|
+
|
38
|
+
option :secret_file,
|
39
|
+
:long => "--secret_file SECRET_FILE",
|
40
|
+
:description => "A file containing the secret key to use to encrypt data bag item values"
|
41
|
+
|
42
|
+
def read_secret
|
43
|
+
if config[:secret]
|
44
|
+
config[:secret]
|
45
|
+
else
|
46
|
+
Chef::EncryptedDataBagItem.load_secret(config[:secret_file])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def use_encryption
|
51
|
+
if config[:secret] && config[:secret_file]
|
52
|
+
stdout.puts "please specify only one of --secret, --secret_file"
|
53
|
+
exit(1)
|
54
|
+
end
|
55
|
+
config[:secret] || config[:secret_file]
|
56
|
+
end
|
57
|
+
|
29
58
|
def run
|
30
59
|
@data_bag_name, @data_bag_item_name = @name_args
|
31
60
|
|
32
61
|
if @data_bag_name.nil?
|
33
62
|
show_usage
|
34
|
-
|
63
|
+
stdout.puts("You must specify a data bag name")
|
35
64
|
exit 1
|
36
65
|
end
|
37
66
|
|
38
67
|
# create the data bag
|
39
68
|
begin
|
40
69
|
rest.post_rest("data", { "name" => @data_bag_name })
|
41
|
-
|
70
|
+
ui.info("Created data_bag[#{@data_bag_name}]")
|
42
71
|
rescue Net::HTTPServerException => e
|
43
72
|
raise unless e.to_s =~ /^409/
|
44
|
-
|
73
|
+
ui.info("Data bag #{@data_bag_name} already exists")
|
45
74
|
end
|
46
75
|
|
47
76
|
# if an item is specified, create it, as well
|
48
77
|
if @data_bag_item_name
|
49
78
|
create_object({ "id" => @data_bag_item_name }, "data_bag_item[#{@data_bag_item_name}]") do |output|
|
50
|
-
|
79
|
+
item = if use_encryption
|
80
|
+
Chef::EncryptedDataBagItem.encrypt_data_bag_item(output,
|
81
|
+
read_secret)
|
82
|
+
else
|
83
|
+
output
|
84
|
+
end
|
85
|
+
rest.post_rest("data/#{@data_bag_name}", item)
|
51
86
|
end
|
52
87
|
end
|
53
88
|
end
|