Class: ChefServerSlice::Roles
- Inherits:
-
Application
- Object
- Merb::Controller
- Application
- ChefServerSlice::Roles
- Defined in:
- app/controllers/roles.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /roles.
-
#delete ⇒ Object
GET /roles/:id/delete.
-
#destroy ⇒ Object
DELETE /roles/:id.
-
#edit ⇒ Object
GET /roles/:id/edit.
-
#index ⇒ Object
GET /roles.
-
#new ⇒ Object
GET /roles/new.
-
#show ⇒ Object
GET /roles/:id.
-
#update ⇒ Object
PUT /roles/:id.
Methods inherited from Application
#absolute_slice_url, #access_denied, #authorized_node, #escape_node_id, #expand_cookbook_deps, #fix_up_node_id, #get_available_recipes, #load_all_files, #load_cookbook_segment, #login_required, #redirect_back_or_default, #segment_files, #specific_cookbooks, #store_location
Instance Method Details
#create ⇒ Object
POST /roles
50 51 52 53 54 55 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 |
# File 'app/controllers/roles.rb', line 50 def create if params.has_key?("inflated_object") @role = params["inflated_object"] exists = true begin Chef::Role.load(@role.name) rescue Net::HTTPServerException exists = false end raise Forbidden, "Role already exists" if exists @role.save self.status = 201 display({ :uri => absolute_slice_url(:role, @role.name) }) else begin @role = Chef::Role.new @role.name(params[:name]) @role.recipes(params[:for_role] ? params[:for_role] : []) @role.description(params[:description]) if params[:description] != '' @role.default_attributes(JSON.parse(params[:default_attributes])) if params[:default_attributes] != '' @role.override_attributes(JSON.parse(params[:override_attributes])) if params[:override_attributes] != '' @role.save redirect(slice_url(:roles), :message => { :notice => "Created Role #{@role.name}" }) rescue ArgumentError @available_recipes = get_available_recipes @role = Chef::Role.new @role.default_attributes(JSON.parse(params[:default_attributes])) if params[:default_attributes] != '' @role.override_attributes(JSON.parse(params[:override_attributes])) if params[:override_attributes] != '' @current_recipes = params[:for_role] ? params[:for_role] : [] @_message = { :error => $! } render :new end end end |
#delete ⇒ Object
GET /roles/:id/delete
45 46 47 |
# File 'app/controllers/roles.rb', line 45 def delete end |
#destroy ⇒ Object
DELETE /roles/:id
123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'app/controllers/roles.rb', line 123 def destroy begin @role = Chef::Role.load(params[:id]) rescue Net::HTTPServerException => e raise NotFound, "Cannot load role #{params[:id]}" end @role.destroy if request.accept == "application/json" display @role else redirect(absolute_slice_url(:roles), :message => { :notice => "Role #{@role.name} deleted successfully." }, :permanent => true) end end |
#edit ⇒ Object
GET /roles/:id/edit
33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/roles.rb', line 33 def edit begin @role = Chef::Role.load(params[:id]) rescue Net::HTTPServerException => e raise NotFound, "Cannot load role #{params[:id]}" end @available_recipes = get_available_recipes @current_recipes = @role.recipes render end |
#index ⇒ Object
GET /roles
9 10 11 12 |
# File 'app/controllers/roles.rb', line 9 def index @role_list = Chef::Role.list(true) display(@role_list.collect { |r| absolute_slice_url(:role, r.name) }) end |
#new ⇒ Object
GET /roles/new
25 26 27 28 29 30 |
# File 'app/controllers/roles.rb', line 25 def new @available_recipes = get_available_recipes @role = Chef::Role.new @current_recipes = @role.recipes render end |
#show ⇒ Object
GET /roles/:id
15 16 17 18 19 20 21 22 |
# File 'app/controllers/roles.rb', line 15 def show begin @role = Chef::Role.load(params[:id]) rescue Net::HTTPServerException => e raise NotFound, "Cannot load role #{params[:id]}" end display @role end |
#update ⇒ Object
PUT /roles/:id
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'app/controllers/roles.rb', line 87 def update begin @role = Chef::Role.load(params[:id]) rescue Net::HTTPServerException => e raise NotFound, "Cannot load role #{params[:id]}" end if params.has_key?("inflated_object") @role.description(params["inflated_object"].description) @role.recipes(params["inflated_object"].recipes) @role.default_attributes(params["inflated_object"].default_attributes) @role.override_attributes(params["inflated_object"].override_attributes) @role.save self.status = 200 display(@role) else begin @role.recipes(params[:for_role]) @role.description(params[:description]) if params[:description] != '' @role.default_attributes(JSON.parse(params[:default_attributes])) if params[:default_attributes] != '' @role.override_attributes(JSON.parse(params[:override_attributes])) if params[:override_attributes] != '' @role.save @_message = { :notice => "Updated Role" } render :show rescue ArgumentError @available_recipes = get_available_recipes @current_recipes = params[:for_role] ? params[:for_role] : [] @role.default_attributes(JSON.parse(params[:default_attributes])) if params[:default_attributes] != '' @role.override_attributes(JSON.parse(params[:override_attributes])) if params[:override_attributes] != '' render :edit end end end |