Class: Chef::ChefFS::FileSystem::ChefServer::CookbooksDir
- Inherits:
-
RestListDir
- Object
- BaseFSObject
- BaseFSDir
- RestListDir
- Chef::ChefFS::FileSystem::ChefServer::CookbooksDir
- Includes:
- Mixin::FileClass
- Defined in:
- lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb
Overview
/cookbooks
Example children:
apache2/
mysql/
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from RestListDir
Attributes inherited from BaseFSObject
Instance Method Summary collapse
- #can_have_child?(name, is_dir) ⇒ Boolean
- #children ⇒ Object
- #create_child_from(other, options = {}) ⇒ Object
- #make_child_entry(name) ⇒ Object
- #upload_cookbook(other, options) ⇒ Object
- #upload_cookbook_from(other, options = {}) ⇒ Object
-
#with_actual_cookbooks_dir(actual_cookbook_path) ⇒ Object
Work around the fact that CookbookUploader doesn’t understand chef_repo_path (yet).
Methods included from Mixin::FileClass
Methods inherited from RestListDir
#create_child, #environment, #initialize, #org, #rest
Methods inherited from BaseFSDir
Methods inherited from BaseFSObject
#chef_object, #child, #compare_to, #create_child, #delete, #dir?, #exists?, #initialize, #path_for_printing, #read, #root, #write
Constructor Details
This class inherits a constructor from Chef::ChefFS::FileSystem::ChefServer::RestListDir
Instance Method Details
#can_have_child?(name, is_dir) ⇒ Boolean
94 95 96 |
# File 'lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb', line 94 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, = {}) @children = nil upload_cookbook_from(other, ) 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 |
# File 'lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb', line 74 def upload_cookbook(other, ) cookbook_to_upload = other.chef_object cookbook_to_upload.freeze_version if [:freeze] uploader = Chef::CookbookUploader.new(cookbook_to_upload, :force => [:force], :rest => root.chef_rest) with_actual_cookbooks_dir(other.parent.file_path) do uploader.upload_cookbooks 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, = {}) upload_cookbook(other, ) rescue Timeout::Error => e raise Chef::ChefFS::FileSystem::OperationFailedError.new(:write, self, e, "Timeout writing: #{e}") rescue Net::HTTPServerException => 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)
85 86 87 88 89 90 91 92 |
# File 'lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb', line 85 def with_actual_cookbooks_dir(actual_cookbook_path) old_cookbook_path = Chef::Config.cookbook_path Chef::Config.cookbook_path = actual_cookbook_path if !Chef::Config.cookbook_path yield ensure Chef::Config.cookbook_path = old_cookbook_path end |