gluster-web-interface/app/helpers/volume_helper.rb

48 lines
1.5 KiB
Ruby
Raw Normal View History

2016-08-22 09:41:25 +00:00
module VolumeHelper
2016-09-20 12:13:24 +00:00
2016-09-23 09:28:53 +00:00
def volumes
2016-09-20 12:13:24 +00:00
volumes = Array.new
volume = Hash.new
conf = get_conf
2016-09-23 09:28:53 +00:00
df = get_df
command = String.new
command << "sshpass -p#{conf['user_password']} "
command << "ssh #{conf['user_name']}@#{conf['host_ip']} "
command << "gluster volume info"
puts command
output = `#{command}`.split("\n")
output << "\n"
output.each do |t|
next if t.equal? output.first
2016-09-20 12:13:24 +00:00
if t.include? ":"
temp = t.split(":")
volume[temp[0]] = temp[1]
else
2016-09-23 09:28:53 +00:00
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']
2016-09-20 12:13:24 +00:00
end
volumes << volume
volume = Hash.new
end
end
return volumes
end
def volume_info(volume)
2016-09-23 09:28:53 +00:00
params = ['Type', 'Volume ID', 'Status', 'Number of Bricks', 'Transport-type', 'Bricks', 'Options Reconfigured', 'Mount State', 'Mount Point']
2016-09-20 12:13:24 +00:00
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
2016-08-22 09:41:25 +00:00
end