summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom.may@betfair.com>2010-07-09 14:09:35 +0100
committerSeth Falcon <seth@opscode.com>2010-11-01 10:44:52 -0700
commit16302e94840a5682be7bbe29c343ec8b8bcacab6 (patch)
tree0993f1ae3d2146413dd0ab7655ce3efb753bd071
parentf77f78afe9eb92ece5465efac7f1a5134373b7db (diff)
downloadchef-16302e94840a5682be7bbe29c343ec8b8bcacab6.tar.gz
Convert index_recipes to return *all* recipes
This changes the API somewhat; rather than just an array of recipes (which is bust because recipes may only exist in certain versions of cookbooks) you get a hash back: cookbook -> version -> recipes. Change the only two places that use _recipes to DTRT
-rw-r--r--chef-server-api/app/controllers/cookbooks.rb10
-rw-r--r--chef-server-webui/app/controllers/application.rb9
-rw-r--r--chef/lib/chef/knife/recipe_list.rb1
3 files changed, 8 insertions, 12 deletions
diff --git a/chef-server-api/app/controllers/cookbooks.rb b/chef-server-api/app/controllers/cookbooks.rb
index 1c0490d744..dc3d18383e 100644
--- a/chef-server-api/app/controllers/cookbooks.rb
+++ b/chef-server-api/app/controllers/cookbooks.rb
@@ -58,13 +58,11 @@ class Cookbooks < Application
end
def index_recipes
- all_cookbooks = Array(Chef::CookbookVersion.cdb_list_latest(true))
- all_cookbooks.map! do |cookbook|
- cookbook.manifest["recipes"].map { |r| "#{cookbook.name}::#{File.basename(r['name'], ".rb")}" }
+ display Chef::CookbookVersion.cdb_list(true).inject({}) do |memo, f|
+ memo[f.name] ||= {}
+ memo[f.name][f.version] = f.recipe_filenames_by_name.keys
+ memo
end
- all_cookbooks.flatten!
- all_cookbooks.sort!
- display all_cookbooks
end
def show_versions
diff --git a/chef-server-webui/app/controllers/application.rb b/chef-server-webui/app/controllers/application.rb
index 1e4fdf0e92..79721729f1 100644
--- a/chef-server-webui/app/controllers/application.rb
+++ b/chef-server-webui/app/controllers/application.rb
@@ -256,12 +256,9 @@ class Application < Merb::Controller
def get_available_recipes
r = Chef::REST.new(Chef::Config[:chef_server_url])
all_recipes = Array.new
- r.get_rest('cookbooks').keys.each do |cb|
- all_recipes << r.get_rest("cookbooks/#{cb}")[cb].sort!{|x,y| y <=> x }.map do |ver|
- r.get_rest("cookbooks/#{cb}/#{ver}").recipe_filenames.map do |rec|
- rn = File.basename(rec, ".rb")
- rn == "default" ? "#{cb} #{ver}" : "#{cb}::#{rn} #{ver}"
- end
+ r.get_rest('cookbooks/_recipes').keys.each do |cb|
+ all_recipes << all[cb].sort{|x,y| y <=> x }.map do |ver, recipes|
+ recipes.map{ |rn| rn == "default" ? "#{cb} #{ver}" : "#{cb}::#{rn} #{ver}" }
end
end
all_recipes.flatten.uniq
diff --git a/chef/lib/chef/knife/recipe_list.rb b/chef/lib/chef/knife/recipe_list.rb
index c630a2b406..ef165a3c6c 100644
--- a/chef/lib/chef/knife/recipe_list.rb
+++ b/chef/lib/chef/knife/recipe_list.rb
@@ -23,6 +23,7 @@ class Chef::Knife::RecipeList < Chef::Knife
def run
recipes = rest.get_rest('cookbooks/_recipes')
+ recipes = recipes.keys.map { |cb| recipes[cb].map {|ver, rec| rec.map{ |rn| "#{cb}::#{rn} (#{ver})" }}}.flatten.uniq
if pattern = @name_args.first
recipes = recipes.grep(Regexp.new(pattern))
end