From a93ba1502d9bbb8d589db5049016a154e3f7236a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 5 Jul 2012 12:10:02 +0200 Subject: [PATCH] Feature #1285: Change the quotas output for oneuser and onegroup (cherry picked from commit 82cbf0ff6569029c1922994149f98c2532f947b4) --- src/cli/etc/onegroup.yaml | 13 +++-- src/cli/etc/oneuser.yaml | 12 ++--- src/cli/one_helper/onegroup_helper.rb | 31 +++++++---- src/cli/one_helper/onequota_helper.rb | 77 +++++++++------------------ src/cli/one_helper/oneuser_helper.rb | 18 ++++--- src/cli/one_helper/onevm_helper.rb | 2 +- 6 files changed, 72 insertions(+), 81 deletions(-) diff --git a/src/cli/etc/onegroup.yaml b/src/cli/etc/onegroup.yaml index 51b54d7042..45772a1ba9 100644 --- a/src/cli/etc/onegroup.yaml +++ b/src/cli/etc/onegroup.yaml @@ -5,24 +5,29 @@ :NAME: :desc: Name of the Group - :size: 25 + :size: 29 :left: true +:USERS: + :desc: Number of Users in this group + :size: 5 + :VMS: :desc: Number of VMS - :size: 6 + :size: 9 :MEMORY: :desc: Total memory allocated to user VMs - :size: 8 + :size: 17 :CPU: :desc: Total CPU allocated to user VMs - :size: 8 + :size: 11 :default: - :ID - :NAME +- :USERS - :VMS - :MEMORY - :CPU diff --git a/src/cli/etc/oneuser.yaml b/src/cli/etc/oneuser.yaml index c6b554681a..badfe58e43 100644 --- a/src/cli/etc/oneuser.yaml +++ b/src/cli/etc/oneuser.yaml @@ -5,30 +5,30 @@ :NAME: :desc: Name of the User - :size: 18 + :size: 15 :left: true :GROUP: :desc: Group of the User - :size: 15 + :size: 10 :left: true :AUTH: :desc: Auth driver of the User - :size: 15 + :size: 8 :left: true :VMS: :desc: Number of VMS - :size: 6 + :size: 9 :MEMORY: :desc: Total memory allocated to user VMs - :size: 8 + :size: 17 :CPU: :desc: Total CPU allocated to user VMs - :size: 8 + :size: 11 :PASSWORD: :desc: Password of the User diff --git a/src/cli/one_helper/onegroup_helper.rb b/src/cli/one_helper/onegroup_helper.rb index b2185d00cc..5722ffa7b0 100644 --- a/src/cli/one_helper/onegroup_helper.rb +++ b/src/cli/one_helper/onegroup_helper.rb @@ -53,35 +53,44 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper d["ID"] end - column :NAME, "Name of the Group", :left, :size=>25 do |d| + column :NAME, "Name of the Group", :left, :size=>29 do |d| d["NAME"] end - column :VMS, "Total number of VMS", :size=>6 do |d| - if d.has_key?('VM_QUOTA') and d['VM_QUOTA'].has_key?('VM') - d['VM_QUOTA']['VM']['VMS_USED'] + column :USERS, "Number of Users in this group", :size=>5 do |d| + if d["USERS"]["ID"].nil? + "0" else - "-" - end + d["USERS"]["ID"].size + end end - column :MEMORY, "Total memory allocated to group VMs", :size=>8 do |d| + column :VMS , "Number of VMS", :size=>9 do |d| if d.has_key?('VM_QUOTA') and d['VM_QUOTA'].has_key?('VM') - d['VM_QUOTA']['VM']['MEMORY_USED'] + "%3d / %3d" % [d['VM_QUOTA']['VM']["VMS_USED"], d['VM_QUOTA']['VM']["VMS"]] else "-" end end - column :CPU, "Total CPU allocated to group VMs", :size=>8 do |d| + 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') - d['VM_QUOTA']['VM']['CPU_USED'] + "%7s / %7s" % [OpenNebulaHelper.unit_to_str(d['VM_QUOTA']['VM']["MEMORY_USED"].to_i,{},"M"), + OpenNebulaHelper.unit_to_str(d['VM_QUOTA']['VM']["MEMORY"].to_i,{},"M")] else "-" end end - default :ID, :NAME, :VMS, :MEMORY, :CPU + 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') + "%4d / %4d" % [d['VM_QUOTA']['VM']["CPU_USED"], d['VM_QUOTA']['VM']["CPU"]] + else + "-" + end + end + + default :ID, :NAME, :USERS, :VMS, :MEMORY, :CPU end table diff --git a/src/cli/one_helper/onequota_helper.rb b/src/cli/one_helper/onequota_helper.rb index 20d0a37cc3..5e7a6e0266 100644 --- a/src/cli/one_helper/onequota_helper.rb +++ b/src/cli/one_helper/onequota_helper.rb @@ -24,78 +24,53 @@ class OneQuotaHelper # Tables to format user quotas #--------------------------------------------------------------------------- TABLE_DS = CLIHelper::ShowTable.new(nil, self) do - column :"DATASTORE ID", "", :left, :size=>12 do |d| + column :"DATASTORE ID", "", :size=>12 do |d| d["ID"] if !d.nil? end - column :"IMAGES (used)", "", :right, :size=>14 do |d| - d["IMAGES_USED"] if !d.nil? + column :"IMAGES", "", :right, :size=>20 do |d| + "%8d / %8d" % [d["IMAGES_USED"], d["IMAGES"]] if !d.nil? end - column :"IMAGES (limit)", "", :right, :size=>14 do |d| - d["IMAGES"] if !d.nil? - end - - column :"SIZE (used)", "", :right, :size=>14 do |d| - d["SIZE_USED"] if !d.nil? - end - - column :"SIZE (limit)", "", :right, :size=>14 do |d| - d["SIZE"] if !d.nil? + column :"SIZE", "", :right, :size=>19 do |d| + "%8s / %8s" % [OpenNebulaHelper.unit_to_str(d["SIZE_USED"].to_i,{},"M"), + OpenNebulaHelper.unit_to_str(d["SIZE"].to_i,{},"M")] if !d.nil? end end TABLE_NET = CLIHelper::ShowTable.new(nil, self) do - column :"NETWORK ID", "", :left, :size=>12 do |d| + column :"NETWORK ID", "", :size=>12 do |d| d["ID"] if !d.nil? end - column :"LEASES (used)", "", :right, :size=>14 do |d| - d["LEASES_USED"] if !d.nil? - end - - column :"LEASES (limit)", "", :right, :size=>14 do |d| - d["LEASES"] if !d.nil? + column :"LEASES", "", :right, :size=>20 do |d| + "%8d / %8d" % [d["LEASES_USED"], d["LEASES"]] if !d.nil? end end TABLE_VM = CLIHelper::ShowTable.new(nil, self) do - column :"VMS (used)", "", :left, :size=>12 do |d| - d["VMS_USED"] if !d.nil? + + column :"NUMBER OF VMS", "", :right, :size=>20 do |d| + "%8d / %8d" % [d["VMS_USED"], d["VMS"]] if !d.nil? end - column :"VMS (limit)", "", :left, :size=>12 do |d| - d["VMS"] if !d.nil? + column :"MEMORY", "", :right, :size=>20 do |d| + "%8s / %8s" % [OpenNebulaHelper.unit_to_str(d["MEMORY_USED"].to_i,{},"M"), + OpenNebulaHelper.unit_to_str(d["MEMORY"].to_i,{},"M")] if !d.nil? end - column :"MEMORY (used)", "", :right, :size=>14 do |d| - d["MEMORY_USED"] if !d.nil? - end - - column :"MEMORY (limit)", "", :right, :size=>14 do |d| - d["MEMORY"] if !d.nil? - end - - column :"CPU (used)", "", :right, :size=>14 do |d| - d["CPU_USED"] if !d.nil? - end - - column :"CPU (limit)", "", :right, :size=>14 do |d| - d["CPU"] if !d.nil? + column :"CPU", "", :right, :size=>20 do |d| + "%4d / %4d" % [d["CPU_USED"], d["CPU"]] if !d.nil? end end TABLE_IMG = CLIHelper::ShowTable.new(nil, self) do - column :"IMAGE ID", "", :left, :size=>12 do |d| + column :"IMAGE ID", "", :size=>12 do |d| d["ID"] if !d.nil? end - column :"RVMS (used)", "", :right, :size=>14 do |d| - d["RVMS_USED"] if !d.nil? - end - - column :"RVMS (limit)", "", :right, :size=>14 do |d| - d["RVMS"] if !d.nil? + column :"RUNNING VMS", "", :right, :size=>20 do |d| + "%8d / %8d" % [d["RVMS_USED"], d["RVMS"]] if !d.nil? end end @@ -189,18 +164,18 @@ class OneQuotaHelper puts - ds_quotas = [qh['DATASTORE_QUOTA']['DATASTORE']].flatten - if !ds_quotas[0].nil? - TABLE_DS.show(ds_quotas, {}) - puts - end - vm_quotas = [qh['VM_QUOTA']['VM']].flatten if !vm_quotas[0].nil? TABLE_VM.show(vm_quotas, {}) puts end + ds_quotas = [qh['DATASTORE_QUOTA']['DATASTORE']].flatten + if !ds_quotas[0].nil? + TABLE_DS.show(ds_quotas, {}) + puts + end + net_quotas = [qh['NETWORK_QUOTA']['NETWORK']].flatten if !net_quotas[0].nil? TABLE_NET.show(net_quotas, {}) diff --git a/src/cli/one_helper/oneuser_helper.rb b/src/cli/one_helper/oneuser_helper.rb index 6a8f2aed29..3e2869be86 100644 --- a/src/cli/one_helper/oneuser_helper.rb +++ b/src/cli/one_helper/oneuser_helper.rb @@ -152,37 +152,39 @@ class OneUserHelper < OpenNebulaHelper::OneHelper d["ID"] end - column :NAME, "Name of the User", :left, :size=>18 do |d| + column :NAME, "Name of the User", :left, :size=>15 do |d| d["NAME"] end - column :GROUP, "Group of the User", :left, :size=>15 do |d| + column :GROUP, "Group of the User", :left, :size=>10 do |d| helper.group_name(d, options) end - column :AUTH, "Auth driver of the User", :left, :size=>15 do |d| + column :AUTH, "Auth driver of the User", :left, :size=>8 do |d| d["AUTH_DRIVER"] end - column :VMS, "Number of VMS", :size=>6 do |d| + column :VMS , "Number of VMS", :size=>9 do |d| if d.has_key?('VM_QUOTA') and d['VM_QUOTA'].has_key?('VM') - d['VM_QUOTA']['VM']['VMS_USED'] + "%3d / %3d" % [d['VM_QUOTA']['VM']["VMS_USED"], d['VM_QUOTA']['VM']["VMS"]] else "-" end end - column :MEMORY, "Total memory allocated to user VMs", :size=>8 do |d| + 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') d['VM_QUOTA']['VM']['MEMORY_USED'] + "%7s / %7s" % [OpenNebulaHelper.unit_to_str(d['VM_QUOTA']['VM']["MEMORY_USED"].to_i,{},"M"), + OpenNebulaHelper.unit_to_str(d['VM_QUOTA']['VM']["MEMORY"].to_i,{},"M")] else "-" end end - column :CPU, "Total CPU allocated to user VMs", :size=>8 do |d| + 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') - d['VM_QUOTA']['VM']['CPU_USED'] + "%4d / %4d" % [d['VM_QUOTA']['VM']["CPU_USED"], d['VM_QUOTA']['VM']["CPU"]] else "-" end diff --git a/src/cli/one_helper/onevm_helper.rb b/src/cli/one_helper/onevm_helper.rb index 911b498515..7de8e51a32 100644 --- a/src/cli/one_helper/onevm_helper.rb +++ b/src/cli/one_helper/onevm_helper.rb @@ -235,7 +235,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper d["HOSTNAME"] end - column :REASON, "VM state change reason", :size=>6 do |d| + column :REASON, "VM state change reason", :left, :size=>6 do |d| VirtualMachine.get_reason d["REASON"] end