1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-23 17:33:56 +03:00

F #1880: Added param to check capacity when allocating a new image (this is only for admin users)

This commit is contained in:
juanmont 2018-06-25 16:36:52 +02:00 committed by Ruben S. Montero
parent 7d7bf2a29c
commit 2e8f864318
6 changed files with 29 additions and 11 deletions

View File

@ -211,7 +211,7 @@ public:
ImageAllocate():
RequestManagerAllocate("one.image.allocate",
"Allocates a new image",
"A:ssi",
"A:ssib",
true)
{
Nebula& nd = Nebula::instance();

View File

@ -160,6 +160,14 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
OpenNebulaHelper::DRY
]
IMAGE = {
:name => "no_check_capacity",
:large => "--no_check_capacity",
:description =>
"Check Datastore capacity. By Default YES",
:format => String
}
def self.rname
"IMAGE"
end

View File

@ -75,7 +75,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
list_options << OpenNebulaHelper::NUMERIC
list_options << OpenNebulaHelper::DESCRIBE
CREATE_OPTIONS = [OneDatastoreHelper::DATASTORE]
CREATE_OPTIONS = [OneDatastoreHelper::DATASTORE, OneImageHelper::IMAGE]
########################################################################
# Formatters for arguments
@ -147,6 +147,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
exit -1
end
check_capacity = options[:no_check_capacity].nil? ? false : true;
if args[0] && OpenNebulaHelper.create_template_options_used?(options)
STDERR.puts "You can not use both template file and template"<<
" creation options."
@ -173,7 +175,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
exit 0
end
image.allocate(template, options[:datastore])
image.allocate(template, options[:datastore], check_capacity)
rescue => e
STDERR.puts e.messsage
exit -1

View File

@ -88,16 +88,18 @@ public class Image extends PoolElement
* @param client XML-RPC Client.
* @param description A string containing the template of the image.
* @param datastoreId The Datastore ID
* @param check_capacity to check datastore capacity
*
* @return If successful the message contains the associated
* id generated for this Image.
*/
public static OneResponse allocate(
Client client,
String description,
int datastoreId)
Client client,
String description,
int datastoreId,
boolean check_capacity = true)
{
return client.call(ALLOCATE, description, datastoreId);
return client.call(ALLOCATE, description, datastoreId, check_capacity);
}
/**

View File

@ -115,8 +115,8 @@ module OpenNebula
#
# @return [nil, OpenNebula::Error] nil in case of success, Error
# otherwise
def allocate(description, ds_id)
super(IMAGE_METHODS[:allocate],description, ds_id)
def allocate(description, ds_id, check_capacity=true)
super(IMAGE_METHODS[:allocate],description, ds_id, check_capacity)
end
# Replaces the template contents

View File

@ -352,7 +352,8 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
string tm_mad;
string ds_driver;
bool ds_persistent_only;
bool ds_persistent_only;
bool check_capacity = true;
Datastore::DatastoreType ds_type;
@ -363,6 +364,11 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
string str_tmpl = xmlrpc_c::value_string(params.getString(1));
int ds_id = xmlrpc_c::value_int(params.getInt(2));
if ( params.size() > 3 && att.is_admin() )
{
check_capacity = xmlrpc_c::value_boolean(params.getBoolean(3));
}
Nebula& nd = Nebula::instance();
DatastorePool * dspool = nd.get_dspool();
@ -433,7 +439,7 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
ds_name = ds->get_name();
ds_disk_type = ds->get_disk_type();
ds_check = ds->get_avail_mb(avail);
ds_check = ds->get_avail_mb(avail) && check_capacity;
ds_persistent_only = ds->is_persistent_only();
ds_mad = ds->get_ds_mad();
tm_mad = ds->get_tm_mad();