mirror of
https://github.com/OpenNebula/one.git
synced 2025-02-04 17:47:00 +03:00
Feature #1611: Move default quotas ruby oca methods to new class System
This commit is contained in:
parent
3cbcc77b9d
commit
f3ca471b60
@ -1108,7 +1108,8 @@ RUBY_OPENNEBULA_LIB_FILES="src/oca/ruby/OpenNebula/Host.rb \
|
||||
src/oca/ruby/OpenNebula/DatastorePool.rb \
|
||||
src/oca/ruby/OpenNebula/Cluster.rb \
|
||||
src/oca/ruby/OpenNebula/ClusterPool.rb \
|
||||
src/oca/ruby/OpenNebula/XMLUtils.rb"
|
||||
src/oca/ruby/OpenNebula/XMLUtils.rb \
|
||||
src/oca/ruby/OpenNebula/System.rb"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Common Cloud Files
|
||||
|
@ -48,16 +48,13 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
|
||||
def format_pool(options)
|
||||
config_file = self.class.table_conf
|
||||
|
||||
gpool = GroupPool.new(@client)
|
||||
default_xml_str = gpool.get_quota()
|
||||
system = System.new(@client)
|
||||
default_quotas = system.get_group_quotas()
|
||||
|
||||
# TODO: check error
|
||||
# if OpenNebula::is_error?(default_xml_str)
|
||||
# end
|
||||
|
||||
default_user_quotas = XMLElement.new
|
||||
default_user_quotas.initialize_xml(default_xml_str, 'DEFAULT_GROUP_QUOTAS')
|
||||
|
||||
table = CLIHelper::ShowTable.new(config_file, self) do
|
||||
column :ID, "ONE identifier for the Group", :size=>4 do |d|
|
||||
d["ID"]
|
||||
@ -80,7 +77,7 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
|
||||
limit = d['VM_QUOTA']['VM']["VMS"]
|
||||
|
||||
if limit == "-1"
|
||||
limit = default_user_quotas['VM_QUOTA/VM/VMS']
|
||||
limit = default_quotas['VM_QUOTA/VM/VMS']
|
||||
limit = "0" if limit.nil? || limit == ""
|
||||
end
|
||||
|
||||
@ -95,7 +92,7 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
|
||||
limit = d['VM_QUOTA']['VM']["MEMORY"]
|
||||
|
||||
if limit == "-1"
|
||||
limit = default_user_quotas['VM_QUOTA/VM/MEMORY']
|
||||
limit = default_quotas['VM_QUOTA/VM/MEMORY']
|
||||
limit = "0" if limit.nil? || limit == ""
|
||||
end
|
||||
|
||||
@ -112,7 +109,7 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
|
||||
limit = d['VM_QUOTA']['VM']["CPU"]
|
||||
|
||||
if limit == "-1"
|
||||
limit = default_user_quotas['VM_QUOTA/VM/CPU']
|
||||
limit = default_quotas['VM_QUOTA/VM/CPU']
|
||||
limit = "0" if limit.nil? || limit == ""
|
||||
end
|
||||
|
||||
|
@ -156,13 +156,14 @@ 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)
|
||||
# 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?
|
||||
@ -171,19 +172,6 @@ class OneQuotaHelper
|
||||
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"
|
||||
|
@ -147,16 +147,13 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
|
||||
def format_pool(options)
|
||||
config_file = self.class.table_conf
|
||||
|
||||
upool = UserPool.new(@client)
|
||||
default_xml_str = upool.get_quota()
|
||||
system = System.new(@client)
|
||||
default_quotas = system.get_user_quotas()
|
||||
|
||||
# TODO: check error
|
||||
# if OpenNebula::is_error?(default_xml_str)
|
||||
# if OpenNebula::is_error?(default_quotas)
|
||||
# end
|
||||
|
||||
default_user_quotas = XMLElement.new
|
||||
default_user_quotas.initialize_xml(default_xml_str, 'DEFAULT_USER_QUOTAS')
|
||||
|
||||
table = CLIHelper::ShowTable.new(config_file, self) do
|
||||
column :ID, "ONE identifier for the User", :size=>4 do |d|
|
||||
d["ID"]
|
||||
@ -179,7 +176,7 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
|
||||
limit = d['VM_QUOTA']['VM']["VMS"]
|
||||
|
||||
if limit == "-1"
|
||||
limit = default_user_quotas['VM_QUOTA/VM/VMS']
|
||||
limit = default_quotas['VM_QUOTA/VM/VMS']
|
||||
limit = "0" if limit.nil? || limit == ""
|
||||
end
|
||||
|
||||
@ -194,7 +191,7 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
|
||||
limit = d['VM_QUOTA']['VM']["MEMORY"]
|
||||
|
||||
if limit == "-1"
|
||||
limit = default_user_quotas['VM_QUOTA/VM/MEMORY']
|
||||
limit = default_quotas['VM_QUOTA/VM/MEMORY']
|
||||
limit = "0" if limit.nil? || limit == ""
|
||||
end
|
||||
|
||||
@ -211,7 +208,7 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
|
||||
limit = d['VM_QUOTA']['VM']["CPU"]
|
||||
|
||||
if limit == "-1"
|
||||
limit = default_user_quotas['VM_QUOTA/VM/CPU']
|
||||
limit = default_quotas['VM_QUOTA/VM/CPU']
|
||||
limit = "0" if limit.nil? || limit == ""
|
||||
end
|
||||
|
||||
|
@ -248,16 +248,22 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
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)
|
||||
system = System.new(Client.new)
|
||||
|
||||
str = OneQuotaHelper.set_defaultquota(user_pool, 'DEFAULT_USER_QUOTAS', args[1])
|
||||
default_quotas = system.get_user_quotas()
|
||||
|
||||
rc = user_pool.set_quota(str)
|
||||
if OpenNebula.is_error?(default_quotas)
|
||||
puts default_quotas.message
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
str = OneQuotaHelper.set_defaultquota(default_quotas, args[1])
|
||||
|
||||
rc = system.set_user_quotas(str)
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
puts rc.message
|
||||
exit -1
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
exit 0
|
||||
|
@ -48,6 +48,7 @@ require 'OpenNebula/Cluster'
|
||||
require 'OpenNebula/ClusterPool'
|
||||
require 'OpenNebula/Document'
|
||||
require 'OpenNebula/DocumentPool'
|
||||
require 'OpenNebula/System'
|
||||
|
||||
module OpenNebula
|
||||
|
||||
|
99
src/oca/ruby/OpenNebula/System.rb
Normal file
99
src/oca/ruby/OpenNebula/System.rb
Normal file
@ -0,0 +1,99 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
|
||||
require 'OpenNebula/Pool'
|
||||
|
||||
module OpenNebula
|
||||
class System
|
||||
#######################################################################
|
||||
# Constants and Class attribute accessors
|
||||
#######################################################################
|
||||
|
||||
SYSTEM_METHODS = {
|
||||
:userquotainfo => "userquota.info",
|
||||
:userquotaupdate => "userquota.update",
|
||||
:groupquotainfo => "groupquota.info",
|
||||
:groupquotaupdate => "groupquota.update"
|
||||
}
|
||||
|
||||
#######################################################################
|
||||
# Class constructor
|
||||
#######################################################################
|
||||
|
||||
# Constructor
|
||||
# @param [Client] client that represents a XML-RPC connection
|
||||
def initialize(client)
|
||||
@client = client
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# XML-RPC Methods
|
||||
#######################################################################
|
||||
|
||||
# Gets the default user quota limits
|
||||
#
|
||||
# @return [XMLElement, OpenNebula::Error] the default user quota in case
|
||||
# of success, Error otherwise
|
||||
def get_user_quotas()
|
||||
rc = @client.call(SYSTEM_METHODS[:userquotainfo])
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc
|
||||
end
|
||||
|
||||
default_quotas = XMLElement.new
|
||||
default_quotas.initialize_xml(rc, 'DEFAULT_USER_QUOTAS')
|
||||
|
||||
return default_quotas
|
||||
end
|
||||
|
||||
# Sets the default user quota limits
|
||||
# @param quota [String] a template (XML or txt) with the new quota limits
|
||||
#
|
||||
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
||||
# otherwise
|
||||
def set_user_quotas(quota)
|
||||
return @client.call(SYSTEM_METHODS[:userquotaupdate], quota)
|
||||
end
|
||||
|
||||
# Gets the default group quota limits
|
||||
#
|
||||
# @return [XMLElement, OpenNebula::Error] the default group quota in case
|
||||
# of success, Error otherwise
|
||||
def get_group_quotas()
|
||||
rc = @client.call(SYSTEM_METHODS[:groupquotainfo])
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc
|
||||
end
|
||||
|
||||
default_quotas = XMLElement.new
|
||||
default_quotas.initialize_xml(rc, 'DEFAULT_GROUP_QUOTAS')
|
||||
|
||||
return default_quotas
|
||||
end
|
||||
|
||||
# Sets the default group quota limits
|
||||
# @param quota [String] a template (XML or txt) with the new quota limits
|
||||
#
|
||||
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
||||
# otherwise
|
||||
def set_group_quotas(quota)
|
||||
return @client.call(SYSTEM_METHODS[:groupquotaupdate], quota)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user