Add scope resolution to Routes and Controllers

This commit is contained in:
Youngkyun
2017-10-29 14:28:22 +09:00
parent 3312f36cb8
commit 15db7f27de
16 changed files with 155 additions and 511 deletions

View File

@@ -0,0 +1,54 @@
class Web::HomeController < WebController
before_action :require_login
def index
@current_dir = "/mnt"
end
def file_download
@file_name = params[:file_name].gsub(" ", "/")
if !@file_name.nil?
send_file @file_name
else
puts "file name is nil"
redirect_to '/home/index'
end
end
def make_directory
current_dir = params[:current_dir]
directory_name = params[:directory_name]
# make directory
command = String.new
command << "sudo mkdir #{current_dir}/#{directory_name}"
puts command
`#{command}`
redirect_to '/home/index'
end
def chdir
@current_dir = params[:next_dir]
puts "current_dir : " + @current_dir
render :json => {
:dir => @current_dir,
:file_manager_table => html_file_manager_table(@current_dir),
:disk_usage_table => html_disk_usage_table(@current_dir),
:du => get_du(@current_dir),
}
end
def rmdir
@current_dir = params[:current_dir]
file_name = params[:target]
command = String.new
command << "sudo rm -rf #{file_name}"
puts command
`#{command}`
render :json => {
:dir => @current_dir,
:file_manager_table => html_file_manager_table(@current_dir),
:disk_usage_table => html_disk_usage_table(@current_dir),
:du => get_du(@current_dir),
}
end
end

View File

@@ -0,0 +1,49 @@
class Web::NodeController < WebController
before_action :require_login
def index
end
def detail
@node_id = params[:node_id]
end
def node_update
one_node = Node.find(params[:node_id])
one_node.host_name = params[:host_name]
one_node.host_ip = params[:host_ip]
one_node.user_name = params[:user_name]
one_node.user_password = params[:user_password]
one_node.save
redirect_to '/node/detail/' + params[:node_id]
end
def node_add
new_node = Node.new
new_node.host_name = params[:host_name]
new_node.host_ip = params[:host_ip]
new_node.user_name = params[:user_name]
new_node.user_password = params[:user_password]
new_node.save
redirect_to '/node/index'
end
def node_delete
one_node = Node.find(params[:node_id])
one_node.destroy
redirect_to '/node/index'
end
def node_probe
one_node = Node.find(params[:node_id])
puts "gluster peer probe #{one_node.host_name}"
redirect_to '/node/index'
end
def node_detach
one_node = Node.find(params[:node_id])
puts "gluster peer detach #{one_node.host_name}"
redirect_to '/node/index'
end
end

View File

@@ -0,0 +1,142 @@
class Web::VolumeController < WebController
before_action :require_login
def index
@current_dir = "/mnt"
end
def chdir
@current_dir = params[:next_dir]
puts "current_dir : " + @current_dir
render :json => {
:dir => @current_dir,
:mount_table => html_mount_table(@current_dir),
}
end
def file_upload
df = get_df
mnt_dir = String.new
mnt_dest = String.new
file = params[:file]
df.each do |t|
if t['Filesystem'].include? params[:volume_name]
mnt_dir = t['Mounted on']
end
end
mnt_dest = mnt_dir + "/" + file.original_filename
# change permission
command = String.new
command << "sudo chmod 777 #{mnt_dir}"
puts command
`#{command}`
# upload file
u = AvatarUploader.new(mnt_dir)
u.store!(file)
redirect_to '/volume/index'
end
def volume_mount
node = Node.take
volume_name = params[:volume_name]
index = params[:index]
mount_point = params[:mount_point]
# make command string
command = String.new
command << "sudo mount -t glusterfs #{node.host_ip}:/#{volume_name} #{mount_point}"
puts command
`#{command}`
#redirect_to '/volume/index'
render :json => {
:volume_info => html_volume_info(volume_name, index),
}
end
def volume_unmount
node = Node.take
volume_name = params[:volume_name]
# make command string
command = String.new
command << "sudo umount #{node.host_ip}:/#{volume_name}"
puts command
`#{command}`
volume = ssh_volume_info.find{ |v| v['Volume Name'].delete(' ') == volume_name}
render :json => {
:volume_info => html_volume_info(volume, 0),
}
end
def volume_create
node = Node.take
volume_name = params[:volume_name]
volume_type = params[:volume_type]
num_of_brick = params[:num_of_brick]
bricks = params[:bricks]
# make command string
command = String.new
command << "sshpass -p#{node.user_password} "
command << "ssh #{node.user_name}@#{node.host_ip} "
command << "gluster volume create #{volume_name} "
if !volume_type.include? "Distribute"
command << "#{volume_type.downcase} #{num_of_brick} "
end
nodes = Node.all
bricks.each do |t|
host_name = t.split(":/")[0]
brick_name = t.split(":/")[1]
host_ip = ""
nodes.each do |u|
next if !u.host_name.eql? host_name
host_ip = u['host_ip']
end
brick = "#{host_ip}:/#{brick_name}"
command << "#{brick} "
end
command << "force"
puts command
`#{command}`
render :json => {
:test => 0,
}
end
def volume_stop
node = Node.take
volume_name = params[:volume_name]
# make command string
command = String.new
command << "yes | sshpass -p#{node.user_password} ssh #{node.user_name}@#{node.host_ip} gluster volume stop #{volume_name}"
puts command
`#{command}`
volume = ssh_volume_info.find{ |v| v['Volume Name'].delete(' ') == volume_name}
render :json => {
:volume_info => html_volume_info(volume, 0),
}
end
def volume_start
node = Node.take
volume_name = params[:volume_name]
# make command string
command = String.new
command << "sshpass -p#{node.user_password} ssh #{node.user_name}@#{node.host_ip} gluster volume start #{volume_name}"
puts command
`#{command}`
volume = ssh_volume_info.find{ |v| v['Volume Name'].delete(' ') == volume_name}
render :json => {
:volume_info => html_volume_info(volume, 0),
}
end
def volume_delete
node = Node.take
volume_name = params[:volume_name]
# make command string
command = String.new
command << "yes | sshpass -p#{node.user_password} ssh #{node.user_name}@#{node.host_ip} gluster volume delete #{volume_name}"
puts command
`#{command}`
redirect_to "/volume/index"
end
end