From 0ec7d042f2902d87fffd18b1ef0464285853cdc5 Mon Sep 17 00:00:00 2001 From: Youngkyun Kim Date: Sat, 3 Sep 2016 10:54:41 +0000 Subject: [PATCH] Update and fix volume controller --- app/controllers/volume_controller.rb | 65 ++++++++++++++-------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/app/controllers/volume_controller.rb b/app/controllers/volume_controller.rb index c80214e..bc8c797 100644 --- a/app/controllers/volume_controller.rb +++ b/app/controllers/volume_controller.rb @@ -1,47 +1,49 @@ class VolumeController < ApplicationController - + def index - @config = get_conf - @volumes = Array.new - volume = Hash.new - file_directory("/mnt") + get_conf + info = get_info.split("\n") - if get_info.blank? + if info.blank? flash[:danger] = "Check Server" else - info = get_info.split("\n") - df = get_df - puts df - - for t in 1..(info.length-1) - if info[t].include? ":" - temp = info[t].split(":") - volume[temp[0]] = temp[1] - else - if df.include? volume['Volume Name'].delete(' ') - volume['Mount State'] = "Mounted" - else - volume['Mount State'] = "UnMounted" - end - puts volume['Volume Name'] + ": " + volume['Mount State'] - - @volumes << volume - volume = Hash.new - end - end - @volumes << volume - # puts @volumes + parse_info(info) end end + + def parse_info(info) + @volumes = Array.new + volume = Hash.new + df = get_df + + info.each do |t| + next if t.equal? info.first + + if t.include? ":" + temp = t.split(":") + volume[temp[0]] = temp[1] + else + if df.include? volume['Volume Name'].delete(' ') + volume['Mount State'] = "Mounted" + else + volume['Mount State'] = "UnMounted" + end + puts volume['Volume Name'] + ": " + volume['Mount State'] + + @volumes << volume + volume = Hash.new + end + end + @volumes << volume + + end def get_df - @config = get_conf return `df -P` end def get_info - @config = get_conf return `sshpass -p#{@config["host_password"]} ssh #{@config["host_port"]} #{@config["host_user"]}@#{@config["host_ip"]} gluster volume info` end @@ -52,16 +54,13 @@ class VolumeController < ApplicationController redirect_to '/volume/info' end - def volume_mount @config = get_conf volume_name = params[:volume_name] mount_point = params[:mount_point] volume_name = volume_name.delete(' ') 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