From 0aa5df9b3299e6d9399bbf6ed214d4e15180df5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 23 Nov 2012 18:48:09 +0100 Subject: [PATCH] Feature #1611: New (provisional?) method oneuser defaultquota --- src/cli/one_helper/onequota_helper.rb | 66 +++++++++++++++++++++++++-- src/cli/oneuser | 23 ++++++++++ 2 files changed, 85 insertions(+), 4 deletions(-) diff --git a/src/cli/one_helper/onequota_helper.rb b/src/cli/one_helper/onequota_helper.rb index f448389586..960e5f2631 100644 --- a/src/cli/one_helper/onequota_helper.rb +++ b/src/cli/one_helper/onequota_helper.rb @@ -96,12 +96,16 @@ class OneQuotaHelper # ] # # IMAGE = [ - # ID = - # RVMS = + # ID = + # RVMS = # ] # - # 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 diff --git a/src/cli/oneuser b/src/cli/oneuser index 5973f6e2ee..80a74dc1cd 100755 --- a/src/cli/oneuser +++ b/src/cli/oneuser @@ -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: