1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-10 00:58:17 +03:00

Feature #2964: unlimited quota is now -2, in CLI

This commit is contained in:
Carlos Martín 2014-07-03 12:30:42 +02:00
parent 1b668757fe
commit f1fd63bef6
3 changed files with 117 additions and 42 deletions

View File

@ -110,12 +110,16 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
q = quotas[d['ID']]
limit = q['VM_QUOTA']['VM']["VMS"]
if limit == "-1"
if limit == OneQuotaHelper::LIMIT_DEFAULT
limit = pool_default_quotas("VM_QUOTA/VM/VMS")
limit = "0" if limit.nil? || limit == ""
limit = OneQuotaHelper::LIMIT_UNLIMITED if limit.nil? || limit == ""
end
"%3d / %3d" % [q['VM_QUOTA']['VM']["VMS_USED"], limit]
if limit == OneQuotaHelper::LIMIT_UNLIMITED
"%3d / -" % [q['VM_QUOTA']['VM']["VMS_USED"]]
else
"%3d / %3d" % [q['VM_QUOTA']['VM']["VMS_USED"], limit]
end
rescue NoMethodError
"-"
@ -127,13 +131,19 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
q = quotas[d['ID']]
limit = q['VM_QUOTA']['VM']["MEMORY"]
if limit == "-1"
if limit == OneQuotaHelper::LIMIT_DEFAULT
limit = pool_default_quotas("VM_QUOTA/VM/MEMORY")
limit = "0" if limit.nil? || limit == ""
limit = OneQuotaHelper::LIMIT_UNLIMITED if limit.nil? || limit == ""
end
"%7s / %7s" % [OpenNebulaHelper.unit_to_str(q['VM_QUOTA']['VM']["MEMORY_USED"].to_i,{},"M"),
OpenNebulaHelper.unit_to_str(limit.to_i,{},"M")]
if limit == OneQuotaHelper::LIMIT_UNLIMITED
"%7s / -" % [
OpenNebulaHelper.unit_to_str(q['VM_QUOTA']['VM']["MEMORY_USED"].to_i,{},"M")]
else
"%7s / %7s" % [
OpenNebulaHelper.unit_to_str(q['VM_QUOTA']['VM']["MEMORY_USED"].to_i,{},"M"),
OpenNebulaHelper.unit_to_str(limit.to_i,{},"M")]
end
rescue NoMethodError
"-"
@ -145,12 +155,16 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
q = quotas[d['ID']]
limit = q['VM_QUOTA']['VM']["CPU"]
if limit == "-1"
if limit == OneQuotaHelper::LIMIT_DEFAULT
limit = pool_default_quotas("VM_QUOTA/VM/CPU")
limit = "0" if limit.nil? || limit == ""
limit = OneQuotaHelper::LIMIT_UNLIMITED if limit.nil? || limit == ""
end
"%3.1f / %3.1f" % [q['VM_QUOTA']['VM']["CPU_USED"], limit]
if limit == OneQuotaHelper::LIMIT_UNLIMITED
"%3.1f / -" % [q['VM_QUOTA']['VM']["CPU_USED"]]
else
"%3.1f / %3.1f" % [q['VM_QUOTA']['VM']["CPU_USED"], limit]
end
rescue NoMethodError
"-"

View File

@ -18,6 +18,9 @@ require 'cli_helper'
class OneQuotaHelper
LIMIT_DEFAULT = "-1"
LIMIT_UNLIMITED = "-2"
EDITOR_PATH='/usr/bin/vi'
HELP_QUOTA = <<-EOT.unindent
@ -52,7 +55,7 @@ class OneQuotaHelper
#
# In any quota:
# -1 means use the default limit (set with the 'defaultquota' command)
# 0 means unlimited.
# -2 means unlimited.
#
# The usage counters "*_USED" are shown for information
# purposes and will NOT be modified.
@ -62,7 +65,7 @@ class OneQuotaHelper
HELP_DEFAULT_QUOTA_FOOTER = <<-EOT.unindent
#
# In any quota:
# 0 means unlimited.
# -2 means unlimited.
#
# The usage counters "*_USED" will always be 0 for the default
# quotas, and can be ignored.
@ -209,7 +212,11 @@ class OneQuotaHelper
limit = helper.get_default_limit(
limit, "VM_QUOTA/VM/#{elem}")
"%7d / %7d" % [d["VMS_USED"], limit]
if limit == LIMIT_UNLIMITED
"%7d / -" % [d["VMS_USED"]]
else
"%7d / %7d" % [d["VMS_USED"], limit]
end
end
end
@ -220,10 +227,16 @@ class OneQuotaHelper
limit = helper.get_default_limit(
limit, "VM_QUOTA/VM/#{elem}")
"%8s / %8s" % [
OpenNebulaHelper.unit_to_str(d["MEMORY_USED"].to_i,{},"M"),
OpenNebulaHelper.unit_to_str(limit.to_i,{},"M")
]
if limit == LIMIT_UNLIMITED
"%8s / -" % [
OpenNebulaHelper.unit_to_str(d["MEMORY_USED"].to_i,{},"M")
]
else
"%8s / %8s" % [
OpenNebulaHelper.unit_to_str(d["MEMORY_USED"].to_i,{},"M"),
OpenNebulaHelper.unit_to_str(limit.to_i,{},"M")
]
end
end
end
@ -234,7 +247,11 @@ class OneQuotaHelper
limit = helper.get_default_limit(
limit, "VM_QUOTA/VM/#{elem}")
"%8.2f / %8.2f" % [d["CPU_USED"], limit]
if limit == LIMIT_UNLIMITED
"%8.2f / -" % [d["CPU_USED"]]
else
"%8.2f / %8.2f" % [d["CPU_USED"], limit]
end
end
end
@ -245,10 +262,16 @@ class OneQuotaHelper
limit = helper.get_default_limit(
limit, "VM_QUOTA/VM/#{elem}")
"%8s / %8s" % [
OpenNebulaHelper.unit_to_str(d["VOLATILE_SIZE_USED"].to_i,{},"M"),
OpenNebulaHelper.unit_to_str(limit.to_i,{},"M")
]
if limit == LIMIT_UNLIMITED
"%8s / -" % [
OpenNebulaHelper.unit_to_str(d["VOLATILE_SIZE_USED"].to_i,{},"M")
]
else
"%8s / %8s" % [
OpenNebulaHelper.unit_to_str(d["VOLATILE_SIZE_USED"].to_i,{},"M"),
OpenNebulaHelper.unit_to_str(limit.to_i,{},"M")
]
end
end
end
end.show(vm_quotas, {})
@ -271,7 +294,11 @@ class OneQuotaHelper
limit = helper.get_default_limit(
limit, "DATASTORE_QUOTA/DATASTORE[ID=#{d['ID']}]/#{elem}")
"%8d / %8d" % [d["IMAGES_USED"], limit]
if limit == LIMIT_UNLIMITED
"%8d / -" % [d["IMAGES_USED"]]
else
"%8d / %8d" % [d["IMAGES_USED"], limit]
end
end
end
@ -282,10 +309,16 @@ class OneQuotaHelper
limit = helper.get_default_limit(
limit, "DATASTORE_QUOTA/DATASTORE[ID=#{d['ID']}]/#{elem}")
"%8s / %8s" % [
OpenNebulaHelper.unit_to_str(d["SIZE_USED"].to_i,{},"M"),
OpenNebulaHelper.unit_to_str(limit.to_i,{},"M")
]
if limit == LIMIT_UNLIMITED
"%8s / -" % [
OpenNebulaHelper.unit_to_str(d["SIZE_USED"].to_i,{},"M")
]
else
"%8s / %8s" % [
OpenNebulaHelper.unit_to_str(d["SIZE_USED"].to_i,{},"M"),
OpenNebulaHelper.unit_to_str(limit.to_i,{},"M")
]
end
end
end
end.show(ds_quotas, {})
@ -308,7 +341,11 @@ class OneQuotaHelper
limit = helper.get_default_limit(
limit, "NETWORK_QUOTA/NETWORK[ID=#{d['ID']}]/#{elem}")
"%8d / %8d" % [d["LEASES_USED"], limit]
if limit == LIMIT_UNLIMITED
"%8d / -" % [d["LEASES_USED"]]
else
"%8d / %8d" % [d["LEASES_USED"], limit]
end
end
end
end.show(net_quotas, {})
@ -331,7 +368,11 @@ class OneQuotaHelper
limit = helper.get_default_limit(
limit, "IMAGE_QUOTA/IMAGE[ID=#{d['ID']}]/RVMS")
"%8d / %8d" % [d["RVMS_USED"], limit]
if limit == LIMIT_UNLIMITED
"%8d / -" % [d["RVMS_USED"]]
else
"%8d / %8d" % [d["RVMS_USED"], limit]
end
end
end
end.show(image_quotas, {})
@ -339,13 +380,13 @@ class OneQuotaHelper
end
def get_default_limit(limit, xpath)
if limit == "-1"
if limit == LIMIT_DEFAULT
if !@default_quotas.nil?
limit = @default_quotas[xpath]
limit = "0" if limit.nil? || limit == ""
limit = LIMIT_UNLIMITED if limit.nil? || limit == ""
else
limit = "0"
limit = LIMIT_UNLIMITED
end
end

View File

@ -190,12 +190,18 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
q = quotas[d['ID']]
limit = q['VM_QUOTA']['VM']["VMS"]
if limit == "-1"
if limit == OneQuotaHelper::LIMIT_DEFAULT
limit = pool_default_quotas("VM_QUOTA/VM/VMS")
limit = "0" if limit.nil? || limit == ""
if limit.nil? || limit == ""
limit = OneQuotaHelper::LIMIT_UNLIMITED
end
end
"%3d / %3d" % [q['VM_QUOTA']['VM']["VMS_USED"], limit]
if limit == OneQuotaHelper::LIMIT_UNLIMITED
"%3d / -" % [q['VM_QUOTA']['VM']["VMS_USED"]]
else
"%3d / %3d" % [q['VM_QUOTA']['VM']["VMS_USED"], limit]
end
rescue NoMethodError
"-"
@ -207,13 +213,21 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
q = quotas[d['ID']]
limit = q['VM_QUOTA']['VM']["MEMORY"]
if limit == "-1"
if limit == OneQuotaHelper::LIMIT_DEFAULT
limit = pool_default_quotas("VM_QUOTA/VM/MEMORY")
limit = "0" if limit.nil? || limit == ""
if limit.nil? || limit == ""
limit = OneQuotaHelper::LIMIT_UNLIMITED
end
end
"%7s / %7s" % [OpenNebulaHelper.unit_to_str(q['VM_QUOTA']['VM']["MEMORY_USED"].to_i,{},"M"),
OpenNebulaHelper.unit_to_str(limit.to_i,{},"M")]
if limit == OneQuotaHelper::LIMIT_UNLIMITED
"%7s / -" % [
OpenNebulaHelper.unit_to_str(q['VM_QUOTA']['VM']["MEMORY_USED"].to_i,{},"M")]
else
"%7s / %7s" % [
OpenNebulaHelper.unit_to_str(q['VM_QUOTA']['VM']["MEMORY_USED"].to_i,{},"M"),
OpenNebulaHelper.unit_to_str(limit.to_i,{},"M")]
end
rescue NoMethodError
"-"
@ -225,12 +239,18 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
q = quotas[d['ID']]
limit = q['VM_QUOTA']['VM']["CPU"]
if limit == "-1"
if limit == OneQuotaHelper::LIMIT_DEFAULT
limit = pool_default_quotas("VM_QUOTA/VM/CPU")
limit = "0" if limit.nil? || limit == ""
if limit.nil? || limit == ""
limit = OneQuotaHelper::LIMIT_UNLIMITED
end
end
"%3.1f / %3.1f" % [q['VM_QUOTA']['VM']["CPU_USED"], limit]
if limit == OneQuotaHelper::LIMIT_UNLIMITED
"%3.1f / -" % [q['VM_QUOTA']['VM']["CPU_USED"]]
else
"%3.1f / %3.1f" % [q['VM_QUOTA']['VM']["CPU_USED"], limit]
end
rescue NoMethodError
"-"