Add helper method for 'volumes'
This commit is contained in:
parent
595252011e
commit
37538b5112
@ -1,61 +1,14 @@
|
|||||||
class VolumeController < ApplicationController
|
class VolumeController < ApplicationController
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@volumes = Array.new
|
|
||||||
file_directory("/mnt")
|
file_directory("/mnt")
|
||||||
get_conf
|
get_conf
|
||||||
info = get_volume_info.split("\n")
|
|
||||||
if info.blank?
|
|
||||||
flash[:danger] = "Check Server"
|
|
||||||
else
|
|
||||||
parse_info(info)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def parse_info(info)
|
|
||||||
volume = Hash.new
|
|
||||||
df = get_df
|
|
||||||
info << "\n"
|
|
||||||
info.each do |t|
|
|
||||||
next if t.equal? info.first
|
|
||||||
if t.include? ":"
|
|
||||||
temp = t.split(":")
|
|
||||||
volume[temp[0]] = temp[1]
|
|
||||||
else
|
|
||||||
String state = (df.include? volume['Volume Name'].delete(' ')) ? "mounted" : "unmounted"
|
|
||||||
volume['Mount State'] = state
|
|
||||||
if state.eql? "mounted"
|
|
||||||
s = df.split("\n")
|
|
||||||
s.each do |t|
|
|
||||||
if t.include? volume['Volume Name'].delete(' ')
|
|
||||||
mnt_point = t.split(" ")[5]
|
|
||||||
volume['Mount Point'] = mnt_point
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@volumes << volume
|
|
||||||
volume = Hash.new
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_df
|
def get_df
|
||||||
return `df -P`
|
return `df -P`
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_volume_info
|
|
||||||
command = String.new
|
|
||||||
command << "sshpass -p" + @config["host_password"].to_s
|
|
||||||
command << " ssh "
|
|
||||||
if !@config["host_port"].nil?
|
|
||||||
command << "-p " + @config["host_port"].to_s + " "
|
|
||||||
end
|
|
||||||
command << @config["host_user"].to_s + "@" + @config["host_ip"].to_s
|
|
||||||
command << " gluster volume info"
|
|
||||||
puts command
|
|
||||||
return `#{command}`
|
|
||||||
end
|
|
||||||
|
|
||||||
def file_upload
|
def file_upload
|
||||||
df = get_df
|
df = get_df
|
||||||
mnt_dir = String.new
|
mnt_dir = String.new
|
||||||
|
@ -1,2 +1,71 @@
|
|||||||
module VolumeHelper
|
module VolumeHelper
|
||||||
|
|
||||||
|
def get_conf
|
||||||
|
config = Hash.new
|
||||||
|
output = `cat configure.conf`.split("\n")
|
||||||
|
output.each do |t|
|
||||||
|
if t.include? "project_path="
|
||||||
|
config["project_path"] = t.split("project_path=")[1]
|
||||||
|
elsif t.include? "server_name="
|
||||||
|
config["server_name"] = t.split("server_name=")[1]
|
||||||
|
elsif t.include? "host_user="
|
||||||
|
config["host_user"] = t.split("host_user=")[1]
|
||||||
|
elsif t.include? "host_ip="
|
||||||
|
config["host_ip"] = t.split("host_ip=")[1]
|
||||||
|
elsif t.include? "host_port=" and !t.split("host_port=")[1].nil?
|
||||||
|
config["host_port"] = t.split("host_port=")[1] + " "
|
||||||
|
elsif t.include? "host_password="
|
||||||
|
config["host_password"] = t.split("host_password=")[1]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return config
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_volumes
|
||||||
|
volumes = Array.new
|
||||||
|
volume = Hash.new
|
||||||
|
command = "df -P"
|
||||||
|
df = `#{command}`
|
||||||
|
conf = get_conf
|
||||||
|
command = "sshpass -p#{conf['host_password']} ssh #{conf['host_user']}@#{conf['host_ip']} gluster volume info"
|
||||||
|
info = `#{command}`.split("\n")
|
||||||
|
info << "\n"
|
||||||
|
info.each do |t|
|
||||||
|
next if t.equal? info.first
|
||||||
|
if t.include? ":"
|
||||||
|
temp = t.split(":")
|
||||||
|
volume[temp[0]] = temp[1]
|
||||||
|
else
|
||||||
|
String state = (df.include? volume['Volume Name'].delete(' ')) ? "mounted" : "unmounted"
|
||||||
|
volume['Mount State'] = state
|
||||||
|
if state.eql? "mounted"
|
||||||
|
s = df.split("\n")
|
||||||
|
s.each do |t|
|
||||||
|
if t.include? volume['Volume Name'].delete(' ')
|
||||||
|
mnt_point = t.split(" ")[5]
|
||||||
|
volume['Mount Point'] = mnt_point
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
volumes << volume
|
||||||
|
volume = Hash.new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return volumes
|
||||||
|
end
|
||||||
|
|
||||||
|
def volume_info(volume)
|
||||||
|
params = ['Type', 'Volume ID', 'Status', 'Number of Bricks', 'Transport-type',
|
||||||
|
'Bricks', 'Options Reconfigured', 'Mount State', 'Mount Point']
|
||||||
|
html = ''
|
||||||
|
html << "<div>"
|
||||||
|
params.each do |t|
|
||||||
|
next if volume[t].nil?
|
||||||
|
html << "<p>"
|
||||||
|
html << t + " : " + volume[t]
|
||||||
|
html << "</p>"
|
||||||
|
end
|
||||||
|
html << "</div>"
|
||||||
|
raw(html)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -115,7 +115,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<%@volumes.each do |t|%>
|
<% get_volumes.each_with_index do |t, index| %>
|
||||||
<div class="col-md-6 col-sm-6 col-xs-12">
|
<div class="col-md-6 col-sm-6 col-xs-12">
|
||||||
<div class="x_panel">
|
<div class="x_panel">
|
||||||
<div class="x_title">
|
<div class="x_title">
|
||||||
@ -123,7 +123,12 @@
|
|||||||
<h2>Infomation <small><%=t["Volume Name"]%></small></h2>
|
<h2>Infomation <small><%=t["Volume Name"]%></small></h2>
|
||||||
<!-- right title -->
|
<!-- right title -->
|
||||||
<ul class="nav navbar-right panel_toolbox">
|
<ul class="nav navbar-right panel_toolbox">
|
||||||
<li><a class="collapse-link"><i <%if t!=@volumes[0]%> class="fa fa-chevron-down" <%else%> class="fa fa-chevron-up" <%end%> ></i></a>
|
<li><a class="collapse-link">
|
||||||
|
<% if index == 0 %>
|
||||||
|
<i class="fa fa-chevron-up"></i>
|
||||||
|
<% else %>
|
||||||
|
<i class="fa fa-chevron-down"></i>
|
||||||
|
<% end %></a>
|
||||||
</li>
|
</li>
|
||||||
<li class="dropdown">
|
<li class="dropdown">
|
||||||
<a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
|
<a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
|
||||||
@ -149,7 +154,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<%if t['Status'].eql? " Stopped" %>
|
<%if t['Status'].eql? " Stopped" or t['Status'].eql? " Created" %>
|
||||||
<a><i class="fa fa-circle red"></i></a>
|
<a><i class="fa fa-circle red"></i></a>
|
||||||
<% else %>
|
<% else %>
|
||||||
<a><i class="fa fa-circle"></i></a>
|
<a><i class="fa fa-circle"></i></a>
|
||||||
@ -158,21 +163,16 @@
|
|||||||
</ul>
|
</ul>
|
||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="x_content" <%if t!=@volumes[0]%> style="display: none;" <%end%> >
|
<% if index == 0 %>
|
||||||
|
<div class="x_content">
|
||||||
|
<% else %>
|
||||||
|
<div class="x_content" style="display: none;">
|
||||||
|
<% end %>
|
||||||
<!-- left content -->
|
<!-- left content -->
|
||||||
<div class="col-md-6 col-sm-6 col-xs-12">
|
<div class="col-md-6 col-sm-6 col-xs-12">
|
||||||
<div style="margin: 10px">
|
<div style="margin: 10px">
|
||||||
<p class="text-muted font-13 m-b-30"><span class="badge bg-blue">Volume Info</span></p>
|
<p class="text-muted font-13 m-b-30"><span class="badge bg-blue">Volume Info</span></p>
|
||||||
Type : <%=t["Type"]%> <br>
|
<%= volume_info t %>
|
||||||
Volume ID : <%=t["Volume ID"]%> <br>
|
|
||||||
Status : <%=t["Status"]%> <br>
|
|
||||||
Number of Bricks : <%=t["Number of Bricks"]%> <br>
|
|
||||||
Transport-type : <%=t["Transport-type"]%> <br>
|
|
||||||
Bricks : <%=t["Bricks"]%> <br>
|
|
||||||
Bricks1 : <%=t["Brick1"]%> <br>
|
|
||||||
Options Reconfigured : <%=t["Options Reconfigured"]%> <br>
|
|
||||||
performance.readdir-ahead : <%=t["performance.readdir-ahead"]%> <br>
|
|
||||||
mount state: <%=t["Mount State"]%> <br>
|
|
||||||
</div>
|
</div>
|
||||||
<% if t["Mount State"] == "mounted" %>
|
<% if t["Mount State"] == "mounted" %>
|
||||||
<a class="btn btn-app" href="/volume/unmount/<%=t['Volume Name'].delete(' ')%>"><i class="fa fa-upload"></i> Unmount</a>
|
<a class="btn btn-app" href="/volume/unmount/<%=t['Volume Name'].delete(' ')%>"><i class="fa fa-upload"></i> Unmount</a>
|
||||||
@ -292,7 +292,7 @@
|
|||||||
alert("Volume name can't contains white spaces");
|
alert("Volume name can't contains white spaces");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
<% @volumes.each do |t| %>
|
<% get_volumes.each do |t| %>
|
||||||
if(volume_name == "<%=t["Volume Name"].delete(' ')%>"){
|
if(volume_name == "<%=t["Volume Name"].delete(' ')%>"){
|
||||||
alert("Already has a volume which name is same");
|
alert("Already has a volume which name is same");
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user