1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-22 22:03:39 +03:00

feature #3782: Image XML-RPC methods for snapshot delete

This commit is contained in:
Ruben S. Montero 2015-06-05 03:24:46 +02:00
parent 1bd6ffe60a
commit 62a98c550d
4 changed files with 90 additions and 8 deletions

View File

@ -119,7 +119,57 @@ public:
RequestAttributes& att);
};
/* -------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ImageSnapshotRevert : public RequestManagerImage
{
public:
ImageSnapshotRevert():
RequestManagerImage("ImageSnapshotRevert",
"Reverts image state to a previous snapshot",
"A:sis"){};
~ImageSnapshotRevert(){};
void request_execute(xmlrpc_c::paramList const& _paramList,
RequestAttributes& att);
};
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ImageSnapshotFlatten : public RequestManagerImage
{
public:
ImageSnapshotFlatten():
RequestManagerImage("ImageSnapshotFlatten",
"Flattens the selected image snapshot",
"A:sii"){};
~ImageSnapshotFlatten(){};
void request_execute(xmlrpc_c::paramList const& _paramList,
RequestAttributes& att);
};
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ImageSnapshotDelete : public RequestManagerImage
{
public:
ImageSnapshotDelete():
RequestManagerImage("ImageSnapshotDelete",
"Deletes a snapshot from image",
"A:sii"){};
~ImageSnapshotDelete(){};
void request_execute(xmlrpc_c::paramList const& _paramList,
RequestAttributes& att);
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -397,6 +397,7 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr image_enable(new ImageEnable());
xmlrpc_c::methodPtr image_chtype(new ImageChangeType());
xmlrpc_c::methodPtr image_clone(new ImageClone());
xmlrpc_c::methodPtr image_snap_delete(new ImageSnapshotDelete());
// Datastore Methods
xmlrpc_c::methodPtr datastore_enable(new DatastoreEnable());
@ -653,6 +654,7 @@ void RequestManager::register_xml_methods()
RequestManagerRegistry.addMethod("one.image.chtype", image_chtype);
RequestManagerRegistry.addMethod("one.image.clone", image_clone);
RequestManagerRegistry.addMethod("one.image.rename", image_rename);
RequestManagerRegistry.addMethod("one.image.snapshotdelete", image_snap_delete);
RequestManagerRegistry.addMethod("one.imagepool.info", imagepool_info);

View File

@ -280,7 +280,9 @@ void ImageClone::request_execute(
return;
}
if (img->get_snapshots_size () > 0)
const Snapshots& snaps = img->get_snapshots();
if (snaps.size () > 0)
{
failure_response(ACTION,
request_error("Cannot clone images with snapshots",""), att);
@ -467,4 +469,32 @@ void ImageClone::request_execute(
success_response(new_id, att);
}
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
void ImageSnapshotDelete::request_execute(xmlrpc_c::paramList const& paramList,
RequestAttributes& att)
{
int id = xmlrpc_c::value_int(paramList.getInt(1));
int snap_id = xmlrpc_c::value_int(paramList.getInt(2));
Nebula& nd = Nebula::instance();
ImageManager * imagem = nd.get_imagem();
if ( basic_authorization(id, att) == false )
{
return;
}
string err_msg;
int rc = imagem->delete_snapshot(id, snap_id, err_msg);
if ( rc < 0 )
{
failure_response(ACTION, request_error(err_msg, ""), att);
return;
}
success_response(id, att);
}

View File

@ -2494,13 +2494,13 @@ void VirtualMachineDiskSnapshotCreate::request_execute(
Nebula& nd = Nebula::instance();
DispatchManager * dm = nd.get_dm();
int rc;
int snap_id;
string error_str;
int rc;
int snap_id;
string error_str;
int id = xmlrpc_c::value_int(paramList.getInt(1));
int did = xmlrpc_c::value_int(paramList.getInt(2));
string tag = xmlrpc_c::value_string(paramList.getString(3));
int id = xmlrpc_c::value_int(paramList.getInt(1));
int did = xmlrpc_c::value_int(paramList.getInt(2));
string tag = xmlrpc_c::value_string(paramList.getString(3));
if ( vm_authorization(id, 0, 0, att, 0, 0, auth_op) == false )
{