Add ssh_nodes
This commit is contained in:
parent
89986f9f47
commit
bcb40db3ac
@ -1,39 +1,7 @@
|
||||
class NodeController < ApplicationController
|
||||
before_action :require_login
|
||||
|
||||
def index
|
||||
@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
|
||||
rescue => ex
|
||||
puts ex
|
||||
end
|
||||
end
|
||||
|
||||
def node_add
|
||||
|
@ -113,7 +113,44 @@ module ApplicationHelper
|
||||
return volumes
|
||||
end
|
||||
|
||||
def ssh_peer_status
|
||||
def ssh_nodes
|
||||
nodes = Array.new
|
||||
node = Hash.new
|
||||
db_nodes = Node.all.order("id asc")
|
||||
db_nodes.each do |db_node|
|
||||
node["id"] = db_node.id
|
||||
node["host_name"] = db_node.host_name
|
||||
node["host_ip"] = db_node.host_ip
|
||||
node["user_name"] = db_node.user_name
|
||||
node["user_password"] = db_node.user_password
|
||||
node["created_at"] = db_node.created_at
|
||||
node["updated_at"] = db_node.updated_at
|
||||
node["ping"] = (ping_test?(db_node.host_ip) ? "true" : "false")
|
||||
|
||||
if node["ping"].eql? "true"
|
||||
command = String.new
|
||||
command << "sshpass -p#{node["user_password"]} ssh #{node["user_name"]}@#{node["host_ip"]} gluster peer status"
|
||||
puts command
|
||||
output = `#{command}`.split("\n")
|
||||
|
||||
if output[0].include? "Number of Peers"
|
||||
node["ssh"] = "on"
|
||||
node["gluster"] = "on"
|
||||
node["number_of_peers"] = output[0].split(": ")[1]
|
||||
# put peers
|
||||
|
||||
elsif output[0].include? "check if gluster daemon is operational."
|
||||
node["ssh"] = "on"
|
||||
node["gluster"] = "off"
|
||||
else
|
||||
node["ssh"] = "off"
|
||||
node["gluster"] = "off"
|
||||
end
|
||||
end
|
||||
nodes << node
|
||||
node = Hash.new
|
||||
end
|
||||
return nodes
|
||||
end
|
||||
|
||||
def ssh_peer_probe
|
||||
|
@ -89,6 +89,7 @@
|
||||
</ul>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<% nodes = ssh_nodes %>
|
||||
<div class="x_content">
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
@ -98,27 +99,28 @@
|
||||
<th>Host Name</th>
|
||||
<th>Host IP</th>
|
||||
<th>User Name</th>
|
||||
<th>Date</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<%@nodes.each do |t|%>
|
||||
<% nodes.each do |node| %>
|
||||
<tr>
|
||||
<%if ping_test?(t.host_ip)%>
|
||||
<td><i class="fa fa-circle-o green"></i></a></td>
|
||||
<td><input type="checkbox" class="js-switch probe" value="<%=t.id%>" checked/>Attached</td>
|
||||
<%else%>
|
||||
<td><i class="fa fa-close red"></i></a></td>
|
||||
<td><input type="checkbox" class="js-switch" disabled/></td>
|
||||
<%end%>
|
||||
<th scope="row"><%=t.host_name%></th>
|
||||
<td><%=t.host_ip%></td>
|
||||
<td><%=t.user_name%></td>
|
||||
<td><%=t.created_at%></td>
|
||||
<td><a href="/node/delete/<%=t.id%>"><i class="fa fa-trash"></i></a></td>
|
||||
<% if node["ping"].eql? "true" %>
|
||||
<td><i class="fa fa-circle-o green"></i></td>
|
||||
<% else %>
|
||||
<td><i class="fa fa-close red"></i></td>
|
||||
<% end %>
|
||||
<% if node["gluster"].eql? "on" %>
|
||||
<td><i class="fa fa-circle-o green"></i>Attached</td>
|
||||
<% else %>
|
||||
<td><i class="fa fa-close red"></i>Not operational</td>
|
||||
<% end %>
|
||||
<th scope="row"><%= node["host_name"] %></th>
|
||||
<td><%= node["host_ip"] %></td>
|
||||
<td><%= node["user_name"] %></td>
|
||||
<td><a href="/node/delete/<%= node["id"] %>"><i class="fa fa-trash"></i></a></td>
|
||||
</tr>
|
||||
<%end%>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user