diff --git a/app/controllers/node_controller.rb b/app/controllers/node_controller.rb index 778d597..eccb73a 100644 --- a/app/controllers/node_controller.rb +++ b/app/controllers/node_controller.rb @@ -1,75 +1,73 @@ class NodeController < ApplicationController before_action :require_login - def index - @hosts = Array.new - @nodes = Node.all.order("id asc") - - @node_connects = Array.new - node_info = Hash.new - one_node = Node.take - - node_info["Hostname"] = one_node.host_name - node_info["State"] = "Peer in Cluster Disconnected" - node_info = Hash.new - - if !one_node.blank? - if ping_test?(one_node.host_ip) - command = String.new - command << "sshpass -p#{one_node.user_password} ssh #{one_node.user_name}@#{one_node.host_ip} gluster peer status info" - puts command - output = `#{command}`.split("\n") - output << "\n" - - output.each do |t| - next if t.equal? output.first - if t.include? ":" - temp = t.split(":") - node_info[temp[0]] = temp[1] - else - @node_connects << node_info - node_info = Hash.new + def index + @hosts = Array.new + @nodes = Node.all.order("id asc") + @node_connects = Array.new + node_info = Hash.new + begin + one_node = Node.take + node_info["Hostname"] = one_node.host_name + node_info["State"] = "Peer in Cluster Disconnected" + node_info = Hash.new + + if !one_node.blank? + if ping_test?(one_node.host_ip) + command = String.new + command << "sshpass -p#{one_node.user_password} ssh #{one_node.user_name}@#{one_node.host_ip} gluster peer status info" + puts command + output = `#{command}`.split("\n") + output << "\n" + + output.each do |t| + next if t.equal? output.first + if t.include? ":" + temp = t.split(":") + node_info[temp[0]] = temp[1] + else + @node_connects << node_info + node_info = Hash.new + end + end + + end end + + if get_hosts.blank? + flash[:danger] = "Check Server" + else + @hosts = get_hosts + end + rescue => ex + puts ex end - - end end - - if get_hosts.blank? - flash[:danger] = "Check Server" - else - @hosts = get_hosts + + def node_add + new_node = Node.new + new_node.host_name = params[:host_name] + new_node.host_ip = params[:host_ip] + new_node.user_name = params[:user_name] + new_node.user_password = params[:user_password] + new_node.save + redirect_to '/node/index' end - end - def get_hosts - return ['2', 'aaa', 'bbb', 'ccc'] - end + def node_delete + one_node = Node.find(params[:node_id]) + one_node.destroy + redirect_to '/node/index' + end - def node_add - new_node = Node.new - new_node.host_name = params[:host_name] - new_node.host_ip = params[:host_ip] - new_node.user_name = params[:user_name] - new_node.user_password = params[:user_password] - new_node.save - redirect_to '/node/index' - end + def node_prove + one_node = Node.find(params[:node_id]) + puts "gluster peer probe #{one_node.host_name}" + redirect_to '/node/index' + end - def node_delete - one_node = Node.find(params[:node_id]) - one_node.destroy - redirect_to '/node/index' - end - - def node_prove - one_node = Node.find(params[:node_id]) - puts "gluster peer probe #{one_node.host_name}" - redirect_to '/node/index' - end - - def node_detach - one_node = Node.find(params[:node_id]) - puts "gluster peer detach #{one_node.host_name}" - redirect_to '/node/index' - end + def node_detach + one_node = Node.find(params[:node_id]) + puts "gluster peer detach #{one_node.host_name}" + redirect_to '/node/index' + end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a79846c..066c2af 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,4 +1,5 @@ module ApplicationHelper + require 'net/ping' def get_df df = Array.new @@ -73,7 +74,7 @@ module ApplicationHelper du_each['file_name'] = "empty" du << du_each end - + du.sort_by! { |k| k['usage'] } du.reverse! return du @@ -136,4 +137,8 @@ module ApplicationHelper return files end + def ping_test?(host) + check = Net::Ping::External.new(host) + return check.ping? + end end diff --git a/app/helpers/node_helper.rb b/app/helpers/node_helper.rb index a0b203f..ff049b0 100644 --- a/app/helpers/node_helper.rb +++ b/app/helpers/node_helper.rb @@ -1,7 +1,2 @@ module NodeHelper - require 'net/ping' - def ping_test?(host) - check = Net::Ping::External.new(host) - check.ping? - end end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 3028d33..8363148 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -105,7 +105,7 @@
-
+

File Manager

@@ -350,10 +350,13 @@ $(document).on("click", "#file_manager_div .chdir", function(){ var next_dir = current_dir + "/" + file_name; $.ajax({ - method: "post", - url: "/home/chdir", - data: { next_dir : next_dir }, - success : function(result){ + method : "post", + url : "/home/chdir", + data : { next_dir : next_dir }, + beforeSend : function(){ + Pace.start(); + }, + success : function(result){ $("#current_dir").val(next_dir); $("#file_manager_title_div").empty().append("

File manager

"); $("#disk_usage_title_div").empty().append("

Disk usage

"); @@ -362,6 +365,7 @@ $(document).on("click", "#file_manager_div .chdir", function(){ draw_datatable(); draw_chart(result.du); + Pace.stop(); } }) }) @@ -376,10 +380,13 @@ $(document).on("click", "#file_manager_div .chupper", function(){ var next_dir = current_dir.substring(0, lastindex); $.ajax({ - method: "POST", - url: "/home/chdir", - data: { next_dir : next_dir }, - success : function(result){ + method : "POST", + url : "/home/chdir", + data : { next_dir : next_dir }, + beforeSend : function(){ + Pace.start(); + }, + success : function(result){ $("#current_dir").val(next_dir); $("#file_manager_title_div").empty().append("

File manager

"); $("#disk_usage_title_div").empty().append("

Disk usage

"); @@ -388,6 +395,7 @@ $(document).on("click", "#file_manager_div .chupper", function(){ draw_datatable(); draw_chart(result.du); + Pace.stop(); } }) }) diff --git a/app/views/volume/index.html.erb b/app/views/volume/index.html.erb index 0716312..e4446ea 100644 --- a/app/views/volume/index.html.erb +++ b/app/views/volume/index.html.erb @@ -87,11 +87,21 @@
+ <% nodes = Node.all %> + <% if nodes.length == 0 %> +
+ +
+ <% else %>
<% volumes.each_with_index do |volume, index| %> <%= raw volume_info(volume, index) %> - <%end%> + <% end %>
+ <% end %>