Add top tiles to dashboard
This commit is contained in:
parent
bf7244b273
commit
dd2f52a7d1
@ -3,40 +3,12 @@ class ApplicationController < ActionController::Base
|
||||
# For APIs, you may want to use :null_session instead.
|
||||
# protect_from_forgery with: :exception
|
||||
|
||||
|
||||
def require_login
|
||||
unless user_signed_in?
|
||||
flash[:error] = "Please, Login required to use the service."
|
||||
redirect_to "/users/sign_in" # halts request cycle
|
||||
end
|
||||
end
|
||||
|
||||
def get_conf
|
||||
config = Hash.new
|
||||
one_node = Node.take
|
||||
if !one_node.nil?
|
||||
config["host_name"] = one_node.host_name
|
||||
config["host_ip"] = one_node.host_ip
|
||||
config["user_name"] = one_node.user_name
|
||||
config["user_password"] = one_node.user_password
|
||||
end
|
||||
return config
|
||||
end
|
||||
|
||||
def get_conf_all
|
||||
config = Array.new
|
||||
config_each = Hash.new
|
||||
all_node = Node.all
|
||||
all_node.each do |one_node|
|
||||
config_each["host_name"] = one_node.host_name
|
||||
config_each["host_ip"] = one_node.host_ip
|
||||
config_each["user_name"] = one_node.user_name
|
||||
config_each["user_password"] = one_node.user_password
|
||||
config << config_each
|
||||
config_each = Hash.new
|
||||
end
|
||||
return config
|
||||
end
|
||||
|
||||
def get_df
|
||||
df = Array.new
|
||||
@ -66,7 +38,7 @@ class ApplicationController < ActionController::Base
|
||||
parsing_list = dir_list.split("\n")
|
||||
@files = Array.new
|
||||
file = Hash.new
|
||||
|
||||
|
||||
@total_list = parsing_list[0]
|
||||
for t in 1..(parsing_list.length-1)
|
||||
parsing_file = parsing_list[t].split(" ")
|
||||
|
@ -1,5 +1,5 @@
|
||||
class VolumeController < ApplicationController
|
||||
before_action :require_login
|
||||
before_action :require_login
|
||||
|
||||
def index
|
||||
file_directory("/mnt")
|
||||
@ -28,49 +28,49 @@ class VolumeController < ApplicationController
|
||||
end
|
||||
|
||||
def volume_mount
|
||||
conf = get_conf
|
||||
node = Node.take
|
||||
volume_name = params[:volume_name]
|
||||
mount_point = params[:mount_point]
|
||||
# make command string
|
||||
command = String.new
|
||||
command << "sudo mount -t glusterfs #{conf['host_ip']}:/#{volume_name} #{mount_point}"
|
||||
command << "sudo mount -t glusterfs #{node.host_ip}:/#{volume_name} #{mount_point}"
|
||||
puts command
|
||||
`#{command}`
|
||||
redirect_to '/volume/index'
|
||||
end
|
||||
|
||||
def volume_unmount
|
||||
conf = get_conf
|
||||
node = Node.take
|
||||
volume_name = params[:volume_name]
|
||||
# make command string
|
||||
command = String.new
|
||||
command << "sudo umount #{conf['host_ip']}:/#{volume_name}"
|
||||
command << "sudo umount #{node.host_ip}:/#{volume_name}"
|
||||
puts command
|
||||
`#{command}`
|
||||
redirect_to '/volume/index'
|
||||
end
|
||||
|
||||
def volume_create
|
||||
conf = get_conf
|
||||
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#{conf['user_password']} "
|
||||
command << "ssh #{conf['user_name']}@#{conf['host_ip']} "
|
||||
command << "sshpass -p#{node.user_password} "
|
||||
command << "ssh #{node.host_name}@#{node.host_ip} "
|
||||
command << "gluster volume create #{volume_name} "
|
||||
if !volume_type.include? "Distribute"
|
||||
command << "#{volume_type.downcase} #{num_of_brick}"
|
||||
end
|
||||
conf_all = get_conf_all
|
||||
nodes = Node.all
|
||||
bricks.each do |t|
|
||||
host_name = t.split(":/")[0]
|
||||
brick_name = t.split(":/")[1]
|
||||
host_ip = ""
|
||||
conf_all.each do |u|
|
||||
next if !u['host_name'].eql? host_name
|
||||
nodes.each do |u|
|
||||
next if !u.host_name.eql? host_name
|
||||
host_ip = u['host_ip']
|
||||
end
|
||||
brick = "#{host_ip}:/#{brick_name}"
|
||||
@ -83,12 +83,12 @@ class VolumeController < ApplicationController
|
||||
end
|
||||
|
||||
def volume_stop
|
||||
conf = get_conf
|
||||
node = Node.take
|
||||
volume_name = params[:volume_name]
|
||||
# make command string
|
||||
command = String.new
|
||||
command << "yes | sshpass -p#{conf['user_password']} "
|
||||
command << "ssh #{conf['user_name']}@#{conf['host_ip']} "
|
||||
command << "yes | sshpass -p#{node.user_password} "
|
||||
command << "ssh #{node.host_name}@#{node.host_ip} "
|
||||
command << "gluster volume stop #{volume_name}"
|
||||
puts command
|
||||
`#{command}`
|
||||
@ -96,12 +96,12 @@ class VolumeController < ApplicationController
|
||||
end
|
||||
|
||||
def volume_start
|
||||
conf = get_conf
|
||||
node = Node.take
|
||||
volume_name = params[:volume_name]
|
||||
# make command string
|
||||
command = String.new
|
||||
command << "sshpass -p#{conf['user_password']} "
|
||||
command << "ssh #{conf['user_name']}@#{conf['host_ip']} "
|
||||
command << "sshpass -p#{node.user_password} "
|
||||
command << "ssh #{node.host_name}@#{node.host_ip} "
|
||||
command << " gluster volume start #{volume_name}"
|
||||
puts command
|
||||
`#{command}`
|
||||
@ -109,12 +109,12 @@ class VolumeController < ApplicationController
|
||||
end
|
||||
|
||||
def volume_delete
|
||||
conf = get_conf
|
||||
node = Node.take
|
||||
volume_name = params[:volume_name]
|
||||
# make command string
|
||||
command = String.new
|
||||
command << "yes | sshpass -p#{conf['user_password']} "
|
||||
command << "ssh #{conf['user_name']}@#{conf['host_ip']} "
|
||||
command << "yes | sshpass -p#{node.user_password} "
|
||||
command << "ssh #{node.host_name}@#{node.host_ip} "
|
||||
command << " gluster volume delete #{volume_name}"
|
||||
puts command
|
||||
`#{command}`
|
||||
|
@ -1,32 +1,5 @@
|
||||
module ApplicationHelper
|
||||
|
||||
def get_conf
|
||||
conf = Hash.new
|
||||
node = Node.take
|
||||
if !node.nil?
|
||||
conf["host_name"] = node.host_name
|
||||
conf["host_ip"] = node.host_ip
|
||||
conf["user_name"] = node.user_name
|
||||
conf["user_password"] = node.user_password
|
||||
end
|
||||
return conf
|
||||
end
|
||||
|
||||
def get_conf_all
|
||||
conf_all = Array.new
|
||||
conf = Hash.new
|
||||
nodes = Node.all
|
||||
nodes.each do |node|
|
||||
conf["host_name"] = node.host_name
|
||||
conf["host_ip"] = node.host_ip
|
||||
conf["user_name"] = node.user_name
|
||||
conf["user_password"] = node.user_password
|
||||
conf_all << conf
|
||||
conf = Hash.new
|
||||
end
|
||||
return conf_all
|
||||
end
|
||||
|
||||
def get_df
|
||||
df = Array.new
|
||||
df_each = Hash.new
|
||||
@ -49,25 +22,13 @@ module ApplicationHelper
|
||||
return df
|
||||
end
|
||||
|
||||
def users
|
||||
users = User.all
|
||||
return users
|
||||
end
|
||||
|
||||
def nodes
|
||||
nodes = Node.all
|
||||
return nodes
|
||||
end
|
||||
|
||||
def volumes
|
||||
volumes = Array.new
|
||||
volume = Hash.new
|
||||
conf = get_conf
|
||||
node = Node.take
|
||||
df = get_df
|
||||
command = String.new
|
||||
command << "sshpass -p#{conf['user_password']} "
|
||||
command << "ssh #{conf['user_name']}@#{conf['host_ip']} "
|
||||
command << "gluster volume info"
|
||||
command << "sshpass -p#{node.user_password} ssh #{node.user_name}@#{node.host_ip} gluster volume info"
|
||||
puts command
|
||||
output = `#{command}`.split("\n")
|
||||
output << "\n"
|
||||
@ -89,4 +50,5 @@ module ApplicationHelper
|
||||
end
|
||||
return volumes
|
||||
end
|
||||
|
||||
end
|
||||
|
2
app/helpers/node_helper.rb
Normal file
2
app/helpers/node_helper.rb
Normal file
@ -0,0 +1,2 @@
|
||||
module NodeHelper
|
||||
end
|
@ -1,2 +0,0 @@
|
||||
module PeerHelper
|
||||
end
|
@ -37,15 +37,15 @@
|
||||
|
||||
<!-- top tiles -->
|
||||
<div class="row tile_count">
|
||||
<div class="animated flipInY col-md-2 col-sm-4 col-xs-4 tile_stats_count">
|
||||
<div class="animated flipInY col-md-2 col-sm-6 col-xs-6 tile_stats_count">
|
||||
<div class="left"></div>
|
||||
<div class="right">
|
||||
<span class="count_top"><i class="fa fa-clock-o"></i> Current signed in</span>
|
||||
<div class="count"><%= current_user.current_sign_in_at.strftime("%a, %H:%M") %></div>
|
||||
<span class="count_bottom"> From <i class="green"><%= current_user.current_sign_in_ip %></i></span>
|
||||
<span class="count_bottom"> From <i class="blue"><%= current_user.current_sign_in_ip %></i></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="animated flipInY col-md-2 col-sm-4 col-xs-4 tile_stats_count">
|
||||
<div class="animated flipInY col-md-2 col-sm-6 col-xs-6 tile_stats_count">
|
||||
<div class="left"></div>
|
||||
<div class="right">
|
||||
<span class="count_top"><i class="fa fa-clock-o"></i> Last signed in</span>
|
||||
@ -53,33 +53,40 @@
|
||||
<span class="count_bottom"> From <i class="red"><%= current_user.last_sign_in_ip %></i></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="animated flipInY col-md-2 col-sm-4 col-xs-4 tile_stats_count">
|
||||
<div class="animated flipInY col-md-2 col-sm-6 col-xs-6 tile_stats_count">
|
||||
<div class="left"></div>
|
||||
<div class="right">
|
||||
<span class="count_top"><i class="fa fa-user"></i> Members</span>
|
||||
<div class="count"><%= users.length %></div>
|
||||
<div class="count"><%= User.all.length %></div>
|
||||
<span class="count_bottom"><i class="green"><%= User.where(:last_sign_in_at => Date.today..Date.tomorrow).length %></i> user signed Today</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="animated flipInY col-md-2 col-sm-4 col-xs-4 tile_stats_count">
|
||||
<div class="animated flipInY col-md-2 col-sm-6 col-xs-6 tile_stats_count">
|
||||
<div class="left"></div>
|
||||
<div class="right">
|
||||
<span class="count_top"><i class="fa fa-cubes"></i> Total Nodes</span>
|
||||
<div class="count"><%= nodes.length %></div>
|
||||
<div class="count"><%= Node.all.length %></div>
|
||||
<span class="count_bottom"><i class="green"><%= Node.where(:created_at => Date.today..Date.tomorrow).length %></i> Node added Today</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="animated flipInY col-md-2 col-sm-4 col-xs-4 tile_stats_count">
|
||||
<div class="animated flipInY col-md-2 col-sm-6 col-xs-6 tile_stats_count">
|
||||
<div class="left"></div>
|
||||
<div class="right">
|
||||
<span class="count_top"><i class="fa fa-database"></i> Total volumes</span>
|
||||
<div class="count"><%= volumes.length %></div>
|
||||
<% v = volumes %>
|
||||
<div class="count"><%= v.length %></div>
|
||||
<span class="count_bottom">
|
||||
<i class="blue"><%= v.count{|x| x['Status'].eql? " Started"} %></i> started /
|
||||
<i class="green"><%= v.count{|x| x['Mount State'].eql? "mounted"} %></i> mounted
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="animated flipInY col-md-2 col-sm-4 col-xs-4 tile_stats_count">
|
||||
<div class="animated flipInY col-md-2 col-sm-6 col-xs-6 tile_stats_count">
|
||||
<div class="left"></div>
|
||||
<div class="right">
|
||||
<span class="count_top"><i class="fa fa-user"></i> Total Connections</span>
|
||||
<div class="count">7,325</div>
|
||||
<span class="count_bottom"><i class="green"><i class="fa fa-sort-asc"></i>34% </i> From last Week</span>
|
||||
<div class="count"><%= User.sum("sign_in_count") %></div>
|
||||
<span class="count_bottom"><i class="green"><%= User.where(:last_sign_in_at => Date.today..Date.tomorrow).sum("sign_in_count") %></i> connected today</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -17,7 +17,7 @@
|
||||
<div class="col-md-9 col-sm-9 col-xs-12">
|
||||
<select class="form-control">
|
||||
<% ['Distribute', 'Stripe', 'Replica', 'Disperse', 'Disperse-data', 'Redundancy'].each do |types|%>
|
||||
<option><%=types%></option>
|
||||
<option><%= types %></option>
|
||||
<% end %>
|
||||
</select>
|
||||
</div>
|
||||
@ -28,7 +28,7 @@
|
||||
<div class="col-md-9 col-sm-9 col-xs-12">
|
||||
<select class="form-control">
|
||||
<% for i in 1...11 do %>
|
||||
<option><%=i%></option>
|
||||
<option><%= i %></option>
|
||||
<% end %>
|
||||
</select>
|
||||
</div>
|
||||
@ -39,8 +39,8 @@
|
||||
</label>
|
||||
<div class="col-md-3 col-sm-3 col-xs-4">
|
||||
<select class="form-control">
|
||||
<% get_conf_all.each do |t| %>
|
||||
<option><%= t['host_name'] %></option>
|
||||
<% Node.all.each do |t| %>
|
||||
<option><%= t.host_name %></option>
|
||||
<% end %>
|
||||
</select>
|
||||
</div>
|
||||
@ -354,8 +354,8 @@
|
||||
new_body += "</label>";
|
||||
new_body += "<div class='col-md-3 col-sm-3 col-xs-4'>";
|
||||
new_body += "<select class='form-control'>";
|
||||
<% get_conf_all.each do |t| %>
|
||||
new_body += "<option><%= t['host_name'] %></option>";
|
||||
<% Node.all.each do |t| %>
|
||||
new_body += "<option><%= t.host_name %></option>";
|
||||
<% end %>
|
||||
new_body += "</select>";
|
||||
new_body += "</div>";
|
||||
|
Loading…
Reference in New Issue
Block a user