2016-08-22 09:41:25 +00:00
|
|
|
class VolumeController < ApplicationController
|
2016-09-23 12:53:19 +00:00
|
|
|
before_action :require_login
|
2016-09-03 10:54:41 +00:00
|
|
|
|
2016-09-11 10:57:07 +00:00
|
|
|
def index
|
|
|
|
file_directory("/mnt")
|
|
|
|
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]
|
2016-09-23 09:28:53 +00:00
|
|
|
df.each do |t|
|
|
|
|
if t['Filesystem'].include? params[:volume_name]
|
|
|
|
mnt_dir = t['Mounted on']
|
2016-09-15 06:05:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
mnt_dest = mnt_dir + "/" + file.original_filename
|
2016-09-15 09:58:19 +00:00
|
|
|
# change permission
|
|
|
|
command = String.new
|
2016-09-23 09:28:53 +00:00
|
|
|
command << "sudo chmod 777 #{mnt_dir}"
|
2016-09-15 09:58:19 +00:00
|
|
|
puts command
|
|
|
|
`#{command}`
|
2016-09-23 09:28:53 +00:00
|
|
|
# upload file
|
2016-09-15 08:57:20 +00:00
|
|
|
u = AvatarUploader.new(mnt_dir)
|
2016-09-15 06:05:40 +00:00
|
|
|
u.store!(file)
|
|
|
|
redirect_to '/volume/index'
|
2016-09-11 10:57:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def volume_mount
|
2016-09-23 09:28:53 +00:00
|
|
|
conf = 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-23 09:28:53 +00:00
|
|
|
command << "sudo mount -t glusterfs #{conf['host_ip']}:/#{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-23 09:28:53 +00:00
|
|
|
conf = 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-23 09:28:53 +00:00
|
|
|
command << "sudo umount #{conf['host_ip']}:/#{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-23 09:28:53 +00:00
|
|
|
conf = 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
|
2016-09-23 09:28:53 +00:00
|
|
|
command << "sshpass -p#{conf['user_password']} "
|
|
|
|
command << "ssh #{conf['user_name']}@#{conf['host_ip']} "
|
|
|
|
command << "gluster volume create #{volume_name} "
|
2016-09-14 02:52:04 +00:00
|
|
|
if !volume_type.include? "Distribute"
|
2016-09-23 09:28:53 +00:00
|
|
|
command << "#{volume_type.downcase} #{num_of_brick}"
|
2016-09-12 08:33:08 +00:00
|
|
|
end
|
2016-09-23 09:28:53 +00:00
|
|
|
conf_all = get_conf_all
|
2016-09-11 10:57:07 +00:00
|
|
|
bricks.each do |t|
|
2016-09-23 09:28:53 +00:00
|
|
|
host_name = t.split(":/")[0]
|
|
|
|
brick_name = t.split(":/")[1]
|
|
|
|
host_ip = ""
|
|
|
|
conf_all.each do |u|
|
|
|
|
next if !u['host_name'].eql? host_name
|
|
|
|
host_ip = u['host_ip']
|
|
|
|
end
|
|
|
|
brick = "#{host_ip}:/#{brick_name}"
|
|
|
|
command << "#{brick} "
|
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-23 09:28:53 +00:00
|
|
|
conf = 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-23 09:28:53 +00:00
|
|
|
command << "yes | sshpass -p#{conf['user_password']} "
|
|
|
|
command << "ssh #{conf['user_name']}@#{conf['host_ip']} "
|
|
|
|
command << "gluster volume stop #{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
|
2016-08-28 08:36:02 +00:00
|
|
|
|
2016-09-11 10:57:07 +00:00
|
|
|
def volume_start
|
2016-09-23 09:28:53 +00:00
|
|
|
conf = 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-23 09:28:53 +00:00
|
|
|
command << "sshpass -p#{conf['user_password']} "
|
|
|
|
command << "ssh #{conf['user_name']}@#{conf['host_ip']} "
|
|
|
|
command << " gluster volume start #{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
|
2016-08-31 13:34:09 +00:00
|
|
|
|
2016-09-11 10:57:07 +00:00
|
|
|
def volume_delete
|
2016-09-23 09:28:53 +00:00
|
|
|
conf = 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-23 09:28:53 +00:00
|
|
|
command << "yes | sshpass -p#{conf['user_password']} "
|
|
|
|
command << "ssh #{conf['user_name']}@#{conf['host_ip']} "
|
|
|
|
command << " gluster volume delete #{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
|
2016-08-20 06:58:04 +00:00
|
|
|
end
|