Feature #1611: Show the default quotas limit in oneuser/group list

This commit is contained in:
Carlos Martín authored and Tino Vazquez committed 2012-12-21 11:13:53 +01:00
1 parent 9cc2c8f897
commit 2f17547e87
3 files changed
+81 -12

No files matched your search

+35 -3
View File
@@ -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
+34 -3
View File
@@ -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
+12 -6
View File
@@ -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)