summaryrefslogtreecommitdiff
path: root/chef-server-api/app
diff options
context:
space:
mode:
authorTim Hinderliter <tim@opscode.com>2011-03-16 16:16:31 -0700
committerTim Hinderliter <tim@opscode.com>2011-03-17 16:58:27 -0700
commit492f1e11c837934f3270211111c5ce276113eb88 (patch)
tree9cb25f9bbc82bb082334c2bbdc7f8c228af5c597 /chef-server-api/app
parent834dc9836999874643c06d28bc104c782492f423 (diff)
downloadchef-492f1e11c837934f3270211111c5ce276113eb88.tar.gz
Fixed attributes precendence order broken by previous Client/RunContext/Node refactors.
Re-did fixture text in attribute_settings cuke to make debugging easier. Fixed bug in Chef::Exceptions::CookbookVersionSelection::UnsatisfiableRunListItem#to_json Refactored Node#expand! again, to not clear out default & override attributes; restored Node#reset_defaults_and_overrides; factored out merging of expansion attributes to Node#apply_expansion_attributes; Node#expand! now returns RunListException instead of VersionedRunList Fixed bug with passing of recipes to RunContext#load which was causing us to lose version pinning information directly in the run_list. Added VersionedRecipeList#with_version_constraints_strings, which returns and array of strings like ["recipe@1.2.3", "recipe2@2.3.4"] Moved checking of Chef::Config[:environment] to Client#build_node, out of Node#find_or_create
Diffstat (limited to 'chef-server-api/app')
-rw-r--r--chef-server-api/app/controllers/environments.rb92
-rw-r--r--chef-server-api/app/controllers/nodes.rb4
2 files changed, 46 insertions, 50 deletions
diff --git a/chef-server-api/app/controllers/environments.rb b/chef-server-api/app/controllers/environments.rb
index f3b207db90..d5e20171fe 100644
--- a/chef-server-api/app/controllers/environments.rb
+++ b/chef-server-api/app/controllers/environments.rb
@@ -111,7 +111,48 @@ class Environments < Application
})
end
- # POST /environment/:environment_id/cookbook_versions
+ # GET /environments/:environment_id/cookbooks/:cookbook_id
+ # returns data in the format of:
+ # {"apache2" => {
+ # :url => "http://url",
+ # :versions => [{:url => "http://url/1.0.0", :version => "1.0.0"}, {:url => "http://url/0.0.1", :version=>"0.0.1"}]
+ # }
+ # }
+ def cookbook
+ cookbook_name = params[:cookbook_id]
+ begin
+ filtered_cookbooks = Chef::Environment.cdb_load_filtered_cookbook_versions(params[:environment_id])
+ rescue Chef::Exceptions::CouchDBNotFound
+ raise NotFound, "Cannot load environment #{params[:environment_id]}"
+ end
+ raise NotFound, "Cannot load cookbook #{cookbook_name}" unless filtered_cookbooks.has_key?(cookbook_name)
+ versions = filtered_cookbooks[cookbook_name].map{|v| v.version.to_s}
+ num_versions = num_versions!("all")
+ display({ cookbook_name => expand_cookbook_urls(cookbook_name, versions, num_versions) })
+ end
+
+ # GET /environments/:environment/recipes
+ def list_recipes
+ display(Chef::Environment.cdb_load_filtered_recipe_list(params[:environment_id]))
+ end
+
+ # GET /environments/:environment_id/nodes
+ def list_nodes
+ node_list = Chef::Node.cdb_list_by_environment(params[:environment_id])
+ display(node_list.inject({}) {|r,n| r[n] = absolute_url(:node, n); r})
+ end
+
+ # GET /environments/:environment_id/roles/:role_id
+ def role
+ begin
+ role = Chef::Role.cdb_load(params[:role_id])
+ rescue Chef::Exceptions::CouchDBNotFound
+ raise NotFound, "Cannot load role #{params[:role_id]}"
+ end
+ display("run_list" => role.env_run_lists[params[:environment_id]])
+ end
+
+ # POST /environments/:environment_id/cookbook_versions
#
# Take the given run_list and return the versions of cookbooks that would
# be used after applying the constraints of the given environment.
@@ -158,54 +199,9 @@ class Environments < Application
# to
# name => cookbook manifest
# and display.
- display(names_to_cookbook_version.inject({}) do |res, (cb_name, cb_version)|
- res[cb_name] = cb_version.generate_manifest_with_urls {|opts| absolute_url(:cookbook_file, opts) }
+ display(names_to_cookbook_version.inject({}) do |res, (cookbook_name, cookbook_version)|
+ res[cookbook_name] = cookbook_version.generate_manifest_with_urls {|opts| absolute_url(:cookbook_file, opts) }
res
end)
end
-
-
- # GET /environments/:environment_id/cookbooks/:cookbook_id
- # returns data in the format of:
- # {"apache2" => {
- # :url => "http://url",
- # :versions => [{:url => "http://url/1.0.0", :version => "1.0.0"}, {:url => "http://url/0.0.1", :version=>"0.0.1"}]
- # }
- # }
- def cookbook
- cookbook_name = params[:cookbook_id]
- begin
- filtered_cookbooks = Chef::Environment.cdb_load_filtered_cookbook_versions(params[:environment_id])
- rescue Chef::Exceptions::CouchDBNotFound
- raise NotFound, "Cannot load environment #{params[:environment_id]}"
- end
- raise NotFound, "Cannot load cookbook #{cookbook_name}" unless filtered_cookbooks.has_key?(cookbook_name)
- versions = filtered_cookbooks[cookbook_name].map{|v| v.version.to_s}
- num_versions = num_versions!("all")
- display({ cookbook_name => expand_cookbook_urls(cookbook_name, versions, num_versions) })
- end
-
- # GET /environments/:environment/recipes
- def list_recipes
- display(Chef::Environment.cdb_load_filtered_recipe_list(params[:environment_id]))
- end
-
- # GET /environments/:environment_id/nodes
- def list_nodes
- node_list = Chef::Node.cdb_list_by_environment(params[:environment_id])
- display(node_list.inject({}) {|r,n| r[n] = absolute_url(:node, n); r})
- end
-
- # GET /environments/:environment_id/roles/:role_id
- def role
- begin
- role = Chef::Role.cdb_load(params[:role_id])
- rescue Chef::Exceptions::CouchDBNotFound
- raise NotFound, "Cannot load role #{params[:role_id]}"
- end
- display("run_list" => role.env_run_lists[params[:environment_id]])
- end
-
- private
-
end
diff --git a/chef-server-api/app/controllers/nodes.rb b/chef-server-api/app/controllers/nodes.rb
index e71b8acea1..72564f02fe 100644
--- a/chef-server-api/app/controllers/nodes.rb
+++ b/chef-server-api/app/controllers/nodes.rb
@@ -106,8 +106,8 @@ class Nodes < Application
# to
# name => cookbook manifest
# and display.
- 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) }
+ display(included_cookbooks.inject({}) do |acc, (cookbook_name, cookbook_version)|
+ acc[cookbook_name.to_s] = cookbook_version.generate_manifest_with_urls{|opts| absolute_url(:cookbook_file, opts) }
acc
end)
end