mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-17 18:33:32 +09:00
Feature #1611: New (provisional?) method oneuser defaultquota
This commit is contained in:
1 parent
2f17547e87
commit
0aa5df9b32
2 files changed
+85
-4
No files matched your search
@@ -96,12 +96,16 @@ class OneQuotaHelper
|
||||
# ]
|
||||
#
|
||||
# IMAGE = [
|
||||
# ID = <ID of the image>
|
||||
# RVMS = <Max. number of VMs using the image>
|
||||
# ID = <ID of the image>
|
||||
# RVMS = <Max. number of VMs using the image>
|
||||
# ]
|
||||
#
|
||||
# In any quota 0 means unlimited. The usage counters "*_USED" are
|
||||
# shown for information purposes and will NOT be modified.
|
||||
# In any quota:
|
||||
# -1 means use the default limit ('defaultquota' command)
|
||||
# 0 means unlimited.
|
||||
#
|
||||
# The usage counters "*_USED" are shown for information
|
||||
# purposes and will NOT be modified.
|
||||
#-----------------------------------------------------------------------
|
||||
EOT
|
||||
|
||||
@@ -152,6 +156,60 @@ class OneQuotaHelper
|
||||
str
|
||||
end
|
||||
|
||||
# Edits the default quota template of a pool
|
||||
# @param [Pool] resource to get the current info from
|
||||
# @param [String] root_elem the root element's name
|
||||
# @param [String] path to the new contents. If nil a editor will be
|
||||
# used
|
||||
# @return [String] contents of the new quotas
|
||||
def self.set_defaultquota(resource, root_elem, path)
|
||||
str = ""
|
||||
|
||||
if path.nil?
|
||||
require 'tempfile'
|
||||
|
||||
tmp = Tempfile.new('one-cli')
|
||||
path = tmp.path
|
||||
|
||||
|
||||
|
||||
default_xml_str = resource.get_quota()
|
||||
|
||||
if OpenNebula::is_error?(default_xml_str)
|
||||
puts default_xml_str.message
|
||||
exit -1
|
||||
end
|
||||
|
||||
default_quotas = XMLElement.new
|
||||
default_quotas.initialize_xml(default_xml_str, root_elem)
|
||||
|
||||
|
||||
tmp << HELP_QUOTA
|
||||
tmp << default_quotas.template_like_str("DATASTORE_QUOTA") << "\n"
|
||||
tmp << default_quotas.template_like_str("VM_QUOTA") << "\n"
|
||||
tmp << default_quotas.template_like_str("NETWORK_QUOTA") << "\n"
|
||||
tmp << default_quotas.template_like_str("IMAGE_QUOTA") << "\n"
|
||||
|
||||
tmp.close
|
||||
|
||||
editor_path = ENV["EDITOR"] ? ENV["EDITOR"] : EDITOR_PATH
|
||||
system("#{editor_path} #{path}")
|
||||
|
||||
unless $?.exitstatus == 0
|
||||
puts "Editor not defined"
|
||||
exit -1
|
||||
end
|
||||
|
||||
str = File.read(path)
|
||||
|
||||
File.unlink(path)
|
||||
else
|
||||
str = File.read(path)
|
||||
end
|
||||
|
||||
str
|
||||
end
|
||||
|
||||
# Retrieves a clean quota template, without any existing resource
|
||||
# information
|
||||
# @param path [String] path to the new contents. If nil a editor will be
|
||||
|
||||
@@ -237,6 +237,29 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
end
|
||||
end
|
||||
|
||||
defaultquota_desc = <<-EOT.unindent
|
||||
Sets the default quota limits for the users. If a path is not provided
|
||||
the editor will be launched to modify the current default quotas.
|
||||
EOT
|
||||
|
||||
command :defaultquota, defaultquota_desc, [:file, nil] do
|
||||
|
||||
# TODO: Do not create a new Client here
|
||||
# user_pool = factory_pool()
|
||||
user_pool = UserPool.new(Client.new)
|
||||
|
||||
str = OneQuotaHelper.set_defaultquota(user_pool, 'DEFAULT_USER_QUOTAS', args[1])
|
||||
|
||||
rc = user_pool.set_quota(str)
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
puts rc.message
|
||||
exit -1
|
||||
end
|
||||
|
||||
exit 0
|
||||
end
|
||||
|
||||
login_desc = <<-EOT.unindent
|
||||
Creates the Login token for authentication
|
||||
Examples:
|
||||
|
||||
Reference in new issue
Block a user