mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
Feature #4238: When making an image non-persistent
check if the datastore is PERSISTENT_ONLY
This commit is contained in:
parent
d7b8aa1cd3
commit
77ba16bf56
@ -68,8 +68,15 @@ void ImagePersistent::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
bool persistent_flag = xmlrpc_c::value_boolean(paramList.getBoolean(2));
|
||||
int rc;
|
||||
|
||||
int ds_id;
|
||||
int ds_persistent_only;
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
DatastorePool * dspool = nd.get_dspool();
|
||||
|
||||
Datastore * ds;
|
||||
Image * image;
|
||||
string err_msg;
|
||||
std::string err_msg;
|
||||
|
||||
if ( basic_authorization(id, att) == false )
|
||||
{
|
||||
@ -87,6 +94,36 @@ void ImagePersistent::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
return;
|
||||
}
|
||||
|
||||
ds_id = image->get_ds_id();
|
||||
|
||||
image->unlock();
|
||||
|
||||
ds = dspool->get(ds_id, true);
|
||||
|
||||
if ( ds == 0 )
|
||||
{
|
||||
failure_response(INTERNAL,
|
||||
request_error("Datastore no longer exists.",
|
||||
""), att);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
ds_persistent_only = ds->is_persistent_only();
|
||||
|
||||
ds->unlock();
|
||||
|
||||
image = static_cast<Image *>(pool->get(id,true));
|
||||
|
||||
if ( image == 0 )
|
||||
{
|
||||
failure_response(NO_EXISTS,
|
||||
get_error(object_name(auth_object),id),
|
||||
att);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
switch (image->get_type())
|
||||
{
|
||||
case Image::OS:
|
||||
@ -104,6 +141,17 @@ void ImagePersistent::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
return;
|
||||
}
|
||||
|
||||
/* Check if datastore allows the operation */
|
||||
if ( ds_persistent_only && persistent_flag == false )
|
||||
{
|
||||
failure_response(INTERNAL,
|
||||
request_error("This Datastore only accepts persistent images.",""),
|
||||
att);
|
||||
|
||||
image->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
rc = image->persistent(persistent_flag, err_msg);
|
||||
|
||||
if ( rc != 0 )
|
||||
|
Loading…
x
Reference in New Issue
Block a user