mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-25 23:21:29 +03:00
feature #200: Added Image Delete RM method
This commit is contained in:
parent
1a956aa355
commit
9ca75314b4
@ -104,6 +104,7 @@ public:
|
||||
|
||||
/** Drops an image from the DB, the image mutex MUST BE locked
|
||||
* @param image pointer to Image
|
||||
* @return 0 on success
|
||||
*/
|
||||
int drop(Image * image)
|
||||
{
|
||||
|
@ -663,7 +663,6 @@ private:
|
||||
/* Image Pool Interface */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
|
||||
class ImageAllocate: public xmlrpc_c::method
|
||||
{
|
||||
public:
|
||||
@ -687,6 +686,31 @@ private:
|
||||
UserPool * upool;
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
class ImageDelete: public xmlrpc_c::method
|
||||
{
|
||||
public:
|
||||
ImageDelete(ImagePool * _ipool,
|
||||
UserPool * _upool):
|
||||
ipool(_ipool),
|
||||
upool(_upool)
|
||||
{
|
||||
_signature="A:si";
|
||||
_help="Deletes an image";
|
||||
};
|
||||
|
||||
~ImageDelete(){};
|
||||
|
||||
void execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retvalP);
|
||||
|
||||
private:
|
||||
ImagePool * ipool;
|
||||
UserPool * upool;
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
class ImageInfo: public xmlrpc_c::method
|
||||
@ -697,8 +721,8 @@ private:
|
||||
ipool(_ipool),
|
||||
upool(_upool)
|
||||
{
|
||||
_signature="A:ss";
|
||||
_help="Allocates an image in the pool";
|
||||
_signature="A:si";
|
||||
_help="Returns information for an image";
|
||||
};
|
||||
|
||||
~ImageInfo(){};
|
||||
|
@ -302,6 +302,12 @@ int Image::drop(SqlDB * db)
|
||||
{
|
||||
ostringstream oss;
|
||||
int rc;
|
||||
|
||||
// Only delete the VM
|
||||
if (running_vms != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
image_template.drop(db);
|
||||
|
||||
|
@ -273,6 +273,9 @@ void RequestManager::register_xml_methods()
|
||||
xmlrpc_c::methodPtr image_allocate(new
|
||||
RequestManager::ImageAllocate(ipool, upool));
|
||||
|
||||
xmlrpc_c::methodPtr image_delete(new
|
||||
RequestManager::ImageDelete(ipool, upool));
|
||||
|
||||
xmlrpc_c::methodPtr image_info(new
|
||||
RequestManager::ImageInfo(ipool, upool));
|
||||
|
||||
@ -318,6 +321,7 @@ void RequestManager::register_xml_methods()
|
||||
/* Image related methods*/
|
||||
|
||||
RequestManagerRegistry.addMethod("one.image.allocate", image_allocate);
|
||||
RequestManagerRegistry.addMethod("one.image.delete", image_delete);
|
||||
RequestManagerRegistry.addMethod("one.image.info", image_info);
|
||||
|
||||
RequestManagerRegistry.addMethod("one.imagepool.info", imagepool_info);
|
||||
|
123
src/rm/RequestManagerImageDelete.cc
Normal file
123
src/rm/RequestManagerImageDelete.cc
Normal file
@ -0,0 +1,123 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
#include "Nebula.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void RequestManager::ImageDelete::execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retval)
|
||||
{
|
||||
string session;
|
||||
|
||||
int iid;
|
||||
int uid;
|
||||
int rc;
|
||||
|
||||
Image * image;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
|
||||
NebulaLog::log("ReM",Log::DEBUG,"ImageDelete invoked");
|
||||
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
iid = xmlrpc_c::value_int (paramList.getInt(1));
|
||||
|
||||
|
||||
// First, we need to authenticate the user
|
||||
rc = ImageDelete::upool->authenticate(session);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
goto error_authenticate;
|
||||
}
|
||||
|
||||
uid = rc;
|
||||
|
||||
// Get image from the ImagePool
|
||||
image = ImageDelete::ipool->get(iid,true);
|
||||
|
||||
if ( image == 0 )
|
||||
{
|
||||
goto error_image_get;
|
||||
}
|
||||
|
||||
if ( uid != 0 && uid != image->get_uid() )
|
||||
{
|
||||
goto error_authorization;
|
||||
}
|
||||
|
||||
rc = ImageDelete::ipool->drop(image);
|
||||
|
||||
if ( rc < 0 )
|
||||
{
|
||||
goto error_delete;
|
||||
|
||||
}
|
||||
|
||||
image->unlock();
|
||||
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(true));
|
||||
arrayData.push_back(xmlrpc_c::value_int(iid));
|
||||
|
||||
// Copy arrayresult into retval mem space
|
||||
arrayresult = new xmlrpc_c::value_array(arrayData);
|
||||
*retval = *arrayresult;
|
||||
|
||||
delete arrayresult; // and get rid of the original
|
||||
|
||||
return;
|
||||
|
||||
error_authenticate:
|
||||
oss << "User not authenticated, aborting ImageDelete call.";
|
||||
goto error_common;
|
||||
|
||||
error_image_get:
|
||||
oss << "Error getting image with ID = " << iid;
|
||||
goto error_common;
|
||||
|
||||
error_authorization:
|
||||
oss << "User not authorized to delete image, aborting ImageDelete call.";
|
||||
goto error_common;
|
||||
|
||||
error_delete:
|
||||
oss << "Cannot delete image, VMs might be running on it.";
|
||||
goto error_common;
|
||||
|
||||
error_common:
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
*retval = arrayresult_error;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
@ -35,6 +35,7 @@ source_files=[
|
||||
'RequestManagerHostPoolInfo.cc',
|
||||
'RequestManagerHostEnable.cc',
|
||||
'RequestManagerImageAllocate.cc',
|
||||
'RequestManagerImageDelete.cc',
|
||||
'RequestManagerImageInfo.cc',
|
||||
'RequestManagerImagePoolInfo.cc',
|
||||
'RequestManagerVirtualNetworkAllocate.cc',
|
||||
|
Loading…
Reference in New Issue
Block a user