mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
feature #2371: fix bugs in CLI table renderer
This commit is contained in:
parent
93377e0ba6
commit
c5839f087b
@ -126,6 +126,31 @@ module CLIHelper
|
||||
puts
|
||||
end
|
||||
|
||||
module HashWithSearch
|
||||
def dsearch(path)
|
||||
stems=path.split('/')
|
||||
hash=self
|
||||
|
||||
stems.delete_if {|s| s.nil? || s.empty? }
|
||||
|
||||
stems.each do |stem|
|
||||
if Hash===hash
|
||||
if hash[stem]
|
||||
hash=hash[stem]
|
||||
else
|
||||
hash=nil
|
||||
break
|
||||
end
|
||||
else
|
||||
hash=nil
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
hash
|
||||
end
|
||||
end
|
||||
|
||||
class ShowTable
|
||||
require 'yaml'
|
||||
|
||||
@ -168,7 +193,23 @@ module CLIHelper
|
||||
|
||||
def show(data, options={})
|
||||
update_columns(options)
|
||||
print_table(data, options)
|
||||
|
||||
if Hash===data
|
||||
@data=data
|
||||
@data.extend(HashWithSearch)
|
||||
|
||||
pool=@data.keys.first
|
||||
return print_table(nil, options) if !pool
|
||||
|
||||
element=pool.split('_').first
|
||||
|
||||
pool_data=@data.dsearch("#{pool}/#{element}")
|
||||
pool_data=[pool_data].flatten if pool_data
|
||||
|
||||
print_table(pool_data, options)
|
||||
else
|
||||
print_table(data, options)
|
||||
end
|
||||
end
|
||||
|
||||
def top(options={}, &block)
|
||||
|
@ -431,14 +431,12 @@ EOT
|
||||
array=pool.get_hash
|
||||
return -1, array.message if OpenNebula.is_error?(array)
|
||||
|
||||
pool_to_array(array)
|
||||
array
|
||||
}
|
||||
else
|
||||
array=pool.get_hash
|
||||
return -1, array.message if OpenNebula.is_error?(array)
|
||||
|
||||
array=pool_to_array(array)
|
||||
|
||||
if options[:ids]
|
||||
array=array.select do |element|
|
||||
options[:ids].include? element['ID'].to_i
|
||||
|
@ -148,21 +148,27 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
|
||||
def format_pool(options)
|
||||
config_file = self.class.table_conf
|
||||
|
||||
prefix = '/USER_POOL/DEFAULT_USER_QUOTAS/'
|
||||
user_pool = @user_pool
|
||||
|
||||
quotas = user_pool.get_hash()['USER_POOL']['QUOTAS']
|
||||
quotas_hash = Hash.new
|
||||
|
||||
if (!quotas.nil?)
|
||||
quotas = [quotas].flatten
|
||||
|
||||
quotas.each do |q|
|
||||
quotas_hash[q['ID']] = q
|
||||
end
|
||||
end
|
||||
|
||||
table = CLIHelper::ShowTable.new(config_file, self) do
|
||||
def pool_default_quotas(path)
|
||||
@data.dsearch('/USER_POOL/DEFAULT_USER_QUOTAS/'+path)
|
||||
end
|
||||
|
||||
def quotas
|
||||
if !defined?(@quotas)
|
||||
quotas = @data.dsearch('USER_POOL/QUOTAS')
|
||||
@quotas = Hash.new
|
||||
|
||||
if (!quotas.nil?)
|
||||
quotas = [quotas].flatten
|
||||
|
||||
quotas.each do |q|
|
||||
@quotas[q['ID']] = q
|
||||
end
|
||||
end
|
||||
end
|
||||
@quotas
|
||||
end
|
||||
|
||||
column :ID, "ONE identifier for the User", :size=>4 do |d|
|
||||
d["ID"]
|
||||
end
|
||||
@ -181,11 +187,11 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
|
||||
|
||||
column :VMS , "Number of VMS", :size=>9 do |d|
|
||||
begin
|
||||
q = quotas_hash[d['ID']]
|
||||
q = quotas[d['ID']]
|
||||
limit = q['VM_QUOTA']['VM']["VMS"]
|
||||
|
||||
if limit == "-1"
|
||||
limit = user_pool["#{prefix}VM_QUOTA/VM/VMS"]
|
||||
limit = pool_default_quotas("VM_QUOTA/VM/VMS")
|
||||
limit = "0" if limit.nil? || limit == ""
|
||||
end
|
||||
|
||||
@ -198,11 +204,11 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
|
||||
|
||||
column :MEMORY, "Total memory allocated to user VMs", :size=>17 do |d|
|
||||
begin
|
||||
q = quotas_hash[d['ID']]
|
||||
q = quotas[d['ID']]
|
||||
limit = q['VM_QUOTA']['VM']["MEMORY"]
|
||||
|
||||
if limit == "-1"
|
||||
limit = user_pool["#{prefix}VM_QUOTA/VM/MEMORY"]
|
||||
limit = pool_default_quotas("VM_QUOTA/VM/MEMORY")
|
||||
limit = "0" if limit.nil? || limit == ""
|
||||
end
|
||||
|
||||
@ -216,11 +222,11 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
|
||||
|
||||
column :CPU, "Total CPU allocated to user VMs", :size=>11 do |d|
|
||||
begin
|
||||
q = quotas_hash[d['ID']]
|
||||
q = quotas[d['ID']]
|
||||
limit = q['VM_QUOTA']['VM']["CPU"]
|
||||
|
||||
if limit == "-1"
|
||||
limit = user_pool["#{prefix}VM_QUOTA/VM/CPU"]
|
||||
limit = pool_default_quotas("VM_QUOTA/VM/CPU")
|
||||
limit = "0" if limit.nil? || limit == ""
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user