Change all command on Volume controller

This commit is contained in:
kyg516 2016-09-12 17:33:08 +09:00
parent 5fd211e56b
commit c1a44853af
3 changed files with 81 additions and 49 deletions

View File

@ -16,7 +16,7 @@ class ApplicationController < ActionController::Base
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] + " "
@config["host_port"] = t.split("host_port=")[1] + " "
elsif t.include? "host_password="
@config["host_password"] = t.split("host_password=")[1]
end

View File

@ -22,7 +22,7 @@ class VolumeController < ApplicationController
temp = t.split(":")
volume[temp[0]] = temp[1]
else
String state = (df.include? volume['Volume Name'].delete(' ')) ? "Mounted" : "UnMounted"
String state = (df.include? volume['Volume Name'].delete(' ')) ? "mounted" : "unmounted"
volume['Mount State'] = state
@volumes << volume
volume = Hash.new
@ -35,8 +35,16 @@ class VolumeController < ApplicationController
end
def get_volume_info
return `sshpass -p#{@config["host_password"]} ssh #{@config["host_port"]} #{@config["host_user"]}@#{@config["host_ip"]} \
gluster volume info`
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}`
end
def file_upload
@ -47,46 +55,48 @@ class VolumeController < ApplicationController
end
def volume_mount
@config = get_conf
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}`
# make command string
command = String.new
command << "mount -t glusterfs " + @config["host_ip"].to_s + ":/" + volume_name + " " + mount_point
puts command
`#{command}`
redirect_to '/volume/index'
end
def volume_unmount
@config = get_conf
get_conf
volume_name = params[:volume_name]
puts "umount " + @config["host_ip"] + ":/" + volume_name
`umount #{@config["host_ip"]}:/#{volume_name}`
# make command string
command = String.new
command << "umount " + @config["host_ip"].to_s + ":/" + volume_name
puts command
`#{command}`
redirect_to '/volume/index'
end
def volume_create
@config = get_conf
get_conf
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"
command << " -p"
command << @config["host_password"].to_s
command << "sshpass -p" + @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 + " "
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 + " "
if !volume_type.equal? "Distribute"
command << volume_type.downcase + " " + num_of_brick + " "
end
bricks.each do |t|
command << t
command << " "
command << t + " "
end
command << "force"
puts command
@ -95,30 +105,53 @@ class VolumeController < ApplicationController
end
def volume_stop
@config = get_conf
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}`
# 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}`
redirect_to '/volume/index'
end
def volume_start
@config = get_conf
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}`
# 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 start " + volume_name
puts command
`#{command}`
redirect_to '/volume/index'
end
def volume_delete
@config = get_conf
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}`
# 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}`
redirect_to '/volume/index'
end
end

View File

@ -167,14 +167,13 @@
</div>
<% if t["Mount State"] == "Mounted" %>
<% if t["Mount State"] == "mounted" %>
<a class="btn btn-app" href="/volume/unmount/<%=t['Volume Name'].delete(' ')%>"><i class="fa fa-upload"></i> Unmount</a>
<% elsif t["Status"] == " Started" %>
<a class="btn btn-app" href="/volume/stop/<%=t['Volume Name'].delete(' ')%>">
<i class="fa fa-pause" style="color:#d9534f;"></i>
<p style="color:#d9534f;">Stop</p>
</a>
<!-- mount button push : popup event and post mount point -->
<a class="btn btn-app" href="/volume/index?volume_name=<%=t['Volume Name'].delete(' ')%>#popup_mount"><i class="fa fa-download"></i> Mount</a>
<% else %>
<a class="btn btn-app" href="/volume/start/<%=t['Volume Name'].delete(' ')%>">