1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-23 21:57:43 +03:00

feature #1613: New configuration attribute to make optional capacity checking

This commit is contained in:
Ruben S. Montero 2013-07-10 17:48:39 +02:00
parent 75ce560742
commit da40453426
6 changed files with 55 additions and 20 deletions

View File

@ -162,20 +162,13 @@ public:
used_mb = used;
}
unsigned int get_avail_mb()
{
float max_used_size;
if (get_template_attribute("MAX_USED_SIZE", max_used_size))
{
if (used_mb >= (unsigned int) max_used_size)
{
return 0;
}
}
return free_mb;
}
/**
* Returns the available capacity in the datastore.
* @params avail the total available size in the datastore (mb)
* @return true if the datastore is configured to enforce capacity
* checkings
*/
bool get_avail_mb(unsigned int &avail);
private:

View File

@ -103,6 +103,9 @@ MAC_PREFIX = "02:00"
# You can define a different DATASTORE_LOCATION in each cluster by updating
# its properties with onecluster update.
#
# DATASTORE_CAPACITY_CHECK: Checks that there is enough capacity before
# creating a new imag. Defaults to Yes
#
# DEFAULT_IMAGE_TYPE: This can take values
# OS Image file holding an operating system
# CDROM Image file holding a CDROM
@ -117,9 +120,12 @@ MAC_PREFIX = "02:00"
#DATASTORE_LOCATION = /var/lib/one/datastores
DATASTORE_CAPACITY_CHECK = "yes"
DEFAULT_IMAGE_TYPE = "OS"
DEFAULT_DEVICE_PREFIX = "hd"
#*******************************************************************************
# Information Driver Configuration
#*******************************************************************************

View File

@ -542,3 +542,27 @@ int Datastore::replace_template(const string& tmpl_str, string& error_str)
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
bool Datastore::get_avail_mb(unsigned int &avail)
{
float max_used_size;
bool check;
avail = free_mb;
if (get_template_attribute("MAX_USED_SIZE", max_used_size))
{
if (used_mb >= (unsigned int) max_used_size)
{
avail = 0;
}
}
if (!get_template_attribute("DATASTORE_CAPACITY_CHECK", check))
{
Nebula& nd = Nebula::instance();
nd.get_configuration_attribute("DATASTORE_CAPACITY_CHECK", check);
}
return check;
}

View File

@ -199,6 +199,7 @@ void OpenNebulaTemplate::set_conf_default()
# Datastore Configuration
#*******************************************************************************
# DATASTORE_LOCATION
# DATASTORE_CAPACITY_CHECK
# DEFAULT_IMAGE_TYPE
# DEFAULT_DEVICE_PREFIX
#*******************************************************************************
@ -208,6 +209,12 @@ void OpenNebulaTemplate::set_conf_default()
var_location + "/datastores");
conf_default.insert(make_pair(attribute->name(),attribute));
//DATASTORE_CAPACITY_CHECK
value = "YES";
attribute = new SingleAttribute("DATASTORE_CAPACITY_CHECK",value);
conf_default.insert(make_pair(attribute->name(),attribute));
//DEFAULT_IMAGE_TYPE
value = "OS";

View File

@ -342,7 +342,10 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
Datastore * ds;
Image::DiskType ds_disk_type;
int umask, avail;
unsigned int avail;
int umask;
bool ds_check;
// ------------------------- Get user's umask ------------------------------
@ -407,7 +410,7 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
ds_name = ds->get_name();
ds_disk_type = ds->get_disk_type();
avail = ds->get_avail_mb();
ds_check = ds->get_avail_mb(avail);
ds->to_xml(ds_data);
@ -438,7 +441,7 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
return;
}
if ( size_mb > avail )
if (ds_check && ((unsigned int) size_mb > avail))
{
failure_response(ACTION, "Not enough space in datastore", att);

View File

@ -229,8 +229,10 @@ void ImageClone::request_execute(
int clone_id = xmlrpc_c::value_int(paramList.getInt(1));
string name = xmlrpc_c::value_string(paramList.getString(2));
int rc, new_id, ds_id, size, umask, avail;
unsigned int avail;
int rc, new_id, ds_id, size, umask;
string error_str, ds_name, ds_data;
bool ds_check;
Image::DiskType disk_type;
PoolObjectAuth perms, ds_perms;
@ -336,7 +338,7 @@ void ImageClone::request_execute(
ds->to_xml(ds_data);
avail = ds->get_avail_mb();
ds_check = ds->get_avail_mb(avail);
ds->unlock();
@ -345,7 +347,7 @@ void ImageClone::request_execute(
img_usage.add("DATASTORE", ds_id);
img_usage.add("SIZE", size);
if ( size > avail )
if (ds_check && (size > avail))
{
failure_response(ACTION, "Not enough space in datastore", att);