Feature #1611: Merge default quota and individual quota update methods

This commit is contained in:
Carlos Martín authored and Tino Vazquez committed 2012-12-21 11:13:57 +01:00
1 parent 0372820776
commit bd3178e922
3 files changed
+47 -55

No files matched your search

+2 -51
View File
@@ -110,8 +110,8 @@ class OneQuotaHelper
EOT
# Edits the quota template of a resource
# @param resource [PoolElement] to get the current info from
# @param path [String] path to the new contents. If nil a editor will be
# @param [XMLElement] resource to get the current info from
# @param [String] path to the new contents. If nil a editor will be
# used
# @return [String] contents of the new quotas
def self.set_quota(resource, path)
@@ -123,13 +123,6 @@ class OneQuotaHelper
tmp = Tempfile.new('one-cli')
path = tmp.path
rc = resource.info
if OpenNebula.is_error?(rc)
puts rc.message
exit -1
end
tmp << HELP_QUOTA
tmp << resource.template_like_str("DATASTORE_QUOTA") << "\n"
tmp << resource.template_like_str("VM_QUOTA") << "\n"
@@ -156,48 +149,6 @@ class OneQuotaHelper
str
end
# Edits the default quota template of a pool
#
# @param [XMLElement] default_quotas to get the current info from
# @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(default_quotas, path)
str = ""
if path.nil?
require 'tempfile'
tmp = Tempfile.new('one-cli')
path = tmp.path
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
+36
View File
@@ -109,6 +109,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do
command :quota, quota_desc, :groupid, [:file, nil] do
helper.perform_action(args[0], options, "modified") do |group|
rc = group.info
if OpenNebula.is_error?(rc)
puts rc.message
exit -1
end
str = OneQuotaHelper.set_quota(group, args[1])
rc = group.set_quota(str)
@@ -138,4 +145,33 @@ cmd=CommandParser::CmdParser.new(ARGV) do
end
end
end
defaultquota_desc = <<-EOT.unindent
Sets the default quota limits for the groups. 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
system = System.new(Client.new)
default_quotas = system.get_group_quotas()
if OpenNebula.is_error?(default_quotas)
puts default_quotas.message
exit(-1)
end
str = OneQuotaHelper.set_quota(default_quotas, args[1])
rc = system.set_group_quotas(str)
if OpenNebula.is_error?(rc)
puts rc.message
exit(-1)
end
exit 0
end
end
+9 -4
View File
@@ -206,6 +206,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do
command :quota, quota_desc, :userid, [:file, nil] do
helper.perform_action(args[0], options, "modified") do |user|
rc = user.info
if OpenNebula.is_error?(rc)
puts rc.message
exit -1
end
str = OneQuotaHelper.set_quota(user, args[1])
rc = user.set_quota(str)
@@ -213,7 +220,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do
puts rc.message
exit -1
end
end
end
@@ -243,7 +249,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do
EOT
command :defaultquota, defaultquota_desc, [:file, nil] do
# TODO: Do not create a new Client here
system = System.new(Client.new)
@@ -254,10 +259,10 @@ cmd=CommandParser::CmdParser.new(ARGV) do
exit(-1)
end
str = OneQuotaHelper.set_defaultquota(default_quotas, args[1])
str = OneQuotaHelper.set_quota(default_quotas, args[1])
rc = system.set_user_quotas(str)
if OpenNebula.is_error?(rc)
puts rc.message
exit(-1)