gluster-web-interface/app/controllers/node_controller.rb

76 lines
1.8 KiB
Ruby
Raw Normal View History

2016-09-14 08:54:30 +00:00
class NodeController < ApplicationController
2016-09-28 09:55:02 +00:00
before_action :require_login
2016-09-14 08:54:30 +00:00
def index
@hosts = Array.new
2016-09-29 09:35:57 +00:00
@nodes = Node.all.order("id asc")
2016-09-29 09:44:06 +00:00
@node_connects = Array.new
node_info = Hash.new
2016-09-29 09:35:57 +00:00
one_node = Node.take
2016-09-29 09:44:06 +00:00
node_info["Hostname"] = one_node.host_name
node_info["State"] = "Peer in Cluster Disconnected"
node_info = Hash.new
2016-09-29 09:35:57 +00:00
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"
2016-09-29 09:44:06 +00:00
2016-09-29 09:35:57 +00:00
output.each do |t|
next if t.equal? output.first
if t.include? ":"
temp = t.split(":")
2016-09-29 09:44:06 +00:00
node_info[temp[0]] = temp[1]
2016-09-29 09:35:57 +00:00
else
2016-09-29 09:44:06 +00:00
@node_connects << node_info
node_info = Hash.new
2016-09-29 09:35:57 +00:00
end
end
2016-09-29 09:44:06 +00:00
2016-09-29 09:35:57 +00:00
end
end
2016-09-14 08:54:30 +00:00
if get_hosts.blank?
flash[:danger] = "Check Server"
else
@hosts = get_hosts
end
end
def get_hosts
return ['2', 'aaa', 'bbb', 'ccc']
end
2016-09-24 09:00:27 +00:00
2016-09-20 12:14:13 +00:00
def node_add
2016-09-24 09:00:27 +00:00
new_node = Node.new
2016-09-20 12:14:13 +00:00
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
2016-09-24 09:00:27 +00:00
2016-09-20 12:14:13 +00:00
def node_delete
one_node = Node.find(params[:node_id])
one_node.destroy
redirect_to '/node/index'
end
2016-09-28 10:27:54 +00:00
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
2016-09-14 08:54:30 +00:00
end