From 043a8a741088eed3d79d4044daa85cfbace8dc50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 16 Jan 2014 17:08:47 +0100 Subject: [PATCH] Feature #2632: Fix quotas for oneuser/group list --- src/cli/one_helper/onegroup_helper.rb | 40 ++++++++++++++++-------- src/cli/one_helper/oneuser_helper.rb | 44 ++++++++++++++++++--------- 2 files changed, 56 insertions(+), 28 deletions(-) diff --git a/src/cli/one_helper/onegroup_helper.rb b/src/cli/one_helper/onegroup_helper.rb index ed56106308..0444e5bdee 100644 --- a/src/cli/one_helper/onegroup_helper.rb +++ b/src/cli/one_helper/onegroup_helper.rb @@ -65,6 +65,15 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper prefix = '/GROUP_POOL/DEFAULT_GROUP_QUOTAS/' group_pool = @group_pool + quotas = group_pool.to_hash()['GROUP_POOL']['QUOTAS'] + quotas_hash = Hash.new + + if (!quotas.nil?) + quotas.each do |q| + quotas_hash[q['ID']] = q + end + end + table = CLIHelper::ShowTable.new(config_file, self) do column :ID, "ONE identifier for the Group", :size=>4 do |d| d["ID"] @@ -88,48 +97,53 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper end column :VMS , "Number of VMS", :size=>9 do |d| - if d.has_key?('VM_QUOTA') and d['VM_QUOTA'].has_key?('VM') - limit = d['VM_QUOTA']['VM']["VMS"] + begin + q = quotas_hash[d['ID']] + limit = q['VM_QUOTA']['VM']["VMS"] if limit == "-1" limit = group_pool["#{prefix}VM_QUOTA/VM/VMS"] limit = "0" if limit.nil? || limit == "" end - "%3d / %3d" % [d['VM_QUOTA']['VM']["VMS_USED"], limit] - else + "%3d / %3d" % [q['VM_QUOTA']['VM']["VMS_USED"], limit] + + rescue NoMethodError "-" end end column :MEMORY, "Total memory allocated to user VMs", :size=>17 do |d| - if d.has_key?('VM_QUOTA') and d['VM_QUOTA'].has_key?('VM') - limit = d['VM_QUOTA']['VM']["MEMORY"] + begin + q = quotas_hash[d['ID']] + limit = q['VM_QUOTA']['VM']["MEMORY"] if limit == "-1" limit = group_pool["#{prefix}VM_QUOTA/VM/MEMORY"] limit = "0" if limit.nil? || limit == "" end - d['VM_QUOTA']['VM']['MEMORY_USED'] - "%7s / %7s" % [OpenNebulaHelper.unit_to_str(d['VM_QUOTA']['VM']["MEMORY_USED"].to_i,{},"M"), + "%7s / %7s" % [OpenNebulaHelper.unit_to_str(q['VM_QUOTA']['VM']["MEMORY_USED"].to_i,{},"M"), OpenNebulaHelper.unit_to_str(limit.to_i,{},"M")] - else + + rescue NoMethodError "-" end end column :CPU, "Total CPU allocated to user VMs", :size=>11 do |d| - if d.has_key?('VM_QUOTA') and d['VM_QUOTA'].has_key?('VM') - limit = d['VM_QUOTA']['VM']["CPU"] + begin + q = quotas_hash[d['ID']] + limit = q['VM_QUOTA']['VM']["CPU"] if limit == "-1" limit = group_pool["#{prefix}VM_QUOTA/VM/CPU"] limit = "0" if limit.nil? || limit == "" end - "%3.1f / %3.1f" % [d['VM_QUOTA']['VM']["CPU_USED"], limit] - else + "%3.1f / %3.1f" % [q['VM_QUOTA']['VM']["CPU_USED"], limit] + + rescue NoMethodError "-" end end diff --git a/src/cli/one_helper/oneuser_helper.rb b/src/cli/one_helper/oneuser_helper.rb index 6b10072da1..dc4c730492 100644 --- a/src/cli/one_helper/oneuser_helper.rb +++ b/src/cli/one_helper/oneuser_helper.rb @@ -151,6 +151,15 @@ class OneUserHelper < OpenNebulaHelper::OneHelper prefix = '/USER_POOL/DEFAULT_USER_QUOTAS/' user_pool = @user_pool + quotas = user_pool.to_hash()['USER_POOL']['QUOTAS'] + quotas_hash = Hash.new + + if (!quotas.nil?) + quotas.each do |q| + quotas_hash[q['ID']] = q + end + end + table = CLIHelper::ShowTable.new(config_file, self) do column :ID, "ONE identifier for the User", :size=>4 do |d| d["ID"] @@ -168,49 +177,54 @@ class OneUserHelper < OpenNebulaHelper::OneHelper d["AUTH_DRIVER"] end - column :VMS , "Number of VMS", :size=>9 do |d| - if d.has_key?('VM_QUOTA') and d['VM_QUOTA'].has_key?('VM') - limit = d['VM_QUOTA']['VM']["VMS"] + column :VMS , "Number of VMS", :size=>9 do |d| + begin + q = quotas_hash[d['ID']] + limit = q['VM_QUOTA']['VM']["VMS"] if limit == "-1" limit = user_pool["#{prefix}VM_QUOTA/VM/VMS"] limit = "0" if limit.nil? || limit == "" end - "%3d / %3d" % [d['VM_QUOTA']['VM']["VMS_USED"], limit] - else + "%3d / %3d" % [q['VM_QUOTA']['VM']["VMS_USED"], limit] + + rescue NoMethodError "-" - end + end end column :MEMORY, "Total memory allocated to user VMs", :size=>17 do |d| - if d.has_key?('VM_QUOTA') and d['VM_QUOTA'].has_key?('VM') - limit = d['VM_QUOTA']['VM']["MEMORY"] + begin + q = quotas_hash[d['ID']] + limit = q['VM_QUOTA']['VM']["MEMORY"] if limit == "-1" limit = user_pool["#{prefix}VM_QUOTA/VM/MEMORY"] limit = "0" if limit.nil? || limit == "" end - d['VM_QUOTA']['VM']['MEMORY_USED'] - "%7s / %7s" % [OpenNebulaHelper.unit_to_str(d['VM_QUOTA']['VM']["MEMORY_USED"].to_i,{},"M"), + "%7s / %7s" % [OpenNebulaHelper.unit_to_str(q['VM_QUOTA']['VM']["MEMORY_USED"].to_i,{},"M"), OpenNebulaHelper.unit_to_str(limit.to_i,{},"M")] - else + + rescue NoMethodError "-" end end column :CPU, "Total CPU allocated to user VMs", :size=>11 do |d| - if d.has_key?('VM_QUOTA') and d['VM_QUOTA'].has_key?('VM') - limit = d['VM_QUOTA']['VM']["CPU"] + begin + q = quotas_hash[d['ID']] + limit = q['VM_QUOTA']['VM']["CPU"] if limit == "-1" limit = user_pool["#{prefix}VM_QUOTA/VM/CPU"] limit = "0" if limit.nil? || limit == "" end - "%3.1f / %3.1f" % [d['VM_QUOTA']['VM']["CPU_USED"], limit] - else + "%3.1f / %3.1f" % [q['VM_QUOTA']['VM']["CPU_USED"], limit] + + rescue NoMethodError "-" end end