2016-08-22 09:41:25 +00:00
|
|
|
class VolumeController < ApplicationController
|
2016-09-03 10:54:41 +00:00
|
|
|
|
2016-09-11 10:57:07 +00:00
|
|
|
def index
|
|
|
|
file_directory("/mnt")
|
|
|
|
get_conf
|
|
|
|
info = get_volume_info.split("\n")
|
|
|
|
if info.blank?
|
|
|
|
flash[:danger] = "Check Server"
|
|
|
|
else
|
|
|
|
parse_info(info)
|
|
|
|
end
|
2016-09-03 10:54:41 +00:00
|
|
|
end
|
2016-09-11 10:57:07 +00:00
|
|
|
|
|
|
|
def parse_info(info)
|
|
|
|
@volumes = Array.new
|
2016-09-03 10:54:41 +00:00
|
|
|
volume = Hash.new
|
2016-09-11 10:57:07 +00:00
|
|
|
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
|
|
|
|
@volumes << volume
|
|
|
|
volume = Hash.new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_df
|
|
|
|
return `df -P`
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_volume_info
|
|
|
|
return `sshpass -p#{@config["host_password"]} ssh #{@config["host_port"]} #{@config["host_user"]}@#{@config["host_ip"]} \
|
|
|
|
gluster volume info`
|
|
|
|
end
|
|
|
|
|
|
|
|
def file_upload
|
|
|
|
file_name = params[:file]
|
|
|
|
uploader = AvatarUploader.new
|
|
|
|
uploader.store!(file_name)
|
|
|
|
redirect_to '/volume/info'
|
|
|
|
end
|
|
|
|
|
|
|
|
def volume_mount
|
|
|
|
@config = get_conf
|
|
|
|
volume_name = params[:volume_name]
|
|
|
|
mount_point = params[:mount_point]
|
|
|
|
puts "mount -t glusterfs " + @config["host_ip"] + ":/" + volume_name + " " + mount_point
|
|
|
|
`mount -t glusterfs #{@config["host_ip"]}:/#{volume_name} #{mount_point}`
|
|
|
|
redirect_to '/volume/index'
|
|
|
|
end
|
|
|
|
|
|
|
|
def volume_unmount
|
|
|
|
@config = get_conf
|
|
|
|
volume_name = params[:volume_name]
|
|
|
|
puts "umount " + @config["host_ip"] + ":/" + volume_name
|
|
|
|
`umount #{@config["host_ip"]}:/#{volume_name}`
|
|
|
|
redirect_to '/volume/index'
|
|
|
|
end
|
|
|
|
|
|
|
|
def volume_create
|
2016-09-11 16:46:58 +00:00
|
|
|
@config = get_conf
|
2016-09-11 10:57:07 +00:00
|
|
|
volume_name = params[:volume_name]
|
2016-09-11 16:46:58 +00:00
|
|
|
volume_type = params[:volume_type]
|
|
|
|
num_of_brick = params[:num_of_brick]
|
2016-09-11 10:57:07 +00:00
|
|
|
bricks = params[:bricks]
|
2016-09-11 16:46:58 +00:00
|
|
|
command = String.new
|
|
|
|
command << "sshpass"
|
|
|
|
command << " -p"
|
|
|
|
command << @config["host_password"].to_s
|
|
|
|
command << " ssh "
|
|
|
|
command << @config["host_port"].to_s
|
|
|
|
command << " "
|
|
|
|
command << @config["host_user"].to_s
|
|
|
|
command << "@"
|
|
|
|
command << @config["host_ip"].to_s
|
|
|
|
command << " gluster volume create "
|
|
|
|
command << volume_name + " "
|
|
|
|
if !volume_type.include? "Distribute"
|
|
|
|
command << volume_type + " " + num_of_brick + " "
|
|
|
|
end
|
2016-09-11 10:57:07 +00:00
|
|
|
bricks.each do |t|
|
2016-09-11 16:46:58 +00:00
|
|
|
command << t
|
|
|
|
command << " "
|
2016-09-11 10:57:07 +00:00
|
|
|
end
|
2016-09-11 16:46:58 +00:00
|
|
|
command << "force"
|
|
|
|
puts command
|
|
|
|
`#{command}`
|
2016-09-11 10:57:07 +00:00
|
|
|
redirect_to '/volume/index'
|
2016-08-20 12:02:16 +00:00
|
|
|
end
|
2016-08-20 09:31:55 +00:00
|
|
|
|
2016-09-11 10:57:07 +00:00
|
|
|
def volume_stop
|
|
|
|
@config = get_conf
|
|
|
|
volume_name = params[:volume_name]
|
|
|
|
puts "gluster volume stop " + volume_name
|
|
|
|
`yes | sshpass -p#{@config["host_password"]} ssh #{@config["host_port"]} #{@config["host_user"]}@#{@config["host_ip"]} \
|
|
|
|
gluster volume stop #{volume_name}`
|
|
|
|
redirect_to '/volume/index'
|
|
|
|
end
|
2016-08-28 08:36:02 +00:00
|
|
|
|
2016-09-11 10:57:07 +00:00
|
|
|
def volume_start
|
|
|
|
@config = get_conf
|
|
|
|
volume_name = params[:volume_name]
|
|
|
|
puts "gluster volume start " + volume_name
|
|
|
|
`sshpass -p#{@config["host_password"]} ssh #{@config["host_port"]} #{@config["host_user"]}@#{@config["host_ip"]} \
|
|
|
|
gluster volume start #{volume_name}`
|
|
|
|
redirect_to '/volume/index'
|
|
|
|
end
|
2016-08-31 13:34:09 +00:00
|
|
|
|
|
|
|
|
2016-09-11 10:57:07 +00:00
|
|
|
def volume_delete
|
|
|
|
@config = get_conf
|
|
|
|
volume_name = params[:volume_name]
|
|
|
|
puts "gluster volume delete " + volume_name
|
|
|
|
`yes | sshpass -p#{@config["host_password"]} ssh #{@config["host_port"]} #{@config["host_user"]}@#{@config["host_ip"]} \
|
|
|
|
gluster volume delete #{volume_name}`
|
|
|
|
redirect_to '/volume/index'
|
|
|
|
end
|
2016-08-20 06:58:04 +00:00
|
|
|
end
|