mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
feature #1791: manage the image lifecycle during the saveas hot operation
This commit is contained in:
parent
146ca09e08
commit
3816c614ef
@ -954,12 +954,21 @@ public:
|
||||
*/
|
||||
int detach_failure();
|
||||
|
||||
/**
|
||||
* Get the IMAGE_ID of the image that's being saved as hot
|
||||
* @param disk_id of the DISK
|
||||
* @param image_id id of the image being saved
|
||||
* @return IMAGE_ID on success, -1 otherwise
|
||||
*/
|
||||
int get_hotplug_saveas_image_id();
|
||||
|
||||
/**
|
||||
* Sets the hotplug_saveas attribute to the given disk
|
||||
* @param disk_id of the DISK
|
||||
* @param image_id id of the image being saved
|
||||
* @return 0 if the disk_id was found -1 otherwise
|
||||
*/
|
||||
int set_hotplug_saveas(int disk_id);
|
||||
int set_hotplug_saveas(int disk_id, int image_id);
|
||||
|
||||
/**
|
||||
* Cleans the HOTPLUG_SAVEAS = YES attribute from the disks
|
||||
|
@ -385,7 +385,10 @@ static void mkfs_action(istringstream& is,
|
||||
}
|
||||
else
|
||||
{
|
||||
image->set_state(Image::READY);
|
||||
if ( !is_hot )
|
||||
{
|
||||
image->set_state(Image::READY);
|
||||
}
|
||||
|
||||
NebulaLog::log("ImM", Log::INFO, "Image created and ready to use");
|
||||
}
|
||||
@ -423,7 +426,7 @@ static void mkfs_action(istringstream& is,
|
||||
iss >> disk_oid;
|
||||
|
||||
vm->set_state(VirtualMachine::HOTPLUG_SAVEAS);
|
||||
vm->set_hotplug_saveas(disk_oid);
|
||||
vm->set_hotplug_saveas(disk_oid, id);
|
||||
|
||||
vm->set_resched(false);
|
||||
|
||||
|
@ -1200,7 +1200,14 @@ void LifeCycleManager::detach_failure_action(int vid)
|
||||
|
||||
void LifeCycleManager::hotplug_saveas_success_action(int vid)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
ImagePool * ipool = nd.get_ipool();
|
||||
|
||||
VirtualMachine * vm;
|
||||
Image * image;
|
||||
|
||||
int image_id;
|
||||
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
@ -1211,7 +1218,9 @@ void LifeCycleManager::hotplug_saveas_success_action(int vid)
|
||||
|
||||
if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG_SAVEAS)
|
||||
{
|
||||
vm->clear_attach_disk();
|
||||
image_id = vm->get_hotplug_saveas_image_id();
|
||||
|
||||
vm->clear_hotplug_saveas();
|
||||
|
||||
vm->set_state(VirtualMachine::RUNNING);
|
||||
|
||||
@ -1224,6 +1233,22 @@ void LifeCycleManager::hotplug_saveas_success_action(int vid)
|
||||
}
|
||||
|
||||
vm->unlock();
|
||||
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
image = ipool->get(image_id, true);
|
||||
|
||||
if ( image == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
image->set_state(Image::READY);
|
||||
|
||||
ipool->update(image);
|
||||
|
||||
image->unlock();
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -1231,5 +1256,53 @@ void LifeCycleManager::hotplug_saveas_success_action(int vid)
|
||||
|
||||
void LifeCycleManager::hotplug_saveas_failure_action(int vid)
|
||||
{
|
||||
hotplug_saveas_success_action(vid);
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
ImagePool * ipool = nd.get_ipool();
|
||||
|
||||
VirtualMachine * vm;
|
||||
Image * image;
|
||||
|
||||
int image_id;
|
||||
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG_SAVEAS)
|
||||
{
|
||||
image_id = vm->get_hotplug_saveas_image_id();
|
||||
|
||||
vm->clear_hotplug_saveas();
|
||||
|
||||
vm->set_state(VirtualMachine::RUNNING);
|
||||
|
||||
vmpool->update(vm);
|
||||
}
|
||||
else
|
||||
{
|
||||
vm->log("LCM",Log::ERROR,"hotplug_saveas_success_action,"
|
||||
" VM in a wrong state");
|
||||
}
|
||||
|
||||
vm->unlock();
|
||||
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
image = ipool->get(image_id, true);
|
||||
|
||||
if ( image == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
image->set_state(Image::ERROR);
|
||||
|
||||
ipool->update(image);
|
||||
|
||||
image->unlock();
|
||||
}
|
||||
|
@ -1854,10 +1854,51 @@ VectorAttribute * VirtualMachine::delete_attach_disk()
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachine::set_hotplug_saveas(int disk_id)
|
||||
int VirtualMachine::get_hotplug_saveas_image_id()
|
||||
{
|
||||
int num_disks;
|
||||
vector<Attribute *> disks;
|
||||
VectorAttribute * disk;
|
||||
|
||||
istringstream iss;
|
||||
string image_id_str;
|
||||
int image_id;
|
||||
|
||||
num_disks = obj_template->get("DISK", disks);
|
||||
|
||||
for(int i=0; i<num_disks; i++)
|
||||
{
|
||||
disk = dynamic_cast<VectorAttribute * >(disks[i]);
|
||||
|
||||
if ( disk == 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( !disk->vector_value("HOTPLUG_SAVEAS_IMAGE_ID").empty() )
|
||||
{
|
||||
image_id_str = disk->vector_value("HOTPLUG_SAVEAS_IMAGE_ID");
|
||||
iss.str(image_id_str);
|
||||
|
||||
iss >> image_id;
|
||||
|
||||
if ( !iss.fail() )
|
||||
{
|
||||
return image_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachine::set_hotplug_saveas(int disk_id, int img_id)
|
||||
{
|
||||
|
||||
int num_disks;
|
||||
@ -1882,12 +1923,15 @@ int VirtualMachine::set_hotplug_saveas(int disk_id)
|
||||
if ( d_id == disk_id )
|
||||
{
|
||||
disk->replace("HOTPLUG_SAVEAS", "YES");
|
||||
disk->replace("HOTPLUG_SAVEAS_IMAGE_ID", img_id);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
@ -1911,6 +1955,7 @@ void VirtualMachine::clear_hotplug_saveas()
|
||||
if ( disk->vector_value("HOTPLUG_SAVEAS") == "YES" )
|
||||
{
|
||||
disk->remove("HOTPLUG_SAVEAS");
|
||||
disk->remove("HOTPLUG_SAVEAS_IMAGE_ID");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user