app/controllers/nodes.rb in chef-server-webui-0.8.16 vs app/controllers/nodes.rb in chef-server-webui-0.9.0.a3
- old
+ new
@@ -18,36 +18,36 @@
# limitations under the License.
#
require 'chef' / 'node'
-class ChefServerWebui::Nodes < ChefServerWebui::Application
+class Nodes < Application
provides :html
before :login_required
- before :authorized_node, :only => [ :update, :destroy ]
def index
- @node_list = begin
- Chef::Node.list
- rescue => e
- Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
- @_message = {:error => "Could not list nodes"}
- {}
- end
+ begin
+ node_hash = Chef::Node.list
+ @node_list = node_hash.keys.sort_by {|a,b| node_hash[a] <=> node_hash[b]}
+ rescue => e
+ Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
+ @_message = {:error => "Could not list nodes"}
+ @node_hash = {}
+ end
render
end
def show
- @node = begin
- Chef::Node.load(params[:id])
- rescue => e
- Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
- @_message = {:error => "Could not load node #{params[:id]}"}
- Chef::Node.new
- end
+ begin
+ @node =Chef::Node.load(params[:id])
+ rescue => e
+ Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
+ @_message = {:error => "Could not load node #{params[:id]}"}
+ @node = Chef::Node.new
+ end
render
end
def new
begin
@@ -84,18 +84,18 @@
def create
begin
@node = Chef::Node.new
@node.name params[:name]
- @node.attribute = JSON.parse(params[:attributes])
+ @node.normal_attrs = JSON.parse(params[:attributes])
@node.run_list.reset!(params[:for_node] ? params[:for_node] : [])
raise ArgumentError, "Node name cannot be blank" if (params[:name].nil? || params[:name].length==0)
@node.create
- redirect(slice_url(:nodes), :message => { :notice => "Created Node #{@node.name}" })
+ redirect(url(:nodes), :message => { :notice => "Created Node #{@node.name}" })
rescue => e
Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
- @node.attribute = JSON.parse(params[:attributes])
+ @node.normal_attrs = JSON.parse(params[:attributes])
@available_recipes = get_available_recipes
@available_roles = Chef::Role.list.keys.sort
@node.run_list params[:for_node]
@run_list = @node.run_list
@_message = { :error => "Exception raised creating node, #{e.message.length <= 150 ? e.message : "please check logs for details"}" }
@@ -105,11 +105,11 @@
def update
begin
@node = Chef::Node.load(params[:id])
@node.run_list.reset!(params[:for_node] ? params[:for_node] : [])
- @node.attribute = JSON.parse(params[:attributes])
+ @node.normal_attrs = JSON.parse(params[:attributes])
@node.save
@_message = { :notice => "Updated Node" }
render :show
rescue => e
Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
@@ -124,10 +124,10 @@
def destroy
begin
@node = Chef::Node.load(params[:id])
@node.destroy
- redirect(absolute_slice_url(:nodes), {:message => { :notice => "Node #{params[:id]} deleted successfully" }, :permanent => true})
+ redirect(absolute_url(:nodes), {:message => { :notice => "Node #{params[:id]} deleted successfully" }, :permanent => true})
rescue => e
Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
@node_list = Chef::Node.list()
@_message = {:error => "Could not delete the node"}
render :index