diff --git a/src/cli/one_helper/onequota_helper.rb b/src/cli/one_helper/onequota_helper.rb index ca1d71b1e9..61974bf76c 100644 --- a/src/cli/one_helper/onequota_helper.rb +++ b/src/cli/one_helper/onequota_helper.rb @@ -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 diff --git a/src/cli/onegroup b/src/cli/onegroup index 6fc81e561e..5426d0e5ef 100755 --- a/src/cli/onegroup +++ b/src/cli/onegroup @@ -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 diff --git a/src/cli/oneuser b/src/cli/oneuser index ef31f13f10..7b47e99938 100755 --- a/src/cli/oneuser +++ b/src/cli/oneuser @@ -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)