gluster-web-interface/app/controllers/volume_controller.rb

224 lines
6.3 KiB
Ruby
Raw Normal View History

2016-08-22 09:41:25 +00:00
class VolumeController < ApplicationController
2016-08-27 13:21:08 +00:00
helper_method :file_directory
def index
@conf_list = get_conf
2016-09-01 09:29:00 +00:00
#project_path = String.new
#@conf_list.each do |t|
# if t.include? "project_path="
# project_path = t.split("project_path=")[1]
# end
#end
#file_directory(project_path)
2016-09-01 09:29:00 +00:00
puts @config_list["project_path"]
puts @config_list["server_name"]
puts @config_list["host_user"]
puts @config_list["host_ip"]
puts @config_list["host_port"]
puts @config_list["host_password"]
file_directory(@config_list["project_path"])
2016-08-20 12:02:16 +00:00
@volumes = Array.new
volume = Hash.new
2016-08-22 08:07:57 +00:00
if get_info.blank?
flash[:danger] = "Check Server"
else
output = get_info.split("\n")
for t in 1..(output.length-1)
if output[t].include? ":"
temp = output[t].split(":")
volume[temp[0]] = temp[1]
else
@volumes << volume
2016-08-22 08:07:57 +00:00
volume = Hash.new
end
end
@volumes << volume
2016-08-22 08:07:57 +00:00
puts @volumes
2016-08-20 12:02:16 +00:00
end
2016-08-20 09:31:55 +00:00
end
def get_conf
2016-09-01 09:14:39 +00:00
@config = Hash.new
host_user = "root"
host_ip = "127.0.0.1"
host_password = "secret"
host_port = ""
output = `cat configure.conf`.split("\n")
output.each do |t|
2016-09-01 09:25:28 +00:00
if t.include? "project_path="
2016-09-01 09:29:00 +00:00
@config["project_path"] = t.split("project_path=")[1]
elsif t.include? "server_name="
@config["server_name"] = t.split("server_name=")[1]
2016-09-01 09:25:28 +00:00
elsif t.include? "host_user="
2016-09-01 09:14:39 +00:00
@config["host_user"] = t.split("host_user=")[1]
elsif t.include? "host_ip="
@config["host_ip"] = t.split("host_ip=")[1]
elsif t.include? "host_port=" and !t.split("host_port=")[1].nil?
@config["host_port"] = "-p " + t.split("host_port=")[1] + " "
elsif t.include? "host_password="
@config["host_password"] = t.split("host_password=")[1]
end
end
2016-09-01 09:29:00 +00:00
return @config
#return `cat configure.conf`.split("\n")
end
2016-08-20 09:31:55 +00:00
def get_info
host_user = "root"
host_ip = "127.0.0.1"
host_password = "secret"
host_port = ""
@conf_list.each do |t|
if t.include? "host_name="
host_user = t.split("host_user=")[1]
elsif t.include? "host_ip="
host_ip = t.split("host_ip=")[1]
elsif t.include? "host_port=" and !t.split("host_port=")[1].nil?
host_port = "-p " + t.split("host_port=")[1] + " "
elsif t.include? "host_password="
host_password = t.split("host_password=")[1]
end
end
return `sshpass -p#{host_password} ssh #{host_port} #{host_user}@#{host_ip} gluster volume info`
2016-08-20 06:58:04 +00:00
end
2016-08-20 09:37:05 +00:00
2016-08-22 09:41:25 +00:00
def file_upload
file_name = params[:file]
uploader = AvatarUploader.new
uploader.store!(file_name)
redirect_to '/volume/info'
end
2016-08-25 10:22:48 +00:00
2016-08-27 13:21:08 +00:00
def file_directory(dir)
@current_dir = dir
dir_list = `ls #{@current_dir} -l`
parsing_list = dir_list.split("\n")
@files = Array.new
2016-08-27 12:14:35 +00:00
file = Hash.new
2016-08-27 13:21:08 +00:00
@total_list = parsing_list[0]
for t in 1..(parsing_list.length-1)
parsing_file = parsing_list[t].split(" ")
file["auth"] = parsing_file[0]
file["size"] = parsing_file[4]
file["date"] = parsing_file[5] + " " + parsing_file[6] + " " + parsing_file[7]
2016-08-27 13:21:08 +00:00
file["name"] = parsing_file[8]
@files << file
2016-08-27 13:21:08 +00:00
file = Hash.new
end
puts @files
2016-08-27 13:23:33 +00:00
return @files
2016-08-27 13:21:08 +00:00
end
def checkDir
2016-08-27 13:23:33 +00:00
files = file_directory(params[:path])
render :json => {:file => files , :current => @current_dir}
2016-08-25 10:22:48 +00:00
end
2016-08-31 12:29:16 +00:00
2016-08-31 14:42:14 +00:00
def volume_mount
2016-08-31 13:34:09 +00:00
conf_list = get_conf
host_ip = String.new
2016-08-31 14:42:14 +00:00
conf_list.each do |t|
if t.include? "host_ip="
host_ip = t.split("host_ip=")[1]
end
end
volume_name = params[:volume_name]
volume_name = volume_name.delete(' ')
puts "mount -t glusterfs " + host_ip + ":/" + volume_name + " /mnt/glusterfs"
2016-08-31 13:34:09 +00:00
redirect_to '/volume/index'
end
def volume_stop
2016-08-31 14:42:14 +00:00
volume_name = params[:volume_name]
volume_name = volume_name.delete(' ')
2016-08-31 15:21:17 +00:00
host_user = "root"
host_ip = "127.0.0.1"
host_password = "secret"
host_port = ""
@conf_list.each do |t|
if t.include? "host_name="
host_user = t.split("host_user=")[1]
elsif t.include? "host_ip="
host_ip = t.split("host_ip=")[1]
elsif t.include? "host_port=" and !t.split("host_port=")[1].nil?
host_port = "-p " + t.split("host_port=")[1] + " "
elsif t.include? "host_password="
host_password = t.split("host_password=")[1]
end
end
2016-08-31 14:42:14 +00:00
puts "gluster volume stop " + volume_name
2016-08-31 15:21:17 +00:00
output = `sshpass -p#{host_password} ssh #{host_port} #{host_user}@#{host_ip} gluster volume stop #{volume_name}`
redirect_to '/volume/index'
2016-08-31 13:34:09 +00:00
end
def volume_start
2016-08-31 14:42:14 +00:00
volume_name = params[:volume_name]
volume_name = volume_name.delete(' ')
2016-08-31 15:21:17 +00:00
host_user = "root"
host_ip = "127.0.0.1"
host_password = "secret"
host_port = ""
@conf_list.each do |t|
if t.include? "host_name="
host_user = t.split("host_user=")[1]
elsif t.include? "host_ip="
host_ip = t.split("host_ip=")[1]
elsif t.include? "host_port=" and !t.split("host_port=")[1].nil?
host_port = "-p " + t.split("host_port=")[1] + " "
elsif t.include? "host_password="
host_password = t.split("host_password=")[1]
end
end
2016-08-31 14:42:14 +00:00
puts "gluster volume start " + volume_name
2016-08-31 15:21:17 +00:00
output = `sshpass -p#{host_password} ssh #{host_port} #{host_user}@#{host_ip} gluster volume start #{volume_name}`
redirect_to '/volume/index'
2016-08-31 12:29:16 +00:00
end
2016-09-01 09:02:00 +00:00
def volume_delete
volume_name = params[:volume_name]
volume_name = volume_name.delete(' ')
host_user = "root"
host_ip = "127.0.0.1"
host_password = "secret"
host_port = ""
@conf_list.each do |t|
if t.include? "host_name="
host_user = t.split("host_user=")[1]
elsif t.include? "host_ip="
host_ip = t.split("host_ip=")[1]
elsif t.include? "host_port=" and !t.split("host_port=")[1].nil?
host_port = "-p " + t.split("host_port=")[1] + " "
elsif t.include? "host_password="
host_password = t.split("host_password=")[1]
end
end
puts "gluster volume start " + volume_name
output = `sshpass -p#{host_password} ssh #{host_port} #{host_user}@#{host_ip} gluster volume delete #{volume_name}`
redirect_to '/volume/index'
end
2016-08-20 06:58:04 +00:00
end