Class: Chef::Knife::CookbookSiteInstall
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::CookbookSiteInstall
- Defined in:
- lib/chef/knife/cookbook_site_install.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cookbook_name ⇒ Object
readonly
Returns the value of attribute cookbook_name.
-
#vendor_path ⇒ Object
readonly
Returns the value of attribute vendor_path.
Attributes inherited from Chef::Knife
Instance Method Summary collapse
- #clear_existing_files(cookbook_path) ⇒ Object
- #download_cookbook_to(download_path) ⇒ Object
- #extract_cookbook(upstream_file, version) ⇒ Object
- #parse_name_args! ⇒ Object
- #run ⇒ Object
Methods inherited from Chef::Knife
#api_key, category, common_name, #configure_chef, #create_object, #delete_object, deps, #format_rest_error, guess_category, #highlight_config_error, #humanize_exception, #humanize_http_exception, inherited, #initialize, list_commands, load_commands, load_deps, msg, #noauth_rest, #parse_options, #read_config_file, reset_subcommands!, #rest, run, #run_with_pretty_exceptions, #server_url, #show_usage, snake_case_name, subcommand_category, subcommand_class_from, subcommand_loader, subcommands, subcommands_by_category, ui, unnamed?, #username
Methods included from Mixin::ConvertToClassName
#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename
Constructor Details
This class inherits a constructor from Chef::Knife
Instance Attribute Details
#cookbook_name ⇒ Object (readonly)
Returns the value of attribute cookbook_name.
53 54 55 |
# File 'lib/chef/knife/cookbook_site_install.rb', line 53 def cookbook_name @cookbook_name end |
#vendor_path ⇒ Object (readonly)
Returns the value of attribute vendor_path.
54 55 56 |
# File 'lib/chef/knife/cookbook_site_install.rb', line 54 def vendor_path @vendor_path end |
Instance Method Details
#clear_existing_files(cookbook_path) ⇒ Object
134 135 136 137 |
# File 'lib/chef/knife/cookbook_site_install.rb', line 134 def clear_existing_files(cookbook_path) ui.info("Removing pre-existing version.") shell_out!("rm -r #{cookbook_path}", :cwd => @install_path) if File.directory?(cookbook_path) end |
#download_cookbook_to(download_path) ⇒ Object
121 122 123 124 125 126 127 |
# File 'lib/chef/knife/cookbook_site_install.rb', line 121 def download_cookbook_to(download_path) downloader = Chef::Knife::CookbookSiteDownload.new downloader.config[:file] = download_path downloader.name_args = name_args downloader.run downloader end |
#extract_cookbook(upstream_file, version) ⇒ Object
129 130 131 132 |
# File 'lib/chef/knife/cookbook_site_install.rb', line 129 def extract_cookbook(upstream_file, version) ui.info("Uncompressing #{@cookbook_name} version #{version}.") shell_out!("tar zxvf #{upstream_file}", :cwd => @install_path) end |
#parse_name_args! ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/chef/knife/cookbook_site_install.rb', line 109 def parse_name_args! if name_args.empty? ui.error("please specify a cookbook to download and install") exit 1 elsif name_args.size > 1 ui.error("Installing multiple cookbooks at once is not supported") exit 1 else name_args.first end end |
#run ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 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 101 102 103 104 105 106 107 |
# File 'lib/chef/knife/cookbook_site_install.rb', line 56 def run extend Chef::Mixin::ShellOut if config[:cookbook_path] Chef::Config[:cookbook_path] = config[:cookbook_path] else config[:cookbook_path] = Chef::Config[:cookbook_path] end @cookbook_name = parse_name_args! # Check to ensure we have a valid source of cookbooks before continuing # @install_path = config[:cookbook_path].first ui.info "Installing #@cookbook_name to #{@install_path}" @repo = CookbookSCMRepo.new(@install_path, ui, config) #cookbook_path = File.join(vendor_path, name_args[0]) upstream_file = File.join(@install_path, "#{@cookbook_name}.tar.gz") @repo.sanity_check @repo.reset_to_default_state @repo.prepare_to_import(@cookbook_name) downloader = download_cookbook_to(upstream_file) clear_existing_files(File.join(@install_path, @cookbook_name)) extract_cookbook(upstream_file, @install_path) # TODO: it'd be better to store these outside the cookbook repo and # keep them around, e.g., in ~/Library/Caches on OS X. ui.info("removing downloaded tarball") shell_out!("rm #{upstream_file}", :cwd => vendor_path) if @repo.finalize_updates_to(@cookbook_name, downloader.version) @repo.reset_to_default_state @repo.merge_updates_from(@cookbook_name, downloader.version) else @repo.reset_to_default_state end unless config[:no_deps] md = Chef::Cookbook::Metadata.new md.from_file(File.join(@install_path, @cookbook_name, "metadata.rb")) md.dependencies.each do |cookbook, version_list| # Doesn't do versions.. yet nv = self.class.new nv.config = config nv.name_args = [ cookbook ] nv.run end end end |