Class: Chef::ChefFS::FileSystem::ChefServer::CookbooksDir
Overview
/cookbooks
Example children:
apache2/
mysql/
Instance Attribute Summary
Attributes inherited from RestListDir
#api_path, #data_handler
Attributes inherited from BaseFSObject
#name, #parent, #path
Instance Method Summary
collapse
#file_class
Methods inherited from RestListDir
#create_child, #environment, #initialize, #org, #rest
Methods inherited from BaseFSDir
#dir?, #empty?, #initialize
#chef_object, #child, #compare_to, #create_child, #delete, #dir?, #exists?, #initialize, #path_for_printing, #read, #root, #write
Instance Method Details
#can_have_child?(name, is_dir) ⇒ Boolean
111
112
113
|
# File 'lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb', line 111
def can_have_child?(name, is_dir)
is_dir
end
|
#children ⇒ Object
47
48
49
50
51
52
|
# File 'lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb', line 47
def children
@children ||= begin
result = root.get_json(api_path).keys.map { |cookbook_name| CookbookDir.new(cookbook_name, self, exists: true) }
result.sort_by(&:name)
end
end
|
#create_child_from(other, options = {}) ⇒ Object
54
55
56
57
|
# File 'lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb', line 54
def create_child_from(other, options = {})
@children = nil
upload_cookbook_from(other, options)
end
|
#make_child_entry(name) ⇒ Object
42
43
44
45
|
# File 'lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb', line 42
def make_child_entry(name)
result = @children.find { |child| child.name == name } if @children
result || CookbookDir.new(name, self)
end
|
#upload_cookbook(other, options) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb', line 74
def upload_cookbook(other, options)
cookbook = other.chef_object if other.chef_object
raise Chef::Exceptions::MetadataNotFound.new(cookbook.root_paths[0], cookbook.name) unless cookbook.has_metadata_file?
if cookbook
Chef::CookbookLoader.copy_to_tmp_dir_from_array([cookbook]) do |tmp_cl|
tmp_cl.load_cookbooks
tmp_cl.compile_metadata
tmp_cl.freeze_versions if options[:freeze]
cookbook_for_upload = []
tmp_cl.each do |cookbook_name, cookbook|
cookbook_for_upload << cookbook
end
uploader = Chef::CookbookUploader.new(cookbook_for_upload, force: options[:force], rest: chef_rest)
with_actual_cookbooks_dir(other.parent.file_path) do
uploader.upload_cookbooks
end
end
end
end
|
#upload_cookbook_from(other, options = {}) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb', line 59
def upload_cookbook_from(other, options = {})
upload_cookbook(other, options)
rescue Timeout::Error => e
raise Chef::ChefFS::FileSystem::OperationFailedError.new(:write, self, e, "Timeout writing: #{e}")
rescue Net::HTTPClientException => e
case e.response.code
when "409"
raise Chef::ChefFS::FileSystem::CookbookFrozenError.new(:write, self, e, "Cookbook #{other.name} is frozen")
else
raise Chef::ChefFS::FileSystem::OperationFailedError.new(:write, self, e, "HTTP error writing: #{e}")
end
rescue Chef::Exceptions::CookbookFrozen => e
raise Chef::ChefFS::FileSystem::CookbookFrozenError.new(:write, self, e, "Cookbook #{other.name} is frozen")
end
|
#with_actual_cookbooks_dir(actual_cookbook_path) ⇒ Object
Work around the fact that CookbookUploader doesn’t understand chef_repo_path (yet)
102
103
104
105
106
107
108
109
|
# File 'lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb', line 102
def with_actual_cookbooks_dir(actual_cookbook_path)
old_cookbook_path = Chef::Config.cookbook_path
Chef::Config.cookbook_path = actual_cookbook_path unless Chef::Config.cookbook_path
yield
ensure
Chef::Config.cookbook_path = old_cookbook_path
end
|