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
|
2016-09-12 08:33:08 +00:00
|
|
|
String state = (df.include? volume['Volume Name'].delete(' ')) ? "mounted" : "unmounted"
|
2016-09-11 10:57:07 +00:00
|
|
|
volume['Mount State'] = state
|
2016-09-15 06:05:40 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2016-09-11 10:57:07 +00:00
|
|
|
@volumes << volume
|
|
|
|
volume = Hash.new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_df
|
|
|
|
return `df -P`
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_volume_info
|
2016-09-12 08:33:08 +00:00
|
|
|
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}`
|
2016-09-11 10:57:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def file_upload
|
2016-09-15 06:05:40 +00:00
|
|
|
df = get_df
|
|
|
|
mnt_dir = String.new
|
|
|
|
mnt_dest = String.new
|
|
|
|
file = params[:file]
|
|
|
|
s = df.split("\n")
|
|
|
|
s.each do |t|
|
|
|
|
if t.include? params[:volume_name]
|
|
|
|
mnt_dir = t.split(" ")[5]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
mnt_dest = mnt_dir + "/" + file.original_filename
|
|
|
|
|
|
|
|
puts "upload start"
|
2016-09-15 08:57:20 +00:00
|
|
|
# get permission
|
|
|
|
# dir_left = mnt_dir[0..mnt_dir.rindex('/')]
|
|
|
|
# dir_right = mnt_dir.split(dir_left)[1]
|
|
|
|
# pe = `ls -al #{dir_left} | grep #{dir_right}`.split(" ")[0]
|
|
|
|
|
|
|
|
# puts "111" + dir_left
|
|
|
|
# puts "222" + dir_right
|
|
|
|
# puts "333" + pe
|
|
|
|
|
|
|
|
u = AvatarUploader.new(mnt_dir)
|
2016-09-15 06:05:40 +00:00
|
|
|
u.store!(file)
|
|
|
|
puts "upload end"
|
|
|
|
|
|
|
|
redirect_to '/volume/index'
|
2016-09-11 10:57:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def volume_mount
|
2016-09-12 08:33:08 +00:00
|
|
|
get_conf
|
2016-09-11 10:57:07 +00:00
|
|
|
volume_name = params[:volume_name]
|
|
|
|
mount_point = params[:mount_point]
|
2016-09-12 08:33:08 +00:00
|
|
|
# make command string
|
|
|
|
command = String.new
|
2016-09-14 02:52:04 +00:00
|
|
|
command << "sudo mount -t glusterfs " + @config["host_ip"].to_s + ":/" + volume_name + " " + mount_point
|
2016-09-12 08:33:08 +00:00
|
|
|
puts command
|
|
|
|
`#{command}`
|
2016-09-11 10:57:07 +00:00
|
|
|
redirect_to '/volume/index'
|
|
|
|
end
|
|
|
|
|
|
|
|
def volume_unmount
|
2016-09-12 08:33:08 +00:00
|
|
|
get_conf
|
2016-09-11 10:57:07 +00:00
|
|
|
volume_name = params[:volume_name]
|
2016-09-12 08:33:08 +00:00
|
|
|
# make command string
|
|
|
|
command = String.new
|
2016-09-14 02:52:04 +00:00
|
|
|
command << "sudo umount " + @config["host_ip"].to_s + ":/" + volume_name
|
2016-09-12 08:33:08 +00:00
|
|
|
puts command
|
|
|
|
`#{command}`
|
2016-09-11 10:57:07 +00:00
|
|
|
redirect_to '/volume/index'
|
|
|
|
end
|
|
|
|
|
|
|
|
def volume_create
|
2016-09-12 08:33:08 +00:00
|
|
|
get_conf
|
2016-09-11 10:57:07 +00:00
|
|
|
volume_name = params[:volume_name]
|
2016-09-12 08:33:08 +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-12 08:33:08 +00:00
|
|
|
# make command string
|
|
|
|
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 create " + volume_name + " "
|
2016-09-14 02:52:04 +00:00
|
|
|
if !volume_type.include? "Distribute"
|
2016-09-12 08:33:08 +00:00
|
|
|
command << volume_type.downcase + " " + num_of_brick + " "
|
|
|
|
end
|
2016-09-11 10:57:07 +00:00
|
|
|
bricks.each do |t|
|
2016-09-12 08:33:08 +00:00
|
|
|
command << t + " "
|
2016-09-11 10:57:07 +00:00
|
|
|
end
|
2016-09-12 08:33:08 +00:00
|
|
|
command << "force"
|
2016-09-11 16:46:58 +00:00
|
|
|
puts command
|
|
|
|
`#{command}`
|
2016-09-14 07:23:13 +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
|
2016-09-12 08:33:08 +00:00
|
|
|
get_conf
|
2016-09-11 10:57:07 +00:00
|
|
|
volume_name = params[:volume_name]
|
2016-09-12 08:33:08 +00:00
|
|
|
# make command string
|
|
|
|
command = String.new
|
|
|
|
command << "yes | 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 stop " + volume_name
|
|
|
|
puts command
|
|
|
|
`#{command}`
|
2016-09-11 10:57:07 +00:00
|
|
|
redirect_to '/volume/index'
|
|
|
|
end
|
2016-08-28 08:36:02 +00:00
|
|
|
|
2016-09-11 10:57:07 +00:00
|
|
|
def volume_start
|
2016-09-12 08:33:08 +00:00
|
|
|
get_conf
|
2016-09-11 10:57:07 +00:00
|
|
|
volume_name = params[:volume_name]
|
2016-09-12 08:33:08 +00:00
|
|
|
# make command string
|
|
|
|
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
|
2016-09-14 07:23:13 +00:00
|
|
|
command << " gluster volume start " + volume_name.to_s
|
2016-09-12 08:33:08 +00:00
|
|
|
puts command
|
|
|
|
`#{command}`
|
2016-09-11 10:57:07 +00:00
|
|
|
redirect_to '/volume/index'
|
|
|
|
end
|
2016-08-31 13:34:09 +00:00
|
|
|
|
2016-09-11 10:57:07 +00:00
|
|
|
def volume_delete
|
2016-09-12 08:33:08 +00:00
|
|
|
get_conf
|
2016-09-11 10:57:07 +00:00
|
|
|
volume_name = params[:volume_name]
|
2016-09-12 08:33:08 +00:00
|
|
|
# make command string
|
|
|
|
command = String.new
|
|
|
|
command << "yes | 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 delete " + volume_name
|
|
|
|
puts command
|
|
|
|
`#{command}`
|
2016-09-11 10:57:07 +00:00
|
|
|
redirect_to '/volume/index'
|
|
|
|
end
|
2016-08-20 06:58:04 +00:00
|
|
|
end
|