1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-26 06:50:09 +03:00

feature #200: XML-RPC method for saving images while a VM is executing.

This commit is contained in:
Carlos Martín 2010-07-21 18:06:40 +02:00 committed by Ruben S. Montero
parent c8d4f054da
commit 007f5f6b9c
5 changed files with 92 additions and 1 deletions

View File

@ -438,6 +438,34 @@ private:
UserPool * upool;
};
/* ---------------------------------------------------------------------- */
class VirtualMachineSaveDisk: public xmlrpc_c::method
{
public:
VirtualMachineSaveDisk(
VirtualMachinePool * _vmpool,
UserPool * _upool,
ImagePool * _ipool):
vmpool(_vmpool),
upool(_upool),
ipool(_ipool)
{
_signature="A:siii";
_help="Sets the disk to be saved in the given image.";
};
~VirtualMachineSaveDisk(){};
void execute(
xmlrpc_c::paramList const& paramList,
xmlrpc_c::value * const retval);
private:
VirtualMachinePool * vmpool;
UserPool * upool;
ImagePool * ipool;
};
/* ---------------------------------------------------------------------- */

View File

@ -731,6 +731,18 @@ public:
*/
int generate_context(string &files);
// ------------------------------------------------------------------------
// Image repository related functions
// ------------------------------------------------------------------------
/**
* Set the SAVE_AS attribute for the "disk_id"th disk.
* @param disk_id Index of the disk to save
* @param img_id ID of the image this disk will be saved to.
* @return 0 if success
*/
int save_disk(int disk_id, int img_id);
private:
// -------------------------------------------------------------------------

View File

@ -224,7 +224,10 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr vm_action(new
RequestManager::VirtualMachineAction(vmpool,upool));
xmlrpc_c::methodPtr vm_savedisk(new
RequestManager::VirtualMachineSaveDisk(vmpool,upool,ipool));
xmlrpc_c::methodPtr vm_info(new
RequestManager::VirtualMachineInfo(vmpool,upool));
@ -322,6 +325,7 @@ void RequestManager::register_xml_methods()
RequestManagerRegistry.addMethod("one.vm.action", vm_action);
RequestManagerRegistry.addMethod("one.vm.migrate", vm_migrate);
RequestManagerRegistry.addMethod("one.vm.info", vm_info);
RequestManagerRegistry.addMethod("one.vm.savedisk",vm_savedisk);
RequestManagerRegistry.addMethod("one.vmpool.info", vm_pool_info);

View File

@ -27,6 +27,7 @@ source_files=[
'RequestManagerAllocate.cc',
'RequestManagerDeploy.cc',
'RequestManagerMigrate.cc',
'RequestManagerSaveDisk.cc',
'RequestManagerInfo.cc',
'RequestManagerPoolInfo.cc',
'RequestManagerHostAllocate.cc',

View File

@ -1098,6 +1098,52 @@ int VirtualMachine::generate_context(string &files)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int VirtualMachine::save_disk(int disk_id, int img_id)
{
int num_disks;
vector<Attribute * > disks;
VectorAttribute * disk;
string disk_id_str;
int tmp_disk_id;
ostringstream oss;
istringstream iss;
num_disks = vm_template->get("DISK",disks);
for(int i=0; i<num_disks; i++)
{
disk = dynamic_cast<VectorAttribute * >(disks[i]);
if ( disk == 0 )
{
continue;
}
disk_id_str = disk->vector_value("DISK_ID");
iss.str(disk_id_str);
iss >> tmp_disk_id;
if( tmp_disk_id == disk_id )
{
disk->replace("SAVE", "YES");
oss << (img_id);
disk->replace("SAVE_AS", oss.str());
return 0;
}
}
return -1;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
pthread_mutex_t VirtualMachine::lex_mutex = PTHREAD_MUTEX_INITIALIZER;
extern "C"