Skip to content

Commit 7ebaf9d

Browse files
committed
Adding role creation and indexing
1 parent 1317bf2 commit 7ebaf9d

37 files changed

Lines changed: 1170 additions & 53 deletions

chef-server-slice/app/controllers/exceptions.rb

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,17 @@
1717
# limitations under the License.
1818
#
1919

20-
class ChefServerSlice::Exceptions < ChefServerSlice::Application
20+
class Exceptions < ChefServerSlice::Application
2121

2222
provides :html, :json
2323

24-
# handle NotFound exceptions (404)
25-
def not_found
26-
display params
27-
end
28-
29-
# handle NotAcceptable exceptions (406)
30-
def not_acceptable
31-
display params
32-
end
33-
34-
# handle BadRequest exceptions (400)
35-
def bad_request
36-
display params
24+
def standard_error
25+
Merb.logger.warn(request.content_type)
26+
if request.accept =~ /application\/json/
27+
display({ "error" => request.exceptions })
28+
else
29+
display(params)
30+
end
3731
end
3832

3933
end
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
require 'chef/role'
2+
3+
class ChefServerSlice::Roles < ChefServerSlice::Application
4+
5+
provides :html, :json
6+
before :login_required
7+
8+
# GET /roles
9+
def index
10+
@role_list = Chef::Role.list(true)
11+
display @role_list
12+
end
13+
14+
# GET /roles/:id
15+
def show
16+
render
17+
end
18+
19+
# GET /roles/new
20+
def new
21+
cl = Chef::CookbookLoader.new
22+
@available_recipes = cl.sort{ |a,b| a.name.to_s <=> b.name.to_s }
23+
@current_recipes = Array.new
24+
render
25+
end
26+
27+
# GET /roles/:id/edit
28+
def edit
29+
render
30+
end
31+
32+
# GET /roles/:id/delete
33+
def delete
34+
render
35+
end
36+
37+
# POST /roles
38+
def create
39+
if params.has_key?("inflated_object")
40+
@role = params["inflated_object"]
41+
@role.save
42+
self.status = 201
43+
display({ :uri => slice_url(:role, @role.name) })
44+
else
45+
@role = Chef::Role.new
46+
@role.name(params[:name])
47+
@role.recipes(params[:for_role])
48+
@role.description(params[:description]) if params[:description] != ''
49+
@role.default_attributes(JSON.parse(params[:default_attributes])) if params[:default_attributes] != ''
50+
@role.override_attributes(JSON.parse(params[:override_attributes])) if params[:override_attributes] != ''
51+
@role.save
52+
redirect(slice_url(:roles), :message => { :notice => "Created Role #{@role.name}" })
53+
end
54+
end
55+
56+
# PUT /roles/:id
57+
def update
58+
render
59+
end
60+
61+
# DELETE /roles/:id
62+
def destroy
63+
render
64+
end
65+
66+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Merb
2+
module RolesHelper
3+
4+
end
5+
end # Merb

chef-server-slice/app/views/layout/chef_server_slice.html.haml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
%head
55
%meta{ "http-equiv" => "content-type", :content => "text/html; charset=utf-8" }
66
%title Chef Server
7-
= css_include_tag "base", "themes/djime-cerulean/style", "chef", "/facebox/facebox.css"
8-
= js_include_tag "jquery-1.3.1.min", "jquery.jeditable.mini", "jquery.livequery", "jquery.localscroll", "jquery.scrollTo"
7+
= css_include_tag "base", "themes/djime-cerulean/style", "chef", "/facebox/facebox.css", "jquery-ui-1.7.1.custom"
8+
= js_include_tag "jquery-1.3.2.min", "jquery.jeditable.mini", "jquery.livequery", "jquery.localscroll", "jquery.scrollTo"
99
= js_include_tag "/facebox/facebox.js"
1010
= js_include_tag "chef"
11+
= js_include_tag "jquery-ui-1.7.1.custom.min"
1112
1213
%body
1314
#container
@@ -24,6 +25,7 @@
2425
%ul
2526
%li= link_to "Search", slice_url(:searches)
2627
%li= link_to "Status", slice_url(:status)
28+
%li= link_to "Roles", slice_url(:roles)
2729
%li= link_to "Nodes", slice_url(:nodes)
2830
%li= link_to "Cookbooks", slice_url(:cookbooks)
2931
%li= link_to "Registrations", slice_url(:registrations)
@@ -33,7 +35,7 @@
3335
- unless message.empty?
3436
.block#block-messages
3537
.content
36-
%h2.title Error Messages
38+
%h2.title Messages
3739
.inner
3840
.flash
3941
- message.each do |type, msg|
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
%h1 Roles controller, edit action
2+
3+
%p
4+
Edit this file in
5+
%tt app/views/roles/edit.html.haml
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.block#block-tables
2+
.content
3+
%h2.title Roles
4+
.inner
5+
%table.table
6+
%tr
7+
%th.first Name
8+
%th Description
9+
%th.last &nbsp;
10+
- even = false;
11+
- @role_list.each do |role|
12+
%tr{ :class => even ? "even" : "odd" }
13+
%td= link_to(role.name, slice_url(:role, role.name))
14+
%td= role.description
15+
%td
16+
= link_to('Edit', slice_url(:edit_role, role.name))
17+
|
18+
= link_to('Destroy', slice_url(:role, role.name))
19+
- even ? even = false: even = true
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
.block#block-tables
2+
.content
3+
%h2.title Create New Role
4+
.inner
5+
= form :action => slice_url(:roles), :method => :post, :id => 'create_role', :class => 'form' do
6+
%div.group
7+
%label.label Name
8+
= text_field :name => "name", :class => "text_field"
9+
%span.description The name of the Role
10+
%div.group
11+
%label.label Description
12+
= text_area :name => "description", :class => "text_area"
13+
%span.description A description of this Role
14+
%div.group
15+
%label.label Default Attributes
16+
= text_area :name => "default_attributes", :class => "text_area", :rows => 10, :cols => 80
17+
%span.description A JSON hash for default attributes for nodes of this role. These attributes will only be applied if the node does not already have a value for the attributes.
18+
%div.group
19+
%label.label Override Attributes
20+
= text_area :name => "override_attributes", :class => "text_area", :rows => 10, :cols => 80
21+
%span.description A JSON hash for the override attributes for nodes which have this role. These attributes will always apply to every node with this role, regardless of any other value.
22+
%div.group
23+
%table.sortable
24+
%tr
25+
%td
26+
%label.label Available Recipes
27+
%td
28+
%label.label Recipes for this Role
29+
%tr
30+
%td
31+
%div.sortable
32+
%ul#available_recipes.connectedSortable
33+
- @available_recipes.each do |cookbook|
34+
%li{ :id => h(cookbook.name), :class => 'ui-state-highlight' }= h cookbook.name
35+
%td
36+
%div.sortable
37+
%ul#for_role.connectedSortable
38+
39+
%td.help
40+
%span.description
41+
Drag recipes from the list of Available Recipes section on the left, and drop them
42+
in the "Recipes for this Role" section on the right. Then sort the recipes for this role list to the order you would like to see the recipes applied.
43+
%div.group
44+
.actions-bar
45+
.actions= submit "Create Role", :id => 'create_role_button', :class => 'button'
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
%h1 Roles controller, show action
2+
3+
%p
4+
Edit this file in
5+
%tt app/views/roles/show.html.haml

chef-server-slice/config/init.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@
3838
c[:session_secret_key] = Chef::Config.manage_secret_key
3939
c[:session_store] = 'cookie'
4040
c[:exception_details] = true
41-
c[:reload_classes] = false
41+
c[:reload_classes] = true
4242
end
4343

chef-server-slice/config/router.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# This file is here so slice can be testing as a stand alone application.
22

33
#Merb::Router.prepare do
4+
# resources :roles
45
# ...
5-
#end
6+
#end

0 commit comments

Comments
 (0)