mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-16 22:50:10 +03:00
feature #1617: Checks: FILE Images can only be registered in FILE_DS. Cannot clone FILE images.
This commit is contained in:
parent
3c3830aeaf
commit
0496414051
@ -20,6 +20,7 @@
|
||||
#include "PoolSQL.h"
|
||||
#include "Image.h"
|
||||
#include "NebulaLog.h"
|
||||
#include "Datastore.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <sstream>
|
||||
@ -74,8 +75,9 @@ public:
|
||||
ImageTemplate * img_template,
|
||||
int ds_id,
|
||||
const string& ds_name,
|
||||
Image::DiskType ds_type,
|
||||
Image::DiskType disk_type,
|
||||
const string& ds_data,
|
||||
Datastore::DatastoreType ds_type,
|
||||
int source_img_id,
|
||||
int * oid,
|
||||
string& error_str);
|
||||
|
@ -63,18 +63,19 @@ ImagePool::ImagePool(SqlDB * db,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int ImagePool::allocate (
|
||||
int uid,
|
||||
int gid,
|
||||
const string& uname,
|
||||
const string& gname,
|
||||
ImageTemplate* img_template,
|
||||
int ds_id,
|
||||
const string& ds_name,
|
||||
Image::DiskType disk_type,
|
||||
const string& ds_data,
|
||||
int cloning_id,
|
||||
int * oid,
|
||||
string& error_str)
|
||||
int uid,
|
||||
int gid,
|
||||
const string& uname,
|
||||
const string& gname,
|
||||
ImageTemplate * img_template,
|
||||
int ds_id,
|
||||
const string& ds_name,
|
||||
Image::DiskType disk_type,
|
||||
const string& ds_data,
|
||||
Datastore::DatastoreType ds_type,
|
||||
int cloning_id,
|
||||
int * oid,
|
||||
string& error_str)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
ImageManager * imagem = nd.get_imagem();
|
||||
@ -82,6 +83,7 @@ int ImagePool::allocate (
|
||||
Image * img;
|
||||
Image * img_aux = 0;
|
||||
string name;
|
||||
string type;
|
||||
ostringstream oss;
|
||||
|
||||
img = new Image(uid, gid, uname, gname, img_template);
|
||||
@ -101,6 +103,14 @@ int ImagePool::allocate (
|
||||
goto error_name_length;
|
||||
}
|
||||
|
||||
img->get_template_attribute("TYPE", type);
|
||||
|
||||
if ( ds_type == Datastore::FILE_DS &&
|
||||
img->str_to_type(type) != Image::DATAFILE )
|
||||
{
|
||||
goto error_types_missmatch;
|
||||
}
|
||||
|
||||
img_aux = get(name,uid,false);
|
||||
|
||||
if( img_aux != 0 )
|
||||
@ -181,6 +191,10 @@ error_name_length:
|
||||
oss << "NAME is too long; max length is 128 chars.";
|
||||
goto error_common;
|
||||
|
||||
error_types_missmatch:
|
||||
oss << "Only IMAGES of type FILE can be registered in FILE_DS Datastore";
|
||||
goto error_common;
|
||||
|
||||
error_duplicated:
|
||||
oss << "NAME is already taken by IMAGE "
|
||||
<< img_aux->get_oid() << ".";
|
||||
|
@ -289,6 +289,8 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
|
||||
string ds_name;
|
||||
string ds_data;
|
||||
|
||||
Datastore::DatastoreType ds_type;
|
||||
|
||||
int rc, id;
|
||||
|
||||
PoolObjectAuth ds_perms;
|
||||
@ -332,7 +334,9 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ds->get_type() == Datastore::SYSTEM_DS )
|
||||
ds_type = ds->get_type();
|
||||
|
||||
if ( ds_type == Datastore::SYSTEM_DS )
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
@ -448,6 +452,7 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
|
||||
ds_name,
|
||||
ds_disk_type,
|
||||
ds_data,
|
||||
ds_type,
|
||||
-1,
|
||||
&id,
|
||||
error_str);
|
||||
|
@ -182,7 +182,7 @@ void ImageClone::request_execute(
|
||||
Image * img;
|
||||
Datastore * ds;
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
DatastorePool * dspool = nd.get_dspool();
|
||||
ImagePool * ipool = static_cast<ImagePool *>(pool);
|
||||
@ -200,8 +200,19 @@ void ImageClone::request_execute(
|
||||
return;
|
||||
}
|
||||
|
||||
if ( img->get_type() == Image::DATAFILE )
|
||||
{
|
||||
failure_response(ACTION,
|
||||
"Image of type FILE cannot be clonned",
|
||||
att);
|
||||
|
||||
img->unlock();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
tmpl = img->clone_template(name);
|
||||
|
||||
|
||||
img->get_permissions(perms);
|
||||
|
||||
ds_id = img->get_ds_id();
|
||||
@ -224,6 +235,18 @@ void ImageClone::request_execute(
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ds->get_type() == Datastore::FILE_DS )
|
||||
{
|
||||
failure_response(ACTION, "Clone not supported for FILE_DS Datastores",
|
||||
att);
|
||||
|
||||
delete tmpl;
|
||||
|
||||
ds->unlock();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
ds->get_permissions(ds_perms);
|
||||
|
||||
disk_type = ds->get_disk_type();
|
||||
@ -233,7 +256,7 @@ void ImageClone::request_execute(
|
||||
ds->unlock();
|
||||
|
||||
// ------------- Set authorization request ---------------------------------
|
||||
|
||||
|
||||
img_usage.add("DATASTORE", ds_id);
|
||||
img_usage.add("SIZE", size);
|
||||
|
||||
@ -265,21 +288,22 @@ void ImageClone::request_execute(
|
||||
if ( quota_authorization(&img_usage, Quotas::DATASTORE, att) == false )
|
||||
{
|
||||
delete tmpl;
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
rc = ipool->allocate(att.uid,
|
||||
att.gid,
|
||||
att.uname,
|
||||
rc = ipool->allocate(att.uid,
|
||||
att.gid,
|
||||
att.uname,
|
||||
att.gname,
|
||||
tmpl,
|
||||
ds_id,
|
||||
ds_name,
|
||||
tmpl,
|
||||
ds_id,
|
||||
ds_name,
|
||||
disk_type,
|
||||
ds_data,
|
||||
clone_id,
|
||||
&new_id,
|
||||
ds_data,
|
||||
Datastore::IMAGE_DS,
|
||||
clone_id,
|
||||
&new_id,
|
||||
error_str);
|
||||
if ( rc < 0 )
|
||||
{
|
||||
|
@ -725,6 +725,7 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
|
||||
ds_name,
|
||||
ds_disk_type,
|
||||
ds_data,
|
||||
Datastore::IMAGE_DS,
|
||||
-1,
|
||||
&iid,
|
||||
error_str);
|
||||
|
Loading…
x
Reference in New Issue
Block a user