diff --git a/include/ImageManager.h b/include/ImageManager.h index 6fcc6012ba..117178a7fd 100644 --- a/include/ImageManager.h +++ b/include/ImageManager.h @@ -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 diff --git a/src/image/ImageManagerActions.cc b/src/image/ImageManagerActions.cc index 48c0650e2f..e7092b2460 100644 --- a/src/image/ImageManagerActions.cc +++ b/src/image/ImageManagerActions.cc @@ -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; } diff --git a/src/rm/RequestManagerDelete.cc b/src/rm/RequestManagerDelete.cc index d0295a9d38..aa1a0e7317 100644 --- a/src/rm/RequestManagerDelete.cc +++ b/src/rm/RequestManagerDelete.cc @@ -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 ) { diff --git a/src/rm/RequestManagerImage.cc b/src/rm/RequestManagerImage.cc index 86bb1db118..7f96527854 100644 --- a/src/rm/RequestManagerImage.cc +++ b/src/rm/RequestManagerImage.cc @@ -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); diff --git a/src/vmm/VirtualMachineManagerDriver.cc b/src/vmm/VirtualMachineManagerDriver.cc index 9cd9ea6ce0..d0adc0e5d3 100644 --- a/src/vmm/VirtualMachineManagerDriver.cc +++ b/src/vmm/VirtualMachineManagerDriver.cc @@ -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); }