Add volume create function

This commit is contained in:
kyg516 2016-09-11 19:57:07 +09:00
parent 1b2fefebb3
commit 1f8e23e6a5
5 changed files with 475 additions and 348 deletions

View File

@ -2,13 +2,13 @@ class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception. # Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead. # For APIs, you may want to use :null_session instead.
# protect_from_forgery with: :exception # protect_from_forgery with: :exception
def get_conf def get_conf
@config = Hash.new @config = Hash.new
output = `cat configure.conf`.split("\n") output = `cat configure.conf`.split("\n")
output.each do |t| output.each do |t|
if t.include? "project_path=" if t.include? "project_path="
@config["project_path"] = t.split("project_path=")[1] @config["project_path"] = t.split("project_path=")[1]
elsif t.include? "server_name=" elsif t.include? "server_name="
@config["server_name"] = t.split("server_name=")[1] @config["server_name"] = t.split("server_name=")[1]
elsif t.include? "host_user=" elsif t.include? "host_user="
@ -23,14 +23,14 @@ class ApplicationController < ActionController::Base
end end
return @config return @config
end end
def file_directory(dir) def file_directory(dir)
@current_dir = dir @current_dir = dir
dir_list = `ls #{@current_dir} -l` dir_list = `ls #{@current_dir} -l`
parsing_list = dir_list.split("\n") parsing_list = dir_list.split("\n")
@files = Array.new @files = Array.new
file = Hash.new file = Hash.new
@total_list = parsing_list[0] @total_list = parsing_list[0]
for t in 1..(parsing_list.length-1) for t in 1..(parsing_list.length-1)
parsing_file = parsing_list[t].split(" ") parsing_file = parsing_list[t].split(" ")
@ -44,7 +44,7 @@ class ApplicationController < ActionController::Base
puts @files puts @files
return @files return @files
end end
def checkDir def checkDir
files = file_directory(params[:path]) files = file_directory(params[:path])
render :json => {:file => files , :current => @current_dir} render :json => {:file => files , :current => @current_dir}

View File

@ -11,7 +11,7 @@ class HomeController < ApplicationController
current_dir = params[:current_dir] current_dir = params[:current_dir]
directory_name = params[:directory_name] directory_name = params[:directory_name]
puts "mkdir #{current_dir}/#{directory_name}" puts "mkdir #{current_dir}/#{directory_name}"
`mkdir #{current_dir}/#{directory_name}` `sudo mkdir #{current_dir}/#{directory_name}`
redirect_to '/home/index' redirect_to '/home/index'
end end
@ -19,7 +19,7 @@ class HomeController < ApplicationController
def delete_file def delete_file
file_name = params[:file_name] file_name = params[:file_name]
puts "rm #{file_name} -rf" puts "rm #{file_name} -rf"
`rm #{file_name} -rf` `sudo rm #{file_name} -rf`
redirect_to '/home/index' redirect_to '/home/index'
end end
end end

View File

@ -1,89 +1,107 @@
class VolumeController < ApplicationController class VolumeController < ApplicationController
def index def index
file_directory("/mnt") file_directory("/mnt")
get_conf get_conf
info = get_volume_info.split("\n") info = get_volume_info.split("\n")
if info.blank? if info.blank?
flash[:danger] = "Check Server" flash[:danger] = "Check Server"
else else
parse_info(info) parse_info(info)
end
end end
end
def parse_info(info)
def parse_info(info) @volumes = Array.new
@volumes = Array.new
volume = Hash.new
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
String state = (df.include? volume['Volume Name'].delete(' ')) ? "Mounted" : "UnMounted"
volume['Mount State'] = state
@volumes << volume
volume = Hash.new volume = Hash.new
end 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
String state = (df.include? volume['Volume Name'].delete(' ')) ? "Mounted" : "UnMounted"
volume['Mount State'] = state
@volumes << volume
volume = Hash.new
end
end
end end
end
def get_df def get_df
return `df -P` return `df -P`
end end
def get_volume_info def get_volume_info
return `sshpass -p#{@config["host_password"]} ssh #{@config["host_port"]} #{@config["host_user"]}@#{@config["host_ip"]} gluster volume info` return `sshpass -p#{@config["host_password"]} ssh #{@config["host_port"]} #{@config["host_user"]}@#{@config["host_ip"]} \
end gluster volume info`
end
def file_upload
file_name = params[:file]
uploader = AvatarUploader.new
uploader.store!(file_name)
redirect_to '/volume/info'
end
def volume_mount
@config = 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}`
redirect_to '/volume/index'
end
def volume_unmount
@config = get_conf
volume_name = params[:volume_name]
puts "umount " + @config["host_ip"] + ":/" + volume_name
`umount #{@config["host_ip"]}:/#{volume_name}`
redirect_to '/volume/index'
end
def volume_stop def file_upload
@config = get_conf file_name = params[:file]
volume_name = params[:volume_name] uploader = AvatarUploader.new
puts "gluster volume stop " + volume_name uploader.store!(file_name)
`yes | sshpass -p#{@config["host_password"]} ssh #{@config["host_port"]} #{@config["host_user"]}@#{@config["host_ip"]} gluster volume stop #{volume_name}` redirect_to '/volume/info'
redirect_to '/volume/index' end
end
def volume_start def volume_mount
@config = get_conf @config = get_conf
volume_name = params[:volume_name] volume_name = params[:volume_name]
puts "gluster volume start " + volume_name mount_point = params[:mount_point]
`sshpass -p#{@config["host_password"]} ssh #{@config["host_port"]} #{@config["host_user"]}@#{@config["host_ip"]} gluster volume start #{volume_name}` puts "mount -t glusterfs " + @config["host_ip"] + ":/" + volume_name + " " + mount_point
redirect_to '/volume/index' `mount -t glusterfs #{@config["host_ip"]}:/#{volume_name} #{mount_point}`
end redirect_to '/volume/index'
end
def volume_delete def volume_unmount
@config = get_conf @config = get_conf
volume_name = params[:volume_name] volume_name = params[:volume_name]
puts "gluster volume delete " + volume_name puts "umount " + @config["host_ip"] + ":/" + volume_name
`yes | sshpass -p#{@config["host_password"]} ssh #{@config["host_port"]} #{@config["host_user"]}@#{@config["host_ip"]} gluster volume delete #{volume_name}` `umount #{@config["host_ip"]}:/#{volume_name}`
redirect_to '/volume/index' redirect_to '/volume/index'
end end
def volume_create
volume_name = params[:volume_name]
bricks = params[:bricks]
bricks_str = ""
bricks.each do |t|
bricks_str << t
bricks_str << " "
end
puts "gluster volume create " + volume_name + " " + bricks_str + "force"
`sshpass -p#{@config["host_password"]} ssh #{@config["host_port"]} #{@config["host_user"]}@#{@config["host_ip"]} \
gluster volume create #{volume_name} #{bricks_str} force`
redirect_to '/volume/index'
end
def volume_stop
@config = 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}`
redirect_to '/volume/index'
end
def volume_start
@config = 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}`
redirect_to '/volume/index'
end
def volume_delete
@config = 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}`
redirect_to '/volume/index'
end
end end

View File

@ -1,268 +1,376 @@
<!-- create overlay page --> <!-- create overlay page -->
<div id="popup_create" class="overlay"> <div id="popup_create" class="overlay">
<div class="popup"> <div class="popup">
<h2> Choose mount point </h2> <h2> Choose mount point </h2>
<a class="close" href="#">&times;</a> <a class="close" href="#">&times;</a>
<form id="form_volume_create" data-parsley-validate class="form-horizontal form-label-left">
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="volume-name">Volume Name <span class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" id="volume-name" required="required" class="form-control col-md-7 col-xs-12">
</div>
</div>
<div class="form-group"> <form id="form_volume_create" data-parsley-validate class="form-horizontal form-label-left">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Volume Type <span class="required">*</span>
</label>
<div class="col-md-9 col-sm-9 col-xs-12">
<select class="form-control">
<option>Distribute</option>
<option>Stripe</option>
<option>Replica</option>
<option>Arbiter</option>
<option>Disperse</option>
<option>Disperse-data</option>
<option>Redundancy</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Bricks <span class="required">*</span>
</label>
<div class="col-md-3 col-sm-3 col-xs-3">
<select class="form-control">
<option><%=@config['server_name']%></option>
</select>
</div>
<div class="col-md-5 col-sm-5 col-xs-5">
<input type="text" id="bricks" required="required" class="form-control col-md-7 col-xs-12">
</div>
<div class="col-md-1 col-sm-1 col-xs-1">
<a href="#/plus" class="form-control"><i class="fa fa-plus"></i></a>
</div>
</div>
<div class="ln_solid"></div> <div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="volume-name">Volume Name <span class="required">*</span>
<div class="form-group"> </label>
<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3"> <div class="col-md-6 col-sm-6 col-xs-12">
<button type="submit" class="btn btn-primary">Cancel</button> <input type="text" required="required" class="form-control col-md-7 col-xs-12">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>
</div>
</div>
<!-- mount overlay page -->
<div id="popup_mount" class="overlay">
<div class="popup">
<h2> Choose mount point </h2>
<a class="close" href="#">&times;</a>
<table id="datatable" class="table table-striped jambo_table">
<thead>
<tr class="headings">
<th>Name</th>
<th>auth</th>
<th></th>
</tr>
</thead>
<tbody id="datatable_body">
<tr>
<td><i class="fa fa-reply"></i> <a style="cursor: pointer" onclick="change_upper('<%=@current_dir%>')"> ..</a></td>
<td></td>
<td></td>
</tr>
<%@files.each do |t|%>
<% if t["auth"][0]=='d'%>
<tr>
<td style="color:#0d8ade;"><i class="fa fa-folder-open-o"></i>
<a style="cursor: pointer" onclick="change_directory('<%=@current_dir + "/" + t["name"]%>')"> <%=t["name"]%></a>
</td>
<td><%=t["auth"]%></td>
<td>
<button class="btn btn-primary pull-right" onclick="volume_mount('<%=@current_dir + "/" + t["name"]%>')">select</botton>
</td>
</tr>
<%end%>
<%end%>
</tbody>
</table>
</div>
</div>
<!-- page content -->
<div class="right_col" role="main">
<div class="page-title">
<div class="title_left">
<h3>Volume</h3>
</div>
<div class="title_right">
<div class="col-md-5 col-sm-5 col-xs-12 pull-right">
<a class="btn btn-success btn-lg pull-right" href="#popup_create">Create Volume</a>
</div>
</div>
</div>
<div class="clearfix"></div>
<div class="row">
<%@volumes.each do |t|%>
<div class="col-md-6 col-sm-6 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h2>Infomation <small><%=t["Volume Name"]%></small></h2>
<ul class="nav navbar-right panel_toolbox">
<li><a class="collapse-link"><i <%if t!=@volumes[0]%> class="fa fa-chevron-down" <%else%> class="fa fa-chevron-up" <%end%> ></i></a>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Settings 1</a>
</li>
<li><a href="#">Settings 2</a>
</li>
</ul>
</li>
<li><a class="close-link" style="display:none;"><i class="fa fa-close"></i></a>
</li>
</ul>
<div class="clearfix"></div>
</div>
<div class="x_content" <%if t!=@volumes[0]%> style="display: none;" <%end%> >
<!-- left content -->
<div class="col-md-6 col-sm-6 col-xs-12">
<div style="margin: 10px">
<p class="text-muted font-13 m-b-30"><code>Volume Info</code></p>
Type : <%=t["Type"]%> <br>
Volume ID : <%=t["Volume ID"]%> <br>
Status : <%=t["Status"]%> <br>
Number of Bricks : <%=t["Number of Bricks"]%> <br>
Transport-type : <%=t["Transport-type"]%> <br>
Bricks : <%=t["Bricks"]%> <br>
Bricks1 : <%=t["Brick1"]%> <br>
Options Reconfigured : <%=t["Options Reconfigured"]%> <br>
performance.readdir-ahead : <%=t["performance.readdir-ahead"]%> <br>
mount state: <%=t["Mount State"]%> <br>
</div> </div>
<% 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"] == " Stopped" %>
<a class="btn btn-app" href="/volume/start/<%=t['Volume Name'].delete(' ')%>">
<i class="fa fa-play" style="color:#26B99A;"></i>
<p style="color:#26B99A;">Start</p>
</a>
<a class="btn btn-app" href="/volume/delete/<%=t['Volume Name'].delete(' ')%>">
<i class="fa fa-trash"></i> Delete
</a>
<% else %>
<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>
<% end %>
</div>
<!-- right content -->
<div class="col-md-6 col-sm-6 col-xs-12">
<p>Drag multiple files to the box below for multi upload or click to select files.</p>
<form action="/file_upload" method="post" enctype="multipart/form-data" class="dropzone" style="border: 1px solid #e5e5e5; height: 300px; overflow:auto;">
</form>
<br/>
</div>
</div> </div>
</div>
</div>
<%end%>
</div>
</div>
<!-- /page content -->
<!-- volume functions --> <div class="form-group">
<script> <label class="control-label col-md-3 col-sm-3 col-xs-12">Volume Type <span class="required">*</span>
function volume_create() { </label>
<div class="col-md-9 col-sm-9 col-xs-12">
} <select class="form-control">
<% ['Distribute', 'Stripe', 'Replica', 'Arbiter', 'Disperse', 'Disperse-data', 'Redundancy'].each do |types|%>
<option><%=types%></option>
<% end %>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Number of brick <span class="required">*</span>
</label>
<div class="col-md-9 col-sm-9 col-xs-12">
<select class="form-control">
<% for i in 1...11 do %>
<option><%=i%></option>
<% end %>
</select>
</div>
</div>
<div class="form-group">
<div class="row" style="margin:0 0 10px 0">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Bricks <span class="required">*</span>
</label>
<div class="col-md-3 col-sm-3 col-xs-4">
<select class="form-control">
<option><%=@config["server_name"]%></option>
</select>
</div>
<div class="col-md-1 col-sm-1 col-xs-1">
<label class="control-label col-md-12 col-sm-12 col-xs-12">/
</label>
</div>
<div class="col-md-5 col-sm-5 col-xs-7">
<input type="text" required="required" class="form-control col-md-7 col-xs-12">
</div>
</div>
</div>
<div class="ln_solid"></div>
<div class="form-group">
<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
<a href="#" class="btn btn-primary">Cancel</a>
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>
</div>
</div>
<!-- mount overlay page -->
<div id="popup_mount" class="overlay">
<div class="popup">
<h2> Choose mount point </h2>
<a class="close" href="#">&times;</a>
<table id="datatable" class="table table-striped jambo_table">
<thead>
<tr class="headings">
<th>Name</th>
<th>auth</th>
<th></th>
</tr>
</thead>
<tbody id="datatable_body">
<tr>
<td><i class="fa fa-reply"></i> <a style="cursor: pointer" onclick="change_upper('<%=@current_dir%>')"> ..</a></td>
<td></td>
<td></td>
</tr>
<%@files.each do |t|%>
<% if t["auth"][0]=='d'%>
<tr>
<td style="color:#0d8ade;"><i class="fa fa-folder-open-o"></i>
<a style="cursor: pointer" onclick="change_directory('<%=@current_dir + "/" + t["name"]%>')"> <%=t["name"]%></a>
</td>
<td><%=t["auth"]%></td>
<td>
<button class="btn btn-primary pull-right" onclick="volume_mount('<%=@current_dir + "/" + t["name"]%>')">select</botton>
</td>
</tr>
<%end%>
<%end%>
</tbody>
</table>
</div>
</div>
<!-- page content -->
<div class="right_col" role="main">
<div class="page-title">
<div class="title_left">
<h3>Volume</h3>
</div>
<div class="title_right">
<div class="col-md-5 col-sm-5 col-xs-12 pull-right">
<a class="btn btn-success btn-lg pull-right" href="#popup_create">Create Volume</a>
</div>
</div>
</div>
<div class="clearfix"></div>
<div class="row">
<%@volumes.each do |t|%>
<div class="col-md-6 col-sm-6 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h2>Infomation <small><%=t["Volume Name"]%></small></h2>
<ul class="nav navbar-right panel_toolbox">
<li><a class="collapse-link"><i <%if t!=@volumes[0]%> class="fa fa-chevron-down" <%else%> class="fa fa-chevron-up" <%end%> ></i></a>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Settings 1</a>
</li>
<li><a href="#">Settings 2</a>
</li>
</ul>
</li>
<li><a class="close-link" style="display:none;"><i class="fa fa-close"></i></a>
</li>
</ul>
<div class="clearfix"></div>
</div>
<div class="x_content" <%if t!=@volumes[0]%> style="display: none;" <%end%> >
<!-- left content -->
<div class="col-md-6 col-sm-6 col-xs-12">
<div style="margin: 10px">
<p class="text-muted font-13 m-b-30"><code>Volume Info</code></p>
Type : <%=t["Type"]%> <br>
Volume ID : <%=t["Volume ID"]%> <br>
Status : <%=t["Status"]%> <br>
Number of Bricks : <%=t["Number of Bricks"]%> <br>
Transport-type : <%=t["Transport-type"]%> <br>
Bricks : <%=t["Bricks"]%> <br>
Bricks1 : <%=t["Brick1"]%> <br>
Options Reconfigured : <%=t["Options Reconfigured"]%> <br>
performance.readdir-ahead : <%=t["performance.readdir-ahead"]%> <br>
mount state: <%=t["Mount State"]%> <br>
</div>
<% 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"] == " Stopped" %>
<a class="btn btn-app" href="/volume/start/<%=t['Volume Name'].delete(' ')%>">
<i class="fa fa-play" style="color:#26B99A;"></i>
<p style="color:#26B99A;">Start</p>
</a>
<a class="btn btn-app" href="/volume/delete/<%=t['Volume Name'].delete(' ')%>">
<i class="fa fa-trash"></i> Delete
</a>
<% else %>
<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>
<% end %>
</div>
<!-- right content -->
<div class="col-md-6 col-sm-6 col-xs-12">
<p>Drag multiple files to the box below for multi upload or click to select files.</p>
<form action="/file_upload" method="post" enctype="multipart/form-data" class="dropzone" style="border: 1px solid #e5e5e5; height: 300px; overflow:auto;">
</form>
<br/>
</div>
</div>
</div>
</div>
<%end%>
</div>
</div>
<!-- /page content -->
<!-- volume functions -->
<script>
function volume_mount(mnt_point) { function volume_mount(mnt_point) {
var url = window.location + ''; var url = window.location + '';
var vol_name = url.match(/volume_name=([^#]+)/)[1]; var vol_name = url.match(/volume_name=([^#]+)/)[1];
$.ajax({ $.ajax({
type: 'post', type: 'post',
url: '/volume/mount', url: '/volume/mount',
data: {mount_point: mnt_point, volume_name: vol_name}, data: {mount_point: mnt_point, volume_name: vol_name},
success: function(data){ success: function(data){
console.log("mount success"); console.log("mount success");
window.location.replace(url.split("?")[0]); window.location.replace(url.split("?")[0]);
} }
}); });
} }
</script> </script>
<!-- data table handler --> <!-- data table handler -->
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
$('#datatable').dataTable(); $('#datatable').dataTable();
}); });
</script> </script>
<!-- file manager functions --> <!-- file manager functions -->
<script> <script>
function change_upper(directory){ function change_upper(directory){
if(directory == "/") return; if(directory == "/") return;
var lastindex = directory.lastIndexOf("/"); var lastindex = directory.lastIndexOf("/");
if(lastindex == 0) lastindex++; if(lastindex == 0) lastindex++;
change_directory(directory.substring(0, lastindex)); change_directory(directory.substring(0, lastindex));
} }
function change_directory(directory){ function change_directory(directory){
$.ajax({ $.ajax({
method: "POST", method: "POST",
url: "/application/changeDir", url: "/application/changeDir",
data: { path: directory }, data: { path: directory },
success : function(result){ success : function(result){
$("#datatable_body").empty(); $("#datatable_body").empty();
var new_tr = ""; var new_tr = "";
new_tr += "<tr role='row' class='odd'> <td><i class='fa fa-reply'></i>"; new_tr += "<tr role='row' class='odd'> <td><i class='fa fa-reply'></i>";
new_tr += "<a style='cursor: pointer' onclick='change_upper(" + '"' + directory + '"' +")'> ..</a>"; nrailew_tr += "<a style='cursor: pointer' onclick='change_upper(" + '"' + directory + '"' +")'> ..</a>";
new_tr += "</td><td> </td><td> </td><td> </td></tr>"; new_tr += "</td><td> </td><td> </td><td> </td></tr>";
for( var i = 0; i < result.file.length; i++){ for( var i = 0; i < result.file.length; i++){
if(result.file[i].auth[0] != "d") continue; if(result.file[i].auth[0] != "d") continue;
var row_class = i % 2 == 0 ? 'odd' : 'even'; var row_class = i % 2 == 0 ? 'odd' : 'even';
var cur = result.current != "/" ? result.current : ''; var cur = result.current != "/" ? result.current : '';
new_tr += "<tr role='row' class='" + row_class + "'>"; new_tr += "<tr role='row' class='" + row_class + "'>";
new_tr += "<td style='color:#0d8ade;' class='sorting_1'><i class='fa fa-folder-open-o'></i> "; new_tr += "<td style='color:#0d8ade;' class='sorting_1'><i class='fa fa-folder-open-o'></i> ";
new_tr += "<a style='cursor: pointer' onclick='change_directory(" +'"' + cur + "/" + result.file[i].name +'"'+ ")'>" + result.file[i].name + "</a></td>"; new_tr += "<a style='cursor: pointer' onclick='change_directory(" +'"' + cur + "/" + result.file[i].name +'"'+ ")'>" + result.file[i].name + "</a></td>";
new_tr += "<td>"+result.file[i].auth+"</td>"; new_tr += "<td>"+result.file[i].auth+"</td>";
new_tr += "<td><button class='btn btn-primary pull-right'>select</botton></td>"; new_tr += "<td><button class='btn btn-primary pull-right'>select</botton></td>";
new_tr += "</tr>"; new_tr += "</tr>";
} }
$("#datatable_body").append(new_tr); $("#datatable_body").append(new_tr);
$('#datatable').dataTable(); $('#datatable').dataTable();
} }
}) })
} }
</script> </script>
<script> <script>
$("#form_volume_create").change(function (){ // Volume type changed
console.log($("#form_volume_create option:selected").val()); $("#form_volume_create .form-group").eq(1).change(function (){
var $type = $(this).find("option:selected").val();
switch ($type) {
case "Distribute":
case "Stripe":
case "Replica":
case "Arbiter":
case "Disperse":
case "Disperse-data":
case "Redundancy":
console.log($type);
break;
default:
console.log("something goes wrong");
break;
}
}) })
</script>
// Number of bricks changed
$("#form_volume_create .form-group").eq(2).change(function (){
var $num_of_brick = $(this).find("option:selected").val();
var $body = $("#form_volume_create .form-group").eq(3);
$body.empty();
var new_body = "";
for(var i = 0; i < $num_of_brick; ++i) {
new_body += "<div class='row' style='margin:0 0 10px 0'>";
new_body += "<label class='control-label col-md-3 col-sm-3 col-xs-12'>";
if(i == 0)
new_body += "Bricks <span class='required'>*</span>";
new_body += "</label>";
new_body += "<div class='col-md-3 col-sm-3 col-xs-4'>";
new_body += "<select class='form-control'>";
new_body += "<option><%=@config['server_name']%></option>";
new_body += "</select>";
new_body += "</div>";
new_body += "<div class='col-md-1 col-sm-1 col-xs-1'>"
new_body += "<label class='control-label col-md-12 col-sm-12 col-xs-12'>/"
new_body += "</label>"
new_body += "</div>"
new_body += "<div class='col-md-5 col-sm-5 col-xs-7'>";
new_body += "<input type='text' required='required' class='form-control col-md-7 col-xs-12'>";
new_body += "</div>";
new_body += "</div>";
}
$body.append(new_body);
})
$("#form_volume_create").submit(function(){
var volume_name = $(this).find(".form-group:eq(0) input").val();
var volume_type = $(this).find(".form-group:eq(1) option:selected").val();
var num_of_brick = $(this).find(".form-group:eq(2) option:selected").val() * 1; // convert to Number type
var bricks = [];
// error check
if(volume_name.indexOf(' ') >= 0){
alert("Volume name can't contains white spaces");
return;
}
<% @volumes.each do |t| %>
if(volume_name == "<%=t["Volume Name"].delete(' ')%>"){
alert("Already has a volume which name is same");
return;
}
<% end %>
for(var i = 0; i < num_of_brick; i++){
var server_name = $(this).find(".form-group .row").eq(i).find("option:selected").val();
var brick_name = $(this).find(".form-group .row").eq(i).find("input").val();
if(brick_name.indexOf(' ') >= 0) {
alert("Brick name can't contain white spaces");
return;
}
if(brick_name.indexOf('/') == 0) {
alert("Brick name can't start with slash");
return;
}
var brick = "";
if(server_name == "<%=@config['server_name']%>"){
brick += "<%=@config['host_ip']%>";
brick += "/";
brick += brick_name;
bricks.push(brick);
console.log(brick);
}
else{
alert("Something goes wrong!");
return;
}
}
console.log("Create volume..");
$.ajax({
method: "POST",
url: "/volume/create",
data: { volume_name : volume_name, bricks : bricks },
success : function(result){
console.log("volume create success");
}
})
});
</script>

View File

@ -7,29 +7,30 @@ Rails.application.routes.draw do
root 'home#index' root 'home#index'
post 'application/changeDir' => 'application#checkDir' post 'application/changeDir' => 'application#checkDir'
get 'index' => 'plainpage#index' get 'index' => 'plainpage#index'
#Home #Home
get 'home/index' => 'home#index' get 'home/index' => 'home#index'
post 'home/mkdir' => 'home#make_directory' post 'home/mkdir' => 'home#make_directory'
post 'home/delete' => 'home#delete_file' post 'home/delete' => 'home#delete_file'
#Volume #Volume
get 'volume/index' => 'volume#index' get 'volume/index' => 'volume#index'
post 'file_upload' => 'volume#file_upload' post 'file_upload' => 'volume#file_upload'
post 'volume/mount' => "volume#volume_mount" post 'volume/mount' => "volume#volume_mount"
post 'volume/create' => "volume#volume_create"
get 'volume/unmount/:volume_name' => "volume#volume_unmount" get 'volume/unmount/:volume_name' => "volume#volume_unmount"
get 'volume/start/:volume_name' => "volume#volume_start" get 'volume/start/:volume_name' => "volume#volume_start"
get 'volume/stop/:volume_name' => "volume#volume_stop" get 'volume/stop/:volume_name' => "volume#volume_stop"
get 'volume/delete/:volume_name' => "volume#volume_delete" get 'volume/delete/:volume_name' => "volume#volume_delete"
#Peer #Peer
get 'peer/index' => 'peer#index' get 'peer/index' => 'peer#index'
# Example of regular route: # Example of regular route:
# get 'products/:id' => 'catalog#view' # get 'products/:id' => 'catalog#view'