mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-28 14:50:08 +03:00
Feature #1320: Better error messages for image operations
This commit is contained in:
parent
5e4f93432c
commit
5ef5a137ea
@ -113,10 +113,12 @@ public:
|
||||
|
||||
/**
|
||||
* Enables the image
|
||||
* @param iid Image id
|
||||
* @param to_enable true will enable the image.
|
||||
* @param error_str Error reason, if any
|
||||
* @return 0 on success
|
||||
*/
|
||||
int enable_image(int iid, bool to_enable);
|
||||
int enable_image(int iid, bool to_enable, string& error_str);
|
||||
|
||||
/**
|
||||
* Adds a new image to the repository copying or creating it as needed
|
||||
@ -155,9 +157,10 @@ public:
|
||||
/**
|
||||
* Deletes an image from the repository and the DB
|
||||
* @param iid id of image
|
||||
* @param error_str Error reason, if any
|
||||
* @return 0 on success
|
||||
*/
|
||||
int delete_image(int iid, const string& ds_data);
|
||||
int delete_image(int iid, const string& ds_data, string& error_str);
|
||||
|
||||
/**
|
||||
* Gets the size of an image by calling the STAT action of the associated
|
||||
|
@ -328,11 +328,13 @@ void ImageManager::release_cloning_image(int iid, int clone_img_id)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int ImageManager::enable_image(int iid, bool to_enable)
|
||||
int ImageManager::enable_image(int iid, bool to_enable, string& error_str)
|
||||
{
|
||||
int rc = 0;
|
||||
Image * img;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
img = ipool->get(iid,true);
|
||||
|
||||
if ( img == 0 )
|
||||
@ -351,6 +353,10 @@ int ImageManager::enable_image(int iid, bool to_enable)
|
||||
case Image::READY:
|
||||
break;
|
||||
default:
|
||||
oss << "Image cannot be in state "
|
||||
<< Image::state_to_str(img->get_state()) << ".";
|
||||
error_str = oss.str();
|
||||
|
||||
rc = -1;
|
||||
break;
|
||||
}
|
||||
@ -366,6 +372,10 @@ int ImageManager::enable_image(int iid, bool to_enable)
|
||||
case Image::DISABLED:
|
||||
break;
|
||||
default:
|
||||
oss << "Image cannot be in state "
|
||||
<< Image::state_to_str(img->get_state()) << ".";
|
||||
error_str = oss.str();
|
||||
|
||||
rc = -1;
|
||||
break;
|
||||
}
|
||||
@ -379,7 +389,7 @@ int ImageManager::enable_image(int iid, bool to_enable)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int ImageManager::delete_image(int iid, const string& ds_data)
|
||||
int ImageManager::delete_image(int iid, const string& ds_data, string& error_str)
|
||||
{
|
||||
Image * img;
|
||||
|
||||
@ -394,6 +404,8 @@ int ImageManager::delete_image(int iid, const string& ds_data)
|
||||
int gid;
|
||||
int cloning_id = -1;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
img = ipool->get(iid,true);
|
||||
|
||||
if ( img == 0 )
|
||||
@ -406,14 +418,27 @@ int ImageManager::delete_image(int iid, const string& ds_data)
|
||||
case Image::READY:
|
||||
if ( img->get_running() != 0 )
|
||||
{
|
||||
oss << "There are " << img->get_running() << " VMs using it.";
|
||||
error_str = oss.str();
|
||||
|
||||
img->unlock();
|
||||
return -1; //Cannot remove images in use
|
||||
}
|
||||
break;
|
||||
|
||||
case Image::CLONE:
|
||||
oss << "There are " << img->get_cloning() << " active clone operations.";
|
||||
error_str = oss.str();
|
||||
|
||||
img->unlock();
|
||||
return -1; //Cannot remove images in use
|
||||
break;
|
||||
|
||||
case Image::USED:
|
||||
case Image::USED_PERS:
|
||||
case Image::CLONE:
|
||||
oss << "There are " << img->get_running() << " VMs using it.";
|
||||
error_str = oss.str();
|
||||
|
||||
img->unlock();
|
||||
return -1; //Cannot remove images in use
|
||||
break;
|
||||
@ -436,6 +461,8 @@ int ImageManager::delete_image(int iid, const string& ds_data)
|
||||
|
||||
if ( imd == 0 )
|
||||
{
|
||||
error_str = "Error getting ImageManagerDriver";
|
||||
|
||||
img->unlock();
|
||||
return -1;
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ int ImageDelete::drop(int oid, PoolObjectSQL * object, string& error_msg)
|
||||
|
||||
ds->unlock();
|
||||
|
||||
rc = imagem->delete_image(oid, ds_data);
|
||||
rc = imagem->delete_image(oid, ds_data, error_msg);
|
||||
|
||||
if ( rc == 0 )
|
||||
{
|
||||
|
@ -38,17 +38,17 @@ void ImageEnable::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
return;
|
||||
}
|
||||
|
||||
rc = imagem->enable_image(id,enable_flag);
|
||||
rc = imagem->enable_image(id,enable_flag, err_msg);
|
||||
|
||||
if( rc < 0 )
|
||||
{
|
||||
if (enable_flag == true)
|
||||
{
|
||||
err_msg = "Could not enable image.";
|
||||
err_msg = "Could not enable image: " + err_msg;
|
||||
}
|
||||
else
|
||||
{
|
||||
err_msg = "Could not disable image.";
|
||||
err_msg = "Could not disable image: " + err_msg;
|
||||
}
|
||||
|
||||
failure_response(INTERNAL, request_error(err_msg,""), att);
|
||||
|
@ -403,7 +403,7 @@ void VirtualMachineManagerDriver::protocol(
|
||||
|
||||
if ( result == "SUCCESS" )
|
||||
{
|
||||
vm->log("VMM", Log::ERROR, "VM NIC Successfully attached.");
|
||||
vm->log("VMM", Log::INFO, "VM NIC Successfully attached.");
|
||||
|
||||
lcm->trigger(LifeCycleManager::ATTACH_NIC_SUCCESS, id);
|
||||
}
|
||||
@ -422,7 +422,7 @@ void VirtualMachineManagerDriver::protocol(
|
||||
|
||||
if ( result == "SUCCESS" )
|
||||
{
|
||||
vm->log("VMM",Log::ERROR,"VM NIC Successfully detached.");
|
||||
vm->log("VMM",Log::INFO, "VM NIC Successfully detached.");
|
||||
|
||||
lcm->trigger(LifeCycleManager::DETACH_NIC_SUCCESS, id);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user