Update and fix volume controller

This commit is contained in:
Youngkyun Kim 2016-09-03 10:54:41 +00:00
parent 54977ac9a1
commit 0ec7d042f2

View File

@ -1,22 +1,27 @@
class VolumeController < ApplicationController class VolumeController < ApplicationController
def index def index
@config = get_conf
@volumes = Array.new
volume = Hash.new
file_directory("/mnt") file_directory("/mnt")
get_conf
info = get_info.split("\n")
if get_info.blank? if info.blank?
flash[:danger] = "Check Server" flash[:danger] = "Check Server"
else else
info = get_info.split("\n") parse_info(info)
df = get_df end
puts df end
for t in 1..(info.length-1) def parse_info(info)
if info[t].include? ":" @volumes = Array.new
temp = info[t].split(":") volume = Hash.new
df = get_df
info.each do |t|
next if t.equal? info.first
if t.include? ":"
temp = t.split(":")
volume[temp[0]] = temp[1] volume[temp[0]] = temp[1]
else else
if df.include? volume['Volume Name'].delete(' ') if df.include? volume['Volume Name'].delete(' ')
@ -31,17 +36,14 @@ class VolumeController < ApplicationController
end end
end end
@volumes << volume @volumes << volume
# puts @volumes
end
end end
def get_df def get_df
@config = get_conf
return `df -P` return `df -P`
end end
def get_info def get_info
@config = get_conf
return `sshpass -p#{@config["host_password"]} ssh #{@config["host_port"]} #{@config["host_user"]}@#{@config["host_ip"]} gluster volume info` return `sshpass -p#{@config["host_password"]} ssh #{@config["host_port"]} #{@config["host_user"]}@#{@config["host_ip"]} gluster volume info`
end end
@ -52,16 +54,13 @@ class VolumeController < ApplicationController
redirect_to '/volume/info' redirect_to '/volume/info'
end end
def volume_mount def volume_mount
@config = get_conf @config = get_conf
volume_name = params[:volume_name] volume_name = params[:volume_name]
mount_point = params[:mount_point] mount_point = params[:mount_point]
volume_name = volume_name.delete(' ') volume_name = volume_name.delete(' ')
puts "mount -t glusterfs " + @config["host_ip"] + ":/" + volume_name + " " + mount_point puts "mount -t glusterfs " + @config["host_ip"] + ":/" + volume_name + " " + mount_point
`mount -t glusterfs #{@config["host_ip"]}:/#{volume_name} #{mount_point}` `mount -t glusterfs #{@config["host_ip"]}:/#{volume_name} #{mount_point}`
redirect_to '/volume/index' redirect_to '/volume/index'
end end