Update
This commit is contained in:
parent
a37d4b6051
commit
1b5864a7c1
@ -1,75 +1,73 @@
|
|||||||
class NodeController < ApplicationController
|
class NodeController < ApplicationController
|
||||||
before_action :require_login
|
before_action :require_login
|
||||||
def index
|
def index
|
||||||
@hosts = Array.new
|
@hosts = Array.new
|
||||||
@nodes = Node.all.order("id asc")
|
@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
|
||||||
|
|
||||||
@node_connects = Array.new
|
if !one_node.blank?
|
||||||
node_info = Hash.new
|
if ping_test?(one_node.host_ip)
|
||||||
one_node = Node.take
|
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"
|
||||||
|
|
||||||
node_info["Hostname"] = one_node.host_name
|
output.each do |t|
|
||||||
node_info["State"] = "Peer in Cluster Disconnected"
|
next if t.equal? output.first
|
||||||
node_info = Hash.new
|
if t.include? ":"
|
||||||
|
temp = t.split(":")
|
||||||
|
node_info[temp[0]] = temp[1]
|
||||||
|
else
|
||||||
|
@node_connects << node_info
|
||||||
|
node_info = Hash.new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if !one_node.blank?
|
end
|
||||||
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
|
||||||
|
|
||||||
|
if get_hosts.blank?
|
||||||
|
flash[:danger] = "Check Server"
|
||||||
|
else
|
||||||
|
@hosts = get_hosts
|
||||||
|
end
|
||||||
|
rescue => ex
|
||||||
|
puts ex
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if get_hosts.blank?
|
def node_add
|
||||||
flash[:danger] = "Check Server"
|
new_node = Node.new
|
||||||
else
|
new_node.host_name = params[:host_name]
|
||||||
@hosts = get_hosts
|
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
|
||||||
end
|
|
||||||
|
|
||||||
def get_hosts
|
def node_delete
|
||||||
return ['2', 'aaa', 'bbb', 'ccc']
|
one_node = Node.find(params[:node_id])
|
||||||
end
|
one_node.destroy
|
||||||
|
redirect_to '/node/index'
|
||||||
|
end
|
||||||
|
|
||||||
def node_add
|
def node_prove
|
||||||
new_node = Node.new
|
one_node = Node.find(params[:node_id])
|
||||||
new_node.host_name = params[:host_name]
|
puts "gluster peer probe #{one_node.host_name}"
|
||||||
new_node.host_ip = params[:host_ip]
|
redirect_to '/node/index'
|
||||||
new_node.user_name = params[:user_name]
|
end
|
||||||
new_node.user_password = params[:user_password]
|
|
||||||
new_node.save
|
|
||||||
redirect_to '/node/index'
|
|
||||||
end
|
|
||||||
|
|
||||||
def node_delete
|
def node_detach
|
||||||
one_node = Node.find(params[:node_id])
|
one_node = Node.find(params[:node_id])
|
||||||
one_node.destroy
|
puts "gluster peer detach #{one_node.host_name}"
|
||||||
redirect_to '/node/index'
|
redirect_to '/node/index'
|
||||||
end
|
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
|
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
module ApplicationHelper
|
module ApplicationHelper
|
||||||
|
require 'net/ping'
|
||||||
|
|
||||||
def get_df
|
def get_df
|
||||||
df = Array.new
|
df = Array.new
|
||||||
@ -136,4 +137,8 @@ module ApplicationHelper
|
|||||||
return files
|
return files
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ping_test?(host)
|
||||||
|
check = Net::Ping::External.new(host)
|
||||||
|
return check.ping?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,2 @@
|
|||||||
module NodeHelper
|
module NodeHelper
|
||||||
require 'net/ping'
|
|
||||||
def ping_test?(host)
|
|
||||||
check = Net::Ping::External.new(host)
|
|
||||||
check.ping?
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@ -105,7 +105,7 @@
|
|||||||
|
|
||||||
<!-- file manager -->
|
<!-- file manager -->
|
||||||
<div class="col-md-8 col-sm-8 col-xs-12">
|
<div class="col-md-8 col-sm-8 col-xs-12">
|
||||||
<div class="panel panel-body">
|
<div id="pagecontent" class="panel panel-body">
|
||||||
<div class="x_title" id="file_manager_title_div">
|
<div class="x_title" id="file_manager_title_div">
|
||||||
<h2 style="width:130px">File Manager</h2>
|
<h2 style="width:130px">File Manager</h2>
|
||||||
</div>
|
</div>
|
||||||
@ -350,10 +350,13 @@ $(document).on("click", "#file_manager_div .chdir", function(){
|
|||||||
var next_dir = current_dir + "/" + file_name;
|
var next_dir = current_dir + "/" + file_name;
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
method: "post",
|
method : "post",
|
||||||
url: "/home/chdir",
|
url : "/home/chdir",
|
||||||
data: { next_dir : next_dir },
|
data : { next_dir : next_dir },
|
||||||
success : function(result){
|
beforeSend : function(){
|
||||||
|
Pace.start();
|
||||||
|
},
|
||||||
|
success : function(result){
|
||||||
$("#current_dir").val(next_dir);
|
$("#current_dir").val(next_dir);
|
||||||
$("#file_manager_title_div").empty().append("<h2 style='width:130px'>File manager</h2>");
|
$("#file_manager_title_div").empty().append("<h2 style='width:130px'>File manager</h2>");
|
||||||
$("#disk_usage_title_div").empty().append("<h2 style='width:130px'>Disk usage</h2>");
|
$("#disk_usage_title_div").empty().append("<h2 style='width:130px'>Disk usage</h2>");
|
||||||
@ -362,6 +365,7 @@ $(document).on("click", "#file_manager_div .chdir", function(){
|
|||||||
|
|
||||||
draw_datatable();
|
draw_datatable();
|
||||||
draw_chart(result.du);
|
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);
|
var next_dir = current_dir.substring(0, lastindex);
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
method: "POST",
|
method : "POST",
|
||||||
url: "/home/chdir",
|
url : "/home/chdir",
|
||||||
data: { next_dir : next_dir },
|
data : { next_dir : next_dir },
|
||||||
success : function(result){
|
beforeSend : function(){
|
||||||
|
Pace.start();
|
||||||
|
},
|
||||||
|
success : function(result){
|
||||||
$("#current_dir").val(next_dir);
|
$("#current_dir").val(next_dir);
|
||||||
$("#file_manager_title_div").empty().append("<h2 style='width:130px'>File manager</h2>");
|
$("#file_manager_title_div").empty().append("<h2 style='width:130px'>File manager</h2>");
|
||||||
$("#disk_usage_title_div").empty().append("<h2 style='width:130px'>Disk usage</h2>");
|
$("#disk_usage_title_div").empty().append("<h2 style='width:130px'>Disk usage</h2>");
|
||||||
@ -388,6 +395,7 @@ $(document).on("click", "#file_manager_div .chupper", function(){
|
|||||||
|
|
||||||
draw_datatable();
|
draw_datatable();
|
||||||
draw_chart(result.du);
|
draw_chart(result.du);
|
||||||
|
Pace.stop();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -87,11 +87,21 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
|
<% nodes = Node.all %>
|
||||||
|
<% if nodes.length == 0 %>
|
||||||
|
<div class="row animated flipInX col-md-6 col-sm-9 col-xs-12">
|
||||||
|
<div class="alert alert-info" role="alert">
|
||||||
|
<span class="glyphicon glyphicon-bell" area-hidden="true"></span>
|
||||||
|
<span class="glyphicon-class">You don't have a node. Please add nodes to do something in this page.</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% else %>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<% volumes.each_with_index do |volume, index| %>
|
<% volumes.each_with_index do |volume, index| %>
|
||||||
<%= raw volume_info(volume, index) %>
|
<%= raw volume_info(volume, index) %>
|
||||||
<%end%>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<!-- /page content -->
|
<!-- /page content -->
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user