Add ssh_nodes
This commit is contained in:
parent
89986f9f47
commit
bcb40db3ac
@ -1,39 +1,7 @@
|
|||||||
class NodeController < ApplicationController
|
class NodeController < ApplicationController
|
||||||
before_action :require_login
|
before_action :require_login
|
||||||
|
|
||||||
def index
|
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
|
end
|
||||||
|
|
||||||
def node_add
|
def node_add
|
||||||
|
@ -113,7 +113,44 @@ module ApplicationHelper
|
|||||||
return volumes
|
return volumes
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
def ssh_peer_probe
|
def ssh_peer_probe
|
||||||
|
@ -89,6 +89,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
</div>
|
</div>
|
||||||
|
<% nodes = ssh_nodes %>
|
||||||
<div class="x_content">
|
<div class="x_content">
|
||||||
<table class="table table-hover">
|
<table class="table table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
@ -98,27 +99,28 @@
|
|||||||
<th>Host Name</th>
|
<th>Host Name</th>
|
||||||
<th>Host IP</th>
|
<th>Host IP</th>
|
||||||
<th>User Name</th>
|
<th>User Name</th>
|
||||||
<th>Date</th>
|
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<%@nodes.each do |t|%>
|
<% nodes.each do |node| %>
|
||||||
<tr>
|
<tr>
|
||||||
<%if ping_test?(t.host_ip)%>
|
<% if node["ping"].eql? "true" %>
|
||||||
<td><i class="fa fa-circle-o green"></i></a></td>
|
<td><i class="fa fa-circle-o green"></i></td>
|
||||||
<td><input type="checkbox" class="js-switch probe" value="<%=t.id%>" checked/>Attached</td>
|
<% else %>
|
||||||
<%else%>
|
<td><i class="fa fa-close red"></i></td>
|
||||||
<td><i class="fa fa-close red"></i></a></td>
|
<% end %>
|
||||||
<td><input type="checkbox" class="js-switch" disabled/></td>
|
<% if node["gluster"].eql? "on" %>
|
||||||
<%end%>
|
<td><i class="fa fa-circle-o green"></i>Attached</td>
|
||||||
<th scope="row"><%=t.host_name%></th>
|
<% else %>
|
||||||
<td><%=t.host_ip%></td>
|
<td><i class="fa fa-close red"></i>Not operational</td>
|
||||||
<td><%=t.user_name%></td>
|
<% end %>
|
||||||
<td><%=t.created_at%></td>
|
<th scope="row"><%= node["host_name"] %></th>
|
||||||
<td><a href="/node/delete/<%=t.id%>"><i class="fa fa-trash"></i></a></td>
|
<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>
|
</tr>
|
||||||
<%end%>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user