diff options
author | John Keiser <jkeiser@opscode.com> | 2013-06-19 00:24:41 -0600 |
---|---|---|
committer | John Keiser <jkeiser@opscode.com> | 2013-09-12 23:10:54 -0700 |
commit | 9a7449687cc25d42bfa1881584dc10675068e036 (patch) | |
tree | 35ec910e078f2430c2362fb100b50e8cef12997b | |
parent | 52ecc414cdb284182f08bbfbd3b8e46ba1c03958 (diff) | |
download | chef-9a7449687cc25d42bfa1881584dc10675068e036.tar.gz |
Add --cookbook-version to knife download and knife diff
-rw-r--r-- | lib/chef/chef_fs/config.rb | 9 | ||||
-rw-r--r-- | lib/chef/chef_fs/file_system/chef_server_root_dir.rb | 4 | ||||
-rw-r--r-- | lib/chef/chef_fs/file_system/cookbook_dir.rb | 1 | ||||
-rw-r--r-- | lib/chef/chef_fs/knife.rb | 2 | ||||
-rw-r--r-- | lib/chef/knife/diff.rb | 4 | ||||
-rw-r--r-- | lib/chef/knife/download.rb | 4 |
6 files changed, 20 insertions, 4 deletions
diff --git a/lib/chef/chef_fs/config.rb b/lib/chef/chef_fs/config.rb index 6a492dbcc5..bfbe379775 100644 --- a/lib/chef/chef_fs/config.rb +++ b/lib/chef/chef_fs/config.rb @@ -25,9 +25,10 @@ class Chef # Helpers to take Chef::Config and create chef_fs and local_fs from it # class Config - def initialize(chef_config = Chef::Config, cwd = Dir.pwd) + def initialize(chef_config = Chef::Config, cwd = Dir.pwd, options = {}) @chef_config = chef_config @cwd = cwd + @cookbook_version = options[:cookbook_version] # Default to getting *everything* from the server. if !@chef_config[:repo_mode] @@ -39,13 +40,17 @@ class Chef end end + attr_reader :chef_config + attr_reader :cwd + attr_reader :cookbook_version + def chef_fs @chef_fs ||= create_chef_fs end def create_chef_fs require 'chef/chef_fs/file_system/chef_server_root_dir' - Chef::ChefFS::FileSystem::ChefServerRootDir.new("remote", @chef_config) + Chef::ChefFS::FileSystem::ChefServerRootDir.new("remote", @chef_config, :cookbook_version => @cookbook_version) end def local_fs diff --git a/lib/chef/chef_fs/file_system/chef_server_root_dir.rb b/lib/chef/chef_fs/file_system/chef_server_root_dir.rb index 5eb72657c5..98f90e3a68 100644 --- a/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server_root_dir.rb @@ -34,7 +34,7 @@ class Chef module ChefFS module FileSystem class ChefServerRootDir < BaseFSDir - def initialize(root_name, chef_config) + def initialize(root_name, chef_config, options = {}) super("", nil) @chef_server_url = chef_config[:chef_server_url] @chef_username = chef_config[:node_name] @@ -42,6 +42,7 @@ class Chef @environment = chef_config[:environment] @repo_mode = chef_config[:repo_mode] @root_name = root_name + @cookbook_version = options[:cookbook_version] # Used in knife diff and download for server cookbook version end attr_reader :chef_server_url @@ -49,6 +50,7 @@ class Chef attr_reader :chef_private_key attr_reader :environment attr_reader :repo_mode + attr_reader :cookbook_version def fs_description "Chef server at #{chef_server_url} (user #{chef_username}), repo_mode = #{repo_mode}" diff --git a/lib/chef/chef_fs/file_system/cookbook_dir.rb b/lib/chef/chef_fs/file_system/cookbook_dir.rb index cae29a1690..5751328b02 100644 --- a/lib/chef/chef_fs/file_system/cookbook_dir.rb +++ b/lib/chef/chef_fs/file_system/cookbook_dir.rb @@ -41,6 +41,7 @@ class Chef end else @cookbook_name = name + @version = root.cookbook_version # nil unless --cookbook-version specified in download/diff end end diff --git a/lib/chef/chef_fs/knife.rb b/lib/chef/chef_fs/knife.rb index e69e07e744..3b345b9db6 100644 --- a/lib/chef/chef_fs/knife.rb +++ b/lib/chef/chef_fs/knife.rb @@ -68,7 +68,7 @@ class Chef end end - @chef_fs_config = Chef::ChefFS::Config.new(Chef::Config) + @chef_fs_config = Chef::ChefFS::Config.new(Chef::Config, Dir.pwd, config) Chef::ChefFS::Parallelizer.threads = (Chef::Config[:concurrency] || 10) - 1 diff --git a/lib/chef/knife/diff.rb b/lib/chef/knife/diff.rb index 5a3a80544d..df7681c91a 100644 --- a/lib/chef/knife/diff.rb +++ b/lib/chef/knife/diff.rb @@ -30,6 +30,10 @@ class Chef :description => "Select only files that are Added (A), Deleted (D), Modified (M), or have their type (i.e. regular file, directory) changed (T). Any combination of the filter characters (including none) can be used. When * (All-or-none) is added to the combination, all paths are selected if there is any file that matches other criteria in the comparison; if there is no file that matches other criteria, nothing is selected." + option :cookbook_version, + :long => '--cookbook-version VERSION', + :description => 'Version of cookbook to download (if there are multiple versions and cookbook_versions is false)' + def run if config[:name_only] output_mode = :name_only diff --git a/lib/chef/knife/download.rb b/lib/chef/knife/download.rb index e8f26a74aa..d8a0ed2eca 100644 --- a/lib/chef/knife/download.rb +++ b/lib/chef/knife/download.rb @@ -40,6 +40,10 @@ class Chef :default => true, :description => 'Turn off to avoid uploading existing files; only new (and possibly deleted) files with --no-diff' + option :cookbook_version, + :long => '--cookbook-version VERSION', + :description => 'Version of cookbook to download (if there are multiple versions and cookbook_versions is false)' + def run if name_args.length == 0 show_usage |