knife-essentials 0.7.6 → 0.8
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/Rakefile +2 -2
- data/lib/chef/knife/{delete.rb → delete_essentials.rb} +10 -2
- data/lib/chef/knife/dependencies_essentials.rb +117 -0
- data/lib/chef/knife/{diff.rb → diff_essentials.rb} +3 -1
- data/lib/chef/knife/{download.rb → download_essentials.rb} +9 -4
- data/lib/chef/knife/{list.rb → list_essentials.rb} +8 -2
- data/lib/chef/knife/{raw.rb → raw_essentials.rb} +2 -0
- data/lib/chef/knife/{show.rb → show_essentials.rb} +3 -1
- data/lib/chef/knife/{upload.rb → upload_essentials.rb} +9 -4
- data/lib/chef_fs/command_line.rb +18 -0
- data/lib/chef_fs/file_pattern.rb +18 -0
- data/lib/chef_fs/file_system.rb +18 -1
- data/lib/chef_fs/file_system/base_fs_dir.rb +18 -0
- data/lib/chef_fs/file_system/base_fs_object.rb +19 -1
- data/lib/chef_fs/file_system/chef_repository_file_system_entry.rb +49 -8
- data/lib/chef_fs/file_system/chef_repository_file_system_root_dir.rb +62 -3
- data/lib/chef_fs/file_system/chef_server_root_dir.rb +18 -0
- data/lib/chef_fs/file_system/cookbook_dir.rb +26 -0
- data/lib/chef_fs/file_system/cookbook_file.rb +18 -0
- data/lib/chef_fs/file_system/cookbook_subdir.rb +18 -0
- data/lib/chef_fs/file_system/cookbooks_dir.rb +18 -2
- data/lib/chef_fs/file_system/data_bag_dir.rb +18 -0
- data/lib/chef_fs/file_system/data_bag_item.rb +18 -0
- data/lib/chef_fs/file_system/data_bags_dir.rb +18 -0
- data/lib/chef_fs/file_system/file_system_entry.rb +18 -0
- data/lib/chef_fs/file_system/file_system_error.rb +18 -0
- data/lib/chef_fs/file_system/file_system_root_dir.rb +18 -0
- data/lib/chef_fs/file_system/multiplexed_dir.rb +46 -0
- data/lib/chef_fs/file_system/must_delete_recursively_error.rb +18 -0
- data/lib/chef_fs/file_system/nodes_dir.rb +18 -0
- data/lib/chef_fs/file_system/nonexistent_fs_object.rb +18 -0
- data/lib/chef_fs/file_system/not_found_error.rb +18 -0
- data/lib/chef_fs/file_system/rest_list_dir.rb +18 -0
- data/lib/chef_fs/file_system/rest_list_entry.rb +18 -0
- data/lib/chef_fs/knife.rb +128 -18
- data/lib/chef_fs/path_utils.rb +19 -1
- data/lib/chef_fs/version.rb +1 -1
- data/spec/chef_fs/diff_spec.rb +69 -44
- data/spec/chef_fs/file_pattern_spec.rb +497 -479
- data/spec/chef_fs/file_system/chef_server_root_dir_spec.rb +18 -0
- data/spec/chef_fs/file_system/cookbooks_dir_spec.rb +18 -0
- data/spec/chef_fs/file_system/data_bags_dir_spec.rb +18 -0
- data/spec/chef_fs/file_system_spec.rb +124 -106
- data/spec/support/file_system_support.rb +93 -75
- metadata +12 -11
- data/lib/chef/sandbox_uploader.rb +0 -208
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-essentials
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.8'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-17 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Universal knife verbs that work with your Chef repository
|
15
15
|
email: jkeiser@opscode.com
|
@@ -22,14 +22,14 @@ files:
|
|
22
22
|
- LICENSE
|
23
23
|
- README.rdoc
|
24
24
|
- Rakefile
|
25
|
-
- lib/chef/knife/
|
26
|
-
- lib/chef/knife/
|
27
|
-
- lib/chef/knife/
|
28
|
-
- lib/chef/knife/
|
29
|
-
- lib/chef/knife/
|
30
|
-
- lib/chef/knife/
|
31
|
-
- lib/chef/knife/
|
32
|
-
- lib/chef/
|
25
|
+
- lib/chef/knife/delete_essentials.rb
|
26
|
+
- lib/chef/knife/dependencies_essentials.rb
|
27
|
+
- lib/chef/knife/diff_essentials.rb
|
28
|
+
- lib/chef/knife/download_essentials.rb
|
29
|
+
- lib/chef/knife/list_essentials.rb
|
30
|
+
- lib/chef/knife/raw_essentials.rb
|
31
|
+
- lib/chef/knife/show_essentials.rb
|
32
|
+
- lib/chef/knife/upload_essentials.rb
|
33
33
|
- lib/chef_fs/command_line.rb
|
34
34
|
- lib/chef_fs/file_pattern.rb
|
35
35
|
- lib/chef_fs/file_system/base_fs_dir.rb
|
@@ -47,6 +47,7 @@ files:
|
|
47
47
|
- lib/chef_fs/file_system/file_system_entry.rb
|
48
48
|
- lib/chef_fs/file_system/file_system_error.rb
|
49
49
|
- lib/chef_fs/file_system/file_system_root_dir.rb
|
50
|
+
- lib/chef_fs/file_system/multiplexed_dir.rb
|
50
51
|
- lib/chef_fs/file_system/must_delete_recursively_error.rb
|
51
52
|
- lib/chef_fs/file_system/nodes_dir.rb
|
52
53
|
- lib/chef_fs/file_system/nonexistent_fs_object.rb
|
@@ -86,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
87
|
version: '0'
|
87
88
|
requirements: []
|
88
89
|
rubyforge_project:
|
89
|
-
rubygems_version: 1.8.
|
90
|
+
rubygems_version: 1.8.23
|
90
91
|
signing_key:
|
91
92
|
specification_version: 3
|
92
93
|
summary: Universal knife verbs that work with your Chef repository
|
@@ -1,208 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: John Keiser (<jkeiser@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
|
-
|
20
|
-
class Chef
|
21
|
-
#
|
22
|
-
# Represents a sandbox uploading session. You pass in a set of files with
|
23
|
-
#
|
24
|
-
# Much of this is shamelessly stolen from Chef::CookbookUploader, placed at
|
25
|
-
# the sandbox level to allow any set of files to be uploaded and to allow
|
26
|
-
# uploading to plug in to the host's threading model (if any).
|
27
|
-
#
|
28
|
-
# A single-threaded caller will want to:
|
29
|
-
#
|
30
|
-
# uploader = SandboxUploader.new(checksum_files, rest)
|
31
|
-
# while uploader.upload_next_file do
|
32
|
-
# end
|
33
|
-
# uploader.commit
|
34
|
-
#
|
35
|
-
# A multithreaded caller will want to keep doing this:
|
36
|
-
#
|
37
|
-
# if !uploader.upload_next_file
|
38
|
-
# uploader.commit
|
39
|
-
class SandboxUploader
|
40
|
-
# Create a new SandboxUploader.
|
41
|
-
#
|
42
|
-
# ==== Attributes
|
43
|
-
#
|
44
|
-
# * +checksums+ - a list of checksums of files you plan to upload
|
45
|
-
# * +rest+ - the rest client to use
|
46
|
-
#
|
47
|
-
# ==== Throws
|
48
|
-
#
|
49
|
-
# This method will throw an HTTP exception if the sandbox creation fails.
|
50
|
-
def initialize(checksum, rest)
|
51
|
-
# Grab the list of URLs we need to upload to
|
52
|
-
checksums_hash = checksums.inject({}) { |hash,checksum| hash[checksum] = nil; hash }
|
53
|
-
response = rest.post_rest("sandboxes", { :checksums => checksums_hash })
|
54
|
-
@sandbox_url = response['uri']
|
55
|
-
@to_upload = []
|
56
|
-
response['checksums'].each do |checksum, info|
|
57
|
-
if info['needs_upload'] == true
|
58
|
-
@to_upload << {
|
59
|
-
:checksum => checksum,
|
60
|
-
:url => info['url']
|
61
|
-
}
|
62
|
-
else
|
63
|
-
Chef::Log.debug("#{checksum_files[checksum]} has not changed")
|
64
|
-
end
|
65
|
-
end
|
66
|
-
@uploading = 0
|
67
|
-
end
|
68
|
-
|
69
|
-
# Picks a file off the list and uploads it.
|
70
|
-
#
|
71
|
-
# ==== Parameters
|
72
|
-
#
|
73
|
-
# * +&block+ - if there is a file to upload, +block.call(checksum)+ will be
|
74
|
-
# invoked, and this should return the file contents for the given
|
75
|
-
# checksum.
|
76
|
-
#
|
77
|
-
# ==== Throws
|
78
|
-
#
|
79
|
-
# An HTTP error is thrown if the upload fails.
|
80
|
-
#
|
81
|
-
# ==== Returns
|
82
|
-
#
|
83
|
-
# +{ :checksum => checksum, :url => url }+ if a file was uploaded. +nil+ if
|
84
|
-
# there was no file left to upload.
|
85
|
-
def upload_next_file(&block)
|
86
|
-
@uploading += 1
|
87
|
-
begin
|
88
|
-
file = @to_upload.pop
|
89
|
-
return nil if !file
|
90
|
-
|
91
|
-
begin
|
92
|
-
return upload_file(block.call(file[:checksum]), file[:checksum], file[:url])
|
93
|
-
rescue
|
94
|
-
# Stick the work on top so we work on other things first
|
95
|
-
@to_upload.unshift(file)
|
96
|
-
raise
|
97
|
-
end
|
98
|
-
ensure
|
99
|
-
@uploading -= 1
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
# Commits the sandbox to Chef.
|
104
|
-
#
|
105
|
-
# ==== Throws
|
106
|
-
#
|
107
|
-
# * An HTTP error if the commit fails.
|
108
|
-
# * "Attempt to commit "
|
109
|
-
#
|
110
|
-
# ==== Returns
|
111
|
-
#
|
112
|
-
# +true+ if a commit occurred. +false+ if commit
|
113
|
-
# has already been called.
|
114
|
-
def commit
|
115
|
-
return false if !@sandbox_url
|
116
|
-
raise "Attempt to commit before uploads are complete!" if !uploads_complete?
|
117
|
-
# nil out sandbox url to avoid race conditions where multiple
|
118
|
-
# callers try to commit
|
119
|
-
sandbox_url = @sandbox_url
|
120
|
-
@sandbox_url = nil
|
121
|
-
@to_upload = nil
|
122
|
-
|
123
|
-
Chef::Log.debug("Committing sandbox")
|
124
|
-
# Retry if S3 is claims a checksum doesn't exist (the eventual
|
125
|
-
# in eventual consistency)
|
126
|
-
retries = 0
|
127
|
-
begin
|
128
|
-
rest.put_rest(sandbox_url, {:is_completed => true})
|
129
|
-
rescue Net::HTTPServerException => e
|
130
|
-
if e.message =~ /^400/ && (retries += 1) <= 5
|
131
|
-
sleep 2
|
132
|
-
retry
|
133
|
-
else
|
134
|
-
raise
|
135
|
-
end
|
136
|
-
end
|
137
|
-
true
|
138
|
-
end
|
139
|
-
|
140
|
-
def cancel
|
141
|
-
# Yeah, so uh, delete doesn't work. But we'd like to imagine it will.
|
142
|
-
sandbox_url = @sandbox_url
|
143
|
-
@sandbox_url = nil
|
144
|
-
@to_upload = nil
|
145
|
-
rest.delete_rest(sandbox_url)
|
146
|
-
end
|
147
|
-
|
148
|
-
# Tells whether uploads are all complete.
|
149
|
-
def uploads_complete?
|
150
|
-
@to_upload.length == 0 && @uploading == 0
|
151
|
-
end
|
152
|
-
|
153
|
-
private
|
154
|
-
|
155
|
-
def upload_file(file_contents, checksum, url)
|
156
|
-
# Checksum is the hexadecimal representation of the md5,
|
157
|
-
# but we need the base64 encoding for the content-md5
|
158
|
-
# header
|
159
|
-
checksum64 = Base64.encode64([checksum].pack("H*")).strip
|
160
|
-
timestamp = Time.now.utc.iso8601
|
161
|
-
# TODO - 5/28/2010, cw: make signing and sending the request streaming
|
162
|
-
sign_obj = Mixlib::Authentication::SignedHeaderAuth.signing_object(
|
163
|
-
:http_method => :put,
|
164
|
-
:path => URI.parse(url).path,
|
165
|
-
:body => file_contents,
|
166
|
-
:timestamp => timestamp,
|
167
|
-
:user_id => rest.client_name
|
168
|
-
)
|
169
|
-
headers = { 'content-type' => 'application/x-binary', 'content-md5' => checksum64, :accept => 'application/json' }
|
170
|
-
headers.merge!(sign_obj.sign(OpenSSL::PKey::RSA.new(rest.signing_key)))
|
171
|
-
|
172
|
-
begin
|
173
|
-
RestClient::Resource.new(url, :headers=>headers, :timeout=>1800, :open_timeout=>1800).put(file_contents)
|
174
|
-
rescue RestClient::Exception => e
|
175
|
-
Chef::Knife.ui.error("Failed to upload #@cookbook : #{e.message}\n#{e.response.body}")
|
176
|
-
raise
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
# For CookbookDir
|
181
|
-
|
182
|
-
private
|
183
|
-
|
184
|
-
def upload(entries, force, freeze)
|
185
|
-
# knife cookbook upload: Validate environment
|
186
|
-
# knife cookbook upload: Warn about cookbook shadowing
|
187
|
-
# knife cookbook upload: Check for broken links
|
188
|
-
# knife cookbook upload: Check for dependencies
|
189
|
-
# CookbookUploader: Validate cookbook syntax, ruby files and templates
|
190
|
-
# SandboxUploader!
|
191
|
-
entries_by_checksum = entries.inject({}) do |hash,entry|
|
192
|
-
if entry.respond_to?(:checksum)
|
193
|
-
checksum = entry.checksum
|
194
|
-
else
|
195
|
-
checksum = ChefFS::Diff.calc_checksum(entry.read)
|
196
|
-
end
|
197
|
-
hash[checksum] = entry
|
198
|
-
end
|
199
|
-
|
200
|
-
uploader = SandboxUploader.new(entries_by_checksum.keys, rest)
|
201
|
-
while uploader.upload_next_file { |checksum| entries_by_checksum[checksum].read }
|
202
|
-
end
|
203
|
-
uploader.commit
|
204
|
-
# CookbookUploader: PUT the manifest to either the force_save_url or save_url for the cookbook
|
205
|
-
# knife cookbook upload: update version constraints for environment
|
206
|
-
end
|
207
|
-
end
|
208
|
-
end
|