2016-04-25 00:47:31 +00:00
|
|
|
module ApplicationHelper
|
2016-09-23 09:28:53 +00:00
|
|
|
|
|
|
|
def get_df
|
|
|
|
df = Array.new
|
|
|
|
df_each = Hash.new
|
|
|
|
command = String.new
|
|
|
|
command << "df -hP"
|
|
|
|
puts command
|
|
|
|
output = `#{command}`.split("\n")
|
|
|
|
output.each do |t|
|
|
|
|
next if t.equal? output.first
|
2016-09-26 09:06:53 +00:00
|
|
|
begin
|
|
|
|
s = t.split(' ')
|
|
|
|
df_each['Filesystem'] = s[0]
|
|
|
|
df_each['Size'] = s[1]
|
|
|
|
df_each['Used'] = s[2]
|
|
|
|
df_each['Avail'] = s[3]
|
|
|
|
df_each['Use%'] = s[4]
|
|
|
|
df_each['Mounted on'] = s[5]
|
|
|
|
df << df_each
|
|
|
|
df_each = Hash.new
|
|
|
|
rescue => ex
|
|
|
|
puts ex
|
|
|
|
end
|
2016-09-23 09:28:53 +00:00
|
|
|
end
|
|
|
|
return df
|
|
|
|
end
|
|
|
|
|
2016-09-24 09:00:27 +00:00
|
|
|
def volumes
|
|
|
|
volumes = Array.new
|
|
|
|
volume = Hash.new
|
2016-09-24 10:31:27 +00:00
|
|
|
node = Node.take
|
2016-09-24 09:00:27 +00:00
|
|
|
df = get_df
|
2016-09-26 08:10:11 +00:00
|
|
|
# error check : node is nil
|
|
|
|
if node.nil?
|
|
|
|
return volumes
|
|
|
|
end
|
2016-09-24 09:00:27 +00:00
|
|
|
command = String.new
|
2016-09-24 10:31:27 +00:00
|
|
|
command << "sshpass -p#{node.user_password} ssh #{node.user_name}@#{node.host_ip} gluster volume info"
|
2016-09-24 09:00:27 +00:00
|
|
|
puts command
|
|
|
|
output = `#{command}`.split("\n")
|
|
|
|
output << "\n"
|
|
|
|
output.each do |t|
|
|
|
|
next if t.equal? output.first
|
|
|
|
if t.include? ":"
|
|
|
|
temp = t.split(":")
|
|
|
|
volume[temp[0]] = temp[1]
|
|
|
|
else
|
|
|
|
volume['Mount State'] = "unmounted"
|
|
|
|
df.each do |u|
|
|
|
|
next if !u['Filesystem'].include? volume['Volume Name'].delete(' ')
|
|
|
|
volume['Mount State'] = "mounted"
|
|
|
|
volume['Mount Point'] = u['Mounted on']
|
|
|
|
end
|
|
|
|
volumes << volume
|
|
|
|
volume = Hash.new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return volumes
|
|
|
|
end
|
2016-09-24 10:31:27 +00:00
|
|
|
|
2016-09-24 16:24:28 +00:00
|
|
|
def files(dir)
|
|
|
|
files = Array.new
|
|
|
|
file = Hash.new
|
2016-09-26 09:06:53 +00:00
|
|
|
command = String.new
|
|
|
|
command << "ls #{dir} -l"
|
|
|
|
puts command
|
|
|
|
output = `#{command}`.split("\n")
|
2016-09-24 16:24:28 +00:00
|
|
|
output.each do |t|
|
|
|
|
next if t.equal? output.first
|
2016-09-26 09:06:53 +00:00
|
|
|
begin
|
|
|
|
s = t.split(" ")
|
|
|
|
file["auth"] = s[0]
|
|
|
|
file["size"] = s[4]
|
|
|
|
file["date"] = s[5] + " " + s[6] + " " + s[7]
|
|
|
|
file["name"] = s[8]
|
|
|
|
files << file
|
|
|
|
file = Hash.new
|
|
|
|
rescue => ex
|
|
|
|
puts ex
|
|
|
|
end
|
2016-09-24 16:24:28 +00:00
|
|
|
end
|
|
|
|
return files
|
|
|
|
end
|
|
|
|
|
2016-09-26 10:11:13 +00:00
|
|
|
def file_manager_table(dir = "/mnt", id = "datatable", class_option = "table table-striped table-bordered jambo_table")
|
|
|
|
html = String.new
|
2016-09-26 16:53:09 +00:00
|
|
|
html << "<table id='#{id}' class='#{class_option}'>"
|
2016-09-26 10:11:13 +00:00
|
|
|
html << "<thead>"
|
|
|
|
html << "<tr class='headings'>"
|
|
|
|
html << "<th>Name</th>"
|
|
|
|
html << "<th>auth</th>"
|
|
|
|
html << "<th>Size</th>"
|
|
|
|
html << "<th>Date</th>"
|
|
|
|
html << "</tr>"
|
|
|
|
html << "</thead>"
|
2016-09-26 16:53:09 +00:00
|
|
|
html << "<tbody id='#{id}_body'>"
|
2016-09-26 10:11:13 +00:00
|
|
|
html << "<tr>"
|
|
|
|
html << "<td>"
|
2016-09-26 16:53:09 +00:00
|
|
|
html << "<a class='chupper' style='cursor: pointer'><i class='fa fa-reply'></i></a>"
|
|
|
|
html << "<span style='line-height:0'> #{dir}</span>"
|
2016-09-26 10:11:13 +00:00
|
|
|
html << "<a class='pull-right' href='#popup_mkdir'><i class='fa fa-plus'></i><i class='fa fa-folder'></i></a>"
|
|
|
|
html << "</td>"
|
|
|
|
html << "<td></td>"
|
|
|
|
html << "<td></td>"
|
|
|
|
html << "<td></td>"
|
|
|
|
html << "</tr>"
|
|
|
|
|
|
|
|
files(dir).each do |file|
|
|
|
|
html << "<tr class='dir_delete'>"
|
|
|
|
if file["auth"][0]=='d'
|
|
|
|
html << "<td style='color:#0d8ade;'><i class='fa fa-folder-open-o'></i>"
|
2016-09-26 16:53:09 +00:00
|
|
|
html << "<a class='chdir' style='cursor: pointer'> #{file['name']}</a>"
|
2016-09-26 10:11:13 +00:00
|
|
|
html << "</td>"
|
|
|
|
else
|
2016-09-26 16:53:09 +00:00
|
|
|
conv_name = (dir + '/' + file['name']).gsub("/", "+")
|
2016-09-26 10:11:13 +00:00
|
|
|
html << "<td><i class='fa fa-file-o'></i>"
|
2016-09-26 16:53:09 +00:00
|
|
|
html << "<a href='/file_download?file_name=#{conv_name}'> #{file['name']}</a>"
|
2016-09-26 10:11:13 +00:00
|
|
|
html << "</td>"
|
|
|
|
end
|
2016-09-26 16:53:09 +00:00
|
|
|
html << "<td>#{file['auth']}</td>"
|
|
|
|
html << "<td>#{file['size']}</td>"
|
|
|
|
html << "<td>#{file["date"]}"
|
|
|
|
html << "<a class='pull-right rmdir' href='#'><i class='fa fa-trash'></i></a>"
|
2016-09-26 10:11:13 +00:00
|
|
|
html << "</td>"
|
|
|
|
html << "</tr>"
|
|
|
|
end
|
|
|
|
|
|
|
|
html << "</tbody>"
|
|
|
|
html << "</table>"
|
2016-09-26 16:53:09 +00:00
|
|
|
return raw html
|
2016-09-26 10:11:13 +00:00
|
|
|
end
|
2016-04-25 00:47:31 +00:00
|
|
|
end
|