diff options
Diffstat (limited to 'chef-server-api/app/controllers')
-rw-r--r-- | chef-server-api/app/controllers/environments.rb | 11 | ||||
-rw-r--r-- | chef-server-api/app/controllers/nodes.rb | 36 |
2 files changed, 22 insertions, 25 deletions
diff --git a/chef-server-api/app/controllers/environments.rb b/chef-server-api/app/controllers/environments.rb index baa7a74276..05f2d3549f 100644 --- a/chef-server-api/app/controllers/environments.rb +++ b/chef-server-api/app/controllers/environments.rb @@ -18,6 +18,7 @@ # require 'chef/environment' +require 'chef/cookbook_version_selector' class Environments < Application @@ -153,10 +154,18 @@ class Environments < Application end # Expand the run list in the scope of the specified environment. - names_to_cookbook_version = run_list.expand_to_cookbook_versions(environment_input, 'couchdb') + names_to_cookbook_version = Chef::CookbookVersionSelector.expand_to_cookbook_versions(run_list, environment_input) rescue Chef::Exceptions::CouchDBNotFound raise NotFound, "Cannot load environment #{params[:environment_id]}" + rescue Chef::Exceptions::CookbookVersionConflict => e + error = { :message => e.message, + #:unsatisfiable_solution_constraint => e.unsatisfiable_solution_constraint, + #:non_existent_cookbooks => e.disabled_non_existent_packages, + #:most_constrained_cookbooks => e.disabled_most_constrained_packages + } + raise PreconditionFailed, error.to_json end + # convert the hash which is # name => CookbookVersion diff --git a/chef-server-api/app/controllers/nodes.rb b/chef-server-api/app/controllers/nodes.rb index f726f9aee0..9147700080 100644 --- a/chef-server-api/app/controllers/nodes.rb +++ b/chef-server-api/app/controllers/nodes.rb @@ -17,9 +17,10 @@ # limitations under the License. # -require 'chef' / 'node' +require 'chef/node' require 'chef/version_class' require 'chef/version_constraint' +require 'chef/cookbook_version_selector' class Nodes < Application @@ -81,6 +82,8 @@ class Nodes < Application display @node end + # Return a hash, cookbook_name => cookbook manifest, of the cookbooks + # appropriate for this node, using its run_list and environment. def cookbooks begin @node = Chef::Node.cdb_load(params[:id]) @@ -88,30 +91,15 @@ class Nodes < Application raise NotFound, "Cannot load node #{params[:id]}" end - display(load_all_files) - end - - private - - def load_all_files - all_cookbooks = Chef::Environment.cdb_load_filtered_cookbook_versions(@node.chef_environment) - - included_cookbooks = cookbooks_for_node(all_cookbooks) - nodes_cookbooks = Hash.new - included_cookbooks.each do |cookbook_name, cookbook| - nodes_cookbooks[cookbook_name.to_s] = cookbook.generate_manifest_with_urls{|opts| absolute_url(:cookbook_file, opts) } - end + # Get the mapping of cookbook_name => CookbookVersion applicable to + # this node's run_list and its environment. + included_cookbooks = Chef::CookbookVersionSelector.expand_to_cookbook_versions(@node.run_list, @node.chef_environment) - nodes_cookbooks - end - - # returns name -> CookbookVersion for all cookbooks included on the given node. - def cookbooks_for_node(all_cookbooks) - begin - @node.constrain_cookbooks(all_cookbooks, 'couchdb') - rescue Chef::Exceptions::CookbookVersionConflict => e - raise PreconditionFailed, e.message - end + # Then map it to the return format. + display(included_cookbooks.inject({}) do |acc, (cookbook_name, cookbook)| + acc[cookbook_name.to_s] = cookbook.generate_manifest_with_urls{|opts| absolute_url(:cookbook_file, opts) } + acc + end) end end |