This commit is contained in:
kyg516 2016-10-02 21:38:57 +09:00
parent 73cb353d4a
commit 89986f9f47
10 changed files with 50 additions and 72 deletions

View File

@ -31,8 +31,8 @@ class HomeController < ApplicationController
puts "current_dir : " + @current_dir
render :json => {
:dir => @current_dir,
:file_manager_table => file_manager_table(@current_dir),
:disk_usage_table => disk_usage_table(@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

View File

@ -1,7 +1,6 @@
class NodeController < ApplicationController
before_action :require_login
def index
@hosts = Array.new
@nodes = Node.all.order("id asc")
@node_connects = Array.new
node_info = Hash.new
@ -32,12 +31,6 @@ class NodeController < ApplicationController
end
end
if get_hosts.blank?
flash[:danger] = "Check Server"
else
@hosts = get_hosts
end
rescue => ex
puts ex
end
@ -59,7 +52,7 @@ class NodeController < ApplicationController
redirect_to '/node/index'
end
def node_prove
def node_probe
one_node = Node.find(params[:node_id])
puts "gluster peer probe #{one_node.host_name}"
redirect_to '/node/index'

View File

@ -10,7 +10,7 @@ class VolumeController < ApplicationController
puts "current_dir : " + @current_dir
render :json => {
:dir => @current_dir,
:mount_table => mount_table(@current_dir),
:mount_table => html_mount_table(@current_dir),
}
end
@ -49,7 +49,7 @@ class VolumeController < ApplicationController
#redirect_to '/volume/index'
render :json => {
:volume_info => volume_info(volume_name, index),
:volume_info => html_volume_info(volume_name, index),
}
end
@ -61,9 +61,9 @@ class VolumeController < ApplicationController
command << "sudo umount #{node.host_ip}:/#{volume_name}"
puts command
`#{command}`
volume = volumes.find{ |v| v['Volume Name'].delete(' ') == volume_name}
volume = ssh_volume_info.find{ |v| v['Volume Name'].delete(' ') == volume_name}
render :json => {
:volume_info => volume_info(volume, 0),
:volume_info => html_volume_info(volume, 0),
}
end
@ -107,9 +107,9 @@ class VolumeController < ApplicationController
command << "yes | sshpass -p#{node.user_password} ssh #{node.user_name}@#{node.host_ip} gluster volume stop #{volume_name}"
puts command
`#{command}`
volume = volumes.find{ |v| v['Volume Name'].delete(' ') == volume_name}
volume = ssh_volume_info.find{ |v| v['Volume Name'].delete(' ') == volume_name}
render :json => {
:volume_info => volume_info(volume, 0),
:volume_info => html_volume_info(volume, 0),
}
end
@ -121,9 +121,9 @@ class VolumeController < ApplicationController
command << "sshpass -p#{node.user_password} ssh #{node.user_name}@#{node.host_ip} gluster volume start #{volume_name}"
puts command
`#{command}`
volume = volumes.find{ |v| v['Volume Name'].delete(' ') == volume_name}
volume = ssh_volume_info.find{ |v| v['Volume Name'].delete(' ') == volume_name}
render :json => {
:volume_info => volume_info(volume, 0),
:volume_info => html_volume_info(volume, 0),
}
end

View File

@ -80,7 +80,7 @@ module ApplicationHelper
return du
end
def volumes
def ssh_volume_info
volumes = Array.new
volume = Hash.new
node = Node.take
@ -113,6 +113,15 @@ module ApplicationHelper
return volumes
end
def ssh_peer_status
end
def ssh_peer_probe
end
def ssh_peer_detach
end
def files(dir)
files = Array.new
file = Hash.new

View File

@ -1,6 +1,6 @@
module HomeHelper
def file_manager_table(dir = @current_dir, id = "file_manager_table", class_option = "table table-striped table-bordered jambo_table")
def html_file_manager_table(dir = @current_dir, id = "file_manager_table", class_option = "table table-striped table-bordered jambo_table")
html = String.new
html << "<table id='#{id}' class='#{class_option}'>"
html << "<thead>"
@ -48,7 +48,7 @@ module HomeHelper
return html
end
def disk_usage_table(dir = @current_dir, id = "disk_usage_table")
def html_disk_usage_table(dir = @current_dir, id = "disk_usage_table")
html = String.new
html << "<table id='#{id}' class='' style='width:100%'>"
html << "<tr>"

View File

@ -1,6 +1,6 @@
module VolumeHelper
def volume_info(volume, index)
def html_volume_info(volume, index)
params = ['Type', 'Volume ID', 'Status', 'Number of Bricks', 'Transport-type', 'Bricks', 'Options Reconfigured', 'Mount State', 'Mount Point']
arrow = ((index == 0) ? "up" : "down")
display = ((index != 0) ? "style='display: none;'" : "")
@ -96,7 +96,7 @@ module VolumeHelper
return html
end
def mount_table(dir = @current_dir, id = "mount_table", class_option = "table table-striped table-bordered jambo_table")
def html_mount_table(dir = @current_dir, id = "mount_table", class_option = "table table-striped table-bordered jambo_table")
html = String.new
html << "<table id='#{id}' class='#{class_option}'>"
html << "<thead>"
@ -109,7 +109,7 @@ module VolumeHelper
html << "<tbody id='#{id}_body'>"
html << "<tr>"
html << "<td>"
html << "<a class='chupper' style='cursor: pointer'><i class='fa fa-reply'></i></a> #{@current_dir}"
html << "<a class='chupper' style='cursor: pointer'><i class='fa fa-reply'></i></a> <span>#{@current_dir}</span>"
html << "</td>"
html << "<td></td>"
html << "<td></td>"

View File

@ -37,7 +37,7 @@
<!-- top tiles -->
<% users = User.all %>
<% nodes = Node.all %>
<% vols = volumes %>
<% vols = ssh_volume_info %>
<% today_user = User.where(:last_sign_in_at => Date.today..Date.tomorrow) %>
<% today_node = Node.where(:created_at => Date.today..Date.tomorrow) %>
<div class="row tile_count">
@ -111,7 +111,7 @@
</div>
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12" id="file_manager_div">
<%= raw file_manager_table %>
<%= raw html_file_manager_table %>
</div>
</div>
</div>
@ -125,7 +125,7 @@
<h2 style="width:130px">Disk usage</h2>
</div>
<div class="row" id="disk_usage_div">
<%= raw disk_usage_table %>
<%= raw html_disk_usage_table %>
</div>
</div>
</div>

View File

@ -1,12 +1,10 @@
<!-- page content -->
<div class="right_col" role="main">
<div class="page-title">
<div class="title_left"><h3>Peer</h3></div>
<div class="title_left"><h3>Node</h3></div>
<div class="title_right">
</div>
</div>
<div class="clearfix"></div>
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
@ -29,7 +27,6 @@
<div class="clearfix"></div>
</div>
<div class="x_content">
<form class="form-horizontal form-label-left" action="/node/add" method="post" novalidate>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Host Name <span class="required">*</span>
@ -39,7 +36,6 @@
data-toggle="tooltip" data-placement="top" title="Put node's representative name">
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="ip">Host IP <span class="required">*</span>
</label>
@ -48,7 +44,6 @@
data-toggle="tooltip" data-placement="top" title="Put node's ip">
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">User Name <span class="required">*</span>
</label>
@ -68,7 +63,7 @@
<div class="form-group">
<div class="col-md-6 col-md-offset-3">
<button type="submit" class="btn btn-primary">Cancel</button>
<button id="send" type="submit" class="btn btn-success">Add</button>
<button type="submit" class="btn btn-success">Add</button>
</div>
</div>
</form>
@ -78,7 +73,7 @@
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h2><i class="fa fa-align-left"></i> Node List <small>Try hovering over the rows</small></h2>
<h2><i class="fa fa-align-left"></i> Node List</h2>
<ul class="nav navbar-right panel_toolbox">
<li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
</li>
@ -98,13 +93,13 @@
<table class="table table-hover">
<thead>
<tr>
<th>Ping</th> <!-- Ping-->
<th>Ping</th>
<th>Status</th>
<th>Host Name</th>
<th>Host IP</th>
<th>User Name</th>
<th>Date</th>
<th></th> <!-- Delete-->
<th></th>
</tr>
</thead>
<tbody>
@ -112,7 +107,7 @@
<tr>
<%if ping_test?(t.host_ip)%>
<td><i class="fa fa-circle-o green"></i></a></td>
<td><input type="checkbox" class="js-switch prove" value="<%=t.id%>" checked/>Attached</td>
<td><input type="checkbox" class="js-switch probe" value="<%=t.id%>" checked/>Attached</td>
<%else%>
<td><i class="fa fa-close red"></i></a></td>
<td><input type="checkbox" class="js-switch" disabled/></td>
@ -126,22 +121,19 @@
<%end%>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- /page content -->
<script>
$('.prove').change(function() {
<script>
$('.probe').change(function() {
$(location).attr('href',"#loading");
if($(this).is(":checked")) {
$.ajax({
method: "POST",
url: "/node/prove",
url: "/node/probe",
data: { node_id : this.value },
success : function(result){
$(location).attr('href',"#");
@ -173,9 +165,6 @@ $('.multi.required')
validator.checkField.apply($(this).siblings().last()[0]);
});
// bind the validation to the form submit event
//$('#send').click('submit');//.prop('disabled', true);
$('form').submit(function(e) {
e.preventDefault();
var submit = true;

View File

@ -70,7 +70,7 @@
<h2> Choose mount point </h2>
<a class="close" href="#">&times;</a>
<div id="mount_table_div">
<%= raw mount_table %>
<%= raw html_mount_table %>
</div>
</div>
</div>
@ -97,8 +97,8 @@
</div>
<% else %>
<div class="row">
<% volumes.each_with_index do |volume, index| %>
<%= raw volume_info(volume, index) %>
<% ssh_volume_info.each_with_index do |volume, index| %>
<%= raw html_volume_info(volume, index) %>
<% end %>
</div>
<% end %>
@ -116,7 +116,7 @@ $(document).ready(function(){
$.ajax({
type: 'post',
url: '/volume/mount',
before: function(){
beforeSend: function(){
$(location).attr('href',"#loading");
},
data: {mount_point: mnt_point, volume_name: vol_name},
@ -135,7 +135,7 @@ $(document).ready(function(){
alert("Volume name can't contains white spaces");
return;
}
<% volumes.each do |t| %>
<% ssh_volume_info.each do |t| %>
if(volume_name == "<%=t["Volume Name"].delete(' ')%>"){
alert("Already has a volume which name is same");
return;
@ -159,9 +159,9 @@ $(document).ready(function(){
$.ajax({
method: "POST",
url: "/volume/create",
before: function(){
beforeSend: function(){
$(location).attr('href',"#loading");
},
},
data: { volume_name : volume_name, volume_type : volume_type, num_of_brick : num_of_brick, bricks : bricks },
success : function(result){
$(location).attr('href',"#");
@ -231,13 +231,9 @@ $(document).on("click", "#mount_table_div .chdir", function(){
method: "post",
url: "/volume/chdir",
data: { next_dir : next_dir },
before: function(){
$(location).attr('href',"#loading");
},
success : function(result){
$("#mount_table_div").empty();
$("#mount_table_div").append(result.mount_table);
$(location).attr('href',"#");
}
})
})
@ -255,13 +251,9 @@ $(document).on("click", "#mount_table_div .chupper", function(){
method: "POST",
url: "/volume/chdir",
data: { next_dir : next_dir },
before: function(){
$(location).attr('href',"#loading");
},
success : function(result){
$("#mount_table_div").empty();
$("#mount_table_div").append(result.mount_table);
$(location).attr('href',"#");
}
})
})
@ -273,7 +265,6 @@ $(document).on("click", "#mount_table_div .chupper", function(){
// volume mount
$(document).on("click", ".btn-volume-mount", function(){
});
// volume unmount
$(document).on("click", ".btn-volume-unmount", function(){
var $this = $(this);
@ -284,8 +275,7 @@ $(document).on("click", ".btn-volume-unmount", function(){
method: "POST",
url: "/volume/unmount",
data: { volume_name : volume_name },
before: function(){
console.log("zzz");
beforeSend: function(){
$(location).attr('href',"#loading");
},
success: function(result){
@ -322,8 +312,7 @@ $(document).on("click", ".btn-volume-start", function(){
method: "POST",
url: "/volume/start",
data: { volume_name : volume_name },
before: function(){
console.log("zzz");
beforeSend: function(){
$(location).attr('href',"#loading");
},
success: function(result){
@ -360,8 +349,7 @@ $(document).on("click", ".btn-volume-stop", function(){
method: "POST",
url: "/volume/stop",
data: { volume_name : volume_name },
before: function(){
console.log("zzz");
beforeSend: function(){
$(location).attr('href',"#loading");
},
success: function(result){
@ -398,8 +386,7 @@ $(document).on("click", ".btn-volume-delete", function(){
method: "POST",
url: "/volume/delete",
data: { volume_name : volume_name },
before: function(){
console.log("zzz");
beforeSend: function(){
$(location).attr('href',"#loading");
},
success: function(result){

View File

@ -30,7 +30,7 @@ Rails.application.routes.draw do
get 'node/index' => 'node#index'
post 'node/add' => "node#node_add"
get 'node/delete/:node_id' => "node#node_delete"
post 'node/prove' => "node#node_prove"
post 'node/probe' => "node#node_probe"
post 'node/detach' => "node#node_detach"