Class: Chef::ChefFS::FileSystem::ChefServer::CookbookDir
- Inherits:
-
BaseFSDir
show all
- Defined in:
- lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb
Overview
Unversioned cookbook.
/cookbooks/NAME
Children look like:
- metadata.rb
- attributes/
- libraries/
- recipes/
Instance Attribute Summary collapse
Attributes inherited from BaseFSObject
#name, #parent, #path
Instance Method Summary
collapse
Methods inherited from BaseFSDir
#empty?
#child, #create_child, #path_for_printing, #read, #root, #write
Constructor Details
#initialize(name, parent, options = {}) ⇒ CookbookDir
Returns a new instance of CookbookDir.
43
44
45
46
47
48
|
# File 'lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb', line 43
def initialize(name, parent, options = {})
super(name, parent)
@exists = options[:exists]
@cookbook_name = name
@version = root.cookbook_version end
|
Instance Attribute Details
#cookbook_name ⇒ Object
Returns the value of attribute cookbook_name.
50
51
52
|
# File 'lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb', line 50
def cookbook_name
@cookbook_name
end
|
#version ⇒ Object
Returns the value of attribute version.
50
51
52
|
# File 'lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb', line 50
def version
@version
end
|
Instance Method Details
#add_child(child) ⇒ Object
52
53
54
|
# File 'lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb', line 52
def add_child(child)
@children << child
end
|
#api_path ⇒ Object
56
57
58
|
# File 'lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb', line 56
def api_path
"#{parent.api_path}/#{cookbook_name}/#{version || "_latest"}"
end
|
#can_have_child?(name, is_dir) ⇒ Boolean
70
71
72
73
74
|
# File 'lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb', line 70
def can_have_child?(name, is_dir)
return name != "root_files" if is_dir
true
end
|
#chef_object ⇒ Object
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
# File 'lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb', line 161
def chef_object
return @chef_object if @chef_object
if @could_not_get_chef_object
raise Chef::ChefFS::FileSystem::NotFoundError.new(self, @could_not_get_chef_object)
end
begin
old_retry_count = Chef::Config[:http_retry_count]
begin
Chef::Config[:http_retry_count] = 0
@chef_object ||= Chef::CookbookVersion.from_hash(chef_rest.get(api_path))
ensure
Chef::Config[:http_retry_count] = old_retry_count
end
rescue Timeout::Error => e
raise Chef::ChefFS::FileSystem::OperationFailedError.new(:read, self, e, "Timeout reading: #{e}")
rescue Net::HTTPClientException => e
if e.response.code == "404"
@could_not_get_chef_object = e
raise Chef::ChefFS::FileSystem::NotFoundError.new(self, @could_not_get_chef_object)
else
raise Chef::ChefFS::FileSystem::OperationFailedError.new(:read, self, e, "HTTP error reading: #{e}")
end
rescue Net::HTTPFatalError => e
if e.response.code == "500"
@could_not_get_chef_object = e
raise Chef::ChefFS::FileSystem::NotFoundError.new(self, @could_not_get_chef_object)
else
raise Chef::ChefFS::FileSystem::OperationFailedError.new(:read, self, e, "HTTP error reading: #{e}")
end
end
end
|
#chef_rest ⇒ Object
157
158
159
|
# File 'lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb', line 157
def chef_rest
Chef::ServerAPI.new(parent.chef_rest.url, parent.chef_rest.options.merge(version_class: Chef::CookbookManifestVersions))
end
|
#children ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb', line 76
def children
if @children.nil?
@children = []
manifest = chef_object.cookbook_manifest
manifest.by_parent_directory.each_value do |files|
files.each do |file|
parts = file[:path].split("/")
container = self
parts[0, parts.length - 1].each do |part|
old_container = container
container = old_container.children.find { |child| part == child.name }
unless container
container = CookbookSubdir.new(part, old_container, false, true)
old_container.add_child(container)
end
end
container.add_child(CookbookFile.new(parts[parts.length - 1], container, file))
end
end
@children = @children.sort_by(&:name)
end
@children
end
|
#compare_to(other) ⇒ Object
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb', line 135
def compare_to(other)
unless other.dir?
return [ !exists?, nil, nil ]
end
are_same = true
Chef::ChefFS::CommandLine.diff_entries(self, other, nil, :name_only).each do |type, old_entry, new_entry|
if %i{directory_to_file file_to_directory deleted added modified}.include?(type)
are_same = false
end
end
[ are_same, nil, nil ]
end
|
#copy_from(other, options = {}) ⇒ Object
149
150
151
|
# File 'lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb', line 149
def copy_from(other, options = {})
parent.upload_cookbook_from(other, options)
end
|
#delete(recurse) ⇒ Object
#dir? ⇒ Boolean
102
103
104
|
# File 'lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb', line 102
def dir?
exists?
end
|
#exists? ⇒ Boolean
In versioned cookbook mode, actually check if the version exists
Probably want to cache this.
128
129
130
131
132
133
|
# File 'lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb', line 128
def exists?
if @exists.nil?
@exists = parent.children.any? { |child| child.name == name }
end
@exists
end
|
#make_child_entry(name) ⇒ Object
60
61
62
63
64
65
66
67
68
|
# File 'lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb', line 60
def make_child_entry(name)
children.find { |child| child.name == name }
rescue Chef::ChefFS::FileSystem::NotFoundError
nil
end
|