From fc92951994691c18ebac6a647db57fa5ccdba0e3 Mon Sep 17 00:00:00 2001 From: juanmont Date: Mon, 25 Jun 2018 16:36:52 +0200 Subject: [PATCH] F #1880: Added param to check capacity when allocating a new image (this is only for admin users) --- include/RequestManagerAllocate.h | 2 +- src/cli/one_helper/oneimage_helper.rb | 8 ++++++++ src/cli/oneimage | 6 ++++-- .../java/src/org/opennebula/client/image/Image.java | 10 ++++++---- src/oca/ruby/opennebula/image.rb | 4 ++-- src/rm/RequestManagerAllocate.cc | 10 ++++++++-- 6 files changed, 29 insertions(+), 11 deletions(-) diff --git a/include/RequestManagerAllocate.h b/include/RequestManagerAllocate.h index d60c41f63c..183496785d 100644 --- a/include/RequestManagerAllocate.h +++ b/include/RequestManagerAllocate.h @@ -211,7 +211,7 @@ public: ImageAllocate(): RequestManagerAllocate("one.image.allocate", "Allocates a new image", - "A:ssi", + "A:ssib", true) { Nebula& nd = Nebula::instance(); diff --git a/src/cli/one_helper/oneimage_helper.rb b/src/cli/one_helper/oneimage_helper.rb index c72743b84c..6effbcc154 100644 --- a/src/cli/one_helper/oneimage_helper.rb +++ b/src/cli/one_helper/oneimage_helper.rb @@ -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 diff --git a/src/cli/oneimage b/src/cli/oneimage index a7e64540b9..667b14e792 100755 --- a/src/cli/oneimage +++ b/src/cli/oneimage @@ -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 diff --git a/src/oca/java/src/org/opennebula/client/image/Image.java b/src/oca/java/src/org/opennebula/client/image/Image.java index 1109d31609..6db71869c8 100644 --- a/src/oca/java/src/org/opennebula/client/image/Image.java +++ b/src/oca/java/src/org/opennebula/client/image/Image.java @@ -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); } /** diff --git a/src/oca/ruby/opennebula/image.rb b/src/oca/ruby/opennebula/image.rb index fbcfd50308..37fe180ef9 100644 --- a/src/oca/ruby/opennebula/image.rb +++ b/src/oca/ruby/opennebula/image.rb @@ -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 diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index 1d68f6773b..b3f0fa0aaa 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -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();