From 2f17547e878ef704de495017460eb5c554bbd79b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 23 Nov 2012 18:28:09 +0100 Subject: [PATCH] Feature #1611: Show the default quotas limit in oneuser/group list --- src/cli/one_helper/onegroup_helper.rb | 38 ++++++++++++++++++++++++--- src/cli/one_helper/oneuser_helper.rb | 37 +++++++++++++++++++++++--- src/oca/ruby/OpenNebula/XMLUtils.rb | 18 ++++++++----- 3 files changed, 81 insertions(+), 12 deletions(-) diff --git a/src/cli/one_helper/onegroup_helper.rb b/src/cli/one_helper/onegroup_helper.rb index 1737f250a0..3f1fc3e1de 100644 --- a/src/cli/one_helper/onegroup_helper.rb +++ b/src/cli/one_helper/onegroup_helper.rb @@ -48,6 +48,16 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper def format_pool(options) config_file = self.class.table_conf + gpool = GroupPool.new(@client) + default_xml_str = gpool.get_quota() + + # TODO: check error +# if OpenNebula::is_error?(default_xml_str) +# end + + default_user_quotas = XMLElement.new + default_user_quotas.initialize_xml(default_xml_str, 'DEFAULT_GROUP_QUOTAS') + table = CLIHelper::ShowTable.new(config_file, self) do column :ID, "ONE identifier for the Group", :size=>4 do |d| d["ID"] @@ -67,7 +77,14 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper column :VMS , "Number of VMS", :size=>9 do |d| if d.has_key?('VM_QUOTA') and d['VM_QUOTA'].has_key?('VM') - "%3d / %3d" % [d['VM_QUOTA']['VM']["VMS_USED"], d['VM_QUOTA']['VM']["VMS"]] + limit = d['VM_QUOTA']['VM']["VMS"] + + if limit == "-1" + limit = default_user_quotas['VM_QUOTA/VM/VMS'] + limit = "0" if limit.nil? || limit == "" + end + + "%3d / %3d" % [d['VM_QUOTA']['VM']["VMS_USED"], limit] else "-" end @@ -75,8 +92,16 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper 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"] + + if limit == "-1" + limit = default_user_quotas['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"), - OpenNebulaHelper.unit_to_str(d['VM_QUOTA']['VM']["MEMORY"].to_i,{},"M")] + OpenNebulaHelper.unit_to_str(limit.to_i,{},"M")] else "-" end @@ -84,7 +109,14 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper 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') - "%4.0f / %4.0f" % [d['VM_QUOTA']['VM']["CPU_USED"], d['VM_QUOTA']['VM']["CPU"]] + limit = d['VM_QUOTA']['VM']["CPU"] + + if limit == "-1" + limit = default_user_quotas['VM_QUOTA/VM/CPU'] + limit = "0" if limit.nil? || limit == "" + end + + "%4.0f / %4.0f" % [d['VM_QUOTA']['VM']["CPU_USED"], limit] else "-" end diff --git a/src/cli/one_helper/oneuser_helper.rb b/src/cli/one_helper/oneuser_helper.rb index 70a5f38aaf..7f879d3bd7 100644 --- a/src/cli/one_helper/oneuser_helper.rb +++ b/src/cli/one_helper/oneuser_helper.rb @@ -147,6 +147,16 @@ class OneUserHelper < OpenNebulaHelper::OneHelper def format_pool(options) config_file = self.class.table_conf + upool = UserPool.new(@client) + default_xml_str = upool.get_quota() + + # TODO: check error +# if OpenNebula::is_error?(default_xml_str) +# end + + default_user_quotas = XMLElement.new + default_user_quotas.initialize_xml(default_xml_str, 'DEFAULT_USER_QUOTAS') + table = CLIHelper::ShowTable.new(config_file, self) do column :ID, "ONE identifier for the User", :size=>4 do |d| d["ID"] @@ -166,7 +176,14 @@ class OneUserHelper < OpenNebulaHelper::OneHelper column :VMS , "Number of VMS", :size=>9 do |d| if d.has_key?('VM_QUOTA') and d['VM_QUOTA'].has_key?('VM') - "%3d / %3d" % [d['VM_QUOTA']['VM']["VMS_USED"], d['VM_QUOTA']['VM']["VMS"]] + limit = d['VM_QUOTA']['VM']["VMS"] + + if limit == "-1" + limit = default_user_quotas['VM_QUOTA/VM/VMS'] + limit = "0" if limit.nil? || limit == "" + end + + "%3d / %3d" % [d['VM_QUOTA']['VM']["VMS_USED"], limit] else "-" end @@ -174,9 +191,16 @@ class OneUserHelper < OpenNebulaHelper::OneHelper 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"] + + if limit == "-1" + limit = default_user_quotas['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"), - OpenNebulaHelper.unit_to_str(d['VM_QUOTA']['VM']["MEMORY"].to_i,{},"M")] + OpenNebulaHelper.unit_to_str(limit.to_i,{},"M")] else "-" end @@ -184,7 +208,14 @@ class OneUserHelper < OpenNebulaHelper::OneHelper 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') - "%4.0f / %4.0f" % [d['VM_QUOTA']['VM']["CPU_USED"], d['VM_QUOTA']['VM']["CPU"]] + limit = d['VM_QUOTA']['VM']["CPU"] + + if limit == "-1" + limit = default_user_quotas['VM_QUOTA/VM/CPU'] + limit = "0" if limit.nil? || limit == "" + end + + "%4.0f / %4.0f" % [d['VM_QUOTA']['VM']["CPU_USED"], limit] else "-" end diff --git a/src/oca/ruby/OpenNebula/XMLUtils.rb b/src/oca/ruby/OpenNebula/XMLUtils.rb index 13100fafdf..9a244312c0 100644 --- a/src/oca/ruby/OpenNebula/XMLUtils.rb +++ b/src/oca/ruby/OpenNebula/XMLUtils.rb @@ -79,12 +79,18 @@ module OpenNebula return doc end - # Extract an element from the XML description of the PoolElement. - # key::_String_ The name of the element - # [return] _String_ the value of the element - # Examples: - # ['VID'] # gets VM id - # ['HISTORY/HOSTNAME'] # get the hostname from the history + + # Extract a text element from the XML description of the PoolElement. + # + # @param [String] key Xpath expression + # + # @return [String, nil] If a text element is found, the element's + # text value. Otherwise, an empty string or nil, depending + # on the backend + # + # @example + # vm['VID'] # gets VM id + # vm['HISTORY/HOSTNAME'] # get the hostname from the history def [](key) if NOKOGIRI element=@xml.xpath(key.to_s)