1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-27 13:57:23 +03:00

B : Allow VM recover --recreate in poweroff and suspend ()

* Refactor release vnc port
* Fix VNC port for recover --recreate in stopped state
* Improve error messages
*  Update recover --recreate description

(cherry picked from commit 9ed1fba8b95c1ea5d3984f136e638b973577ad69)
This commit is contained in:
Pavel Czerný 2024-05-21 11:59:29 +02:00 committed by Ruben S. Montero
parent 8622d03a1f
commit 0f248706de
No known key found for this signature in database
GPG Key ID: A0CEA6FA880A1D87
7 changed files with 73 additions and 42 deletions

@ -884,6 +884,11 @@ public:
previous_history->req_id = rid;
};
/**
* Release VNC port
*/
void release_vnc_port();
/**
* Release the previous VNC port when a VM is migrated to another cluster
* (GRAPHICS/PREVIOUS_PORT present)

@ -739,7 +739,7 @@ CommandParser::CmdParser.new(ARGV) do
States for success/failure recovers: Any ACTIVE state.
States for a retry recover: Any *FAILURE state
States for delete: Any
States for recreate: Any but DONE/POWEROFF/SUSPENDED
States for recreate: Any but DONE
States for delete-db: Any
EOT

@ -289,7 +289,6 @@ void DispatchManager::free_vm_resources(unique_ptr<VirtualMachine> vm,
int gid;
string deploy_id;
int vrid = -1;
unsigned int port;
VirtualMachineTemplate quota_tmpl;
@ -330,14 +329,7 @@ void DispatchManager::free_vm_resources(unique_ptr<VirtualMachine> vm,
}
}
VectorAttribute * graphics = vm->get_template_attribute("GRAPHICS");
if ( graphics != nullptr && graphics->vector_value("PORT", port) == 0
&& vm->hasHistory())
{
graphics->remove("PORT");
clpool->release_vnc_port(vm->get_cid(), port);
}
vm->release_vnc_port();
vmpool->update(vm.get());
@ -1204,18 +1196,6 @@ int DispatchManager::delete_recreate(unique_ptr<VirtualMachine> vm,
switch (vm->get_state())
{
case VirtualMachine::POWEROFF:
error = "Cannot delete-recreate a powered off VM. Resume it first";
NebulaLog::log("DiM", Log::ERROR, error);
rc = -1;
break;
case VirtualMachine::SUSPENDED:
error = "Cannot delete-recreate a suspended VM. Resume it first";
NebulaLog::log("DiM", Log::ERROR, error);
rc = -1;
break;
case VirtualMachine::INIT:
case VirtualMachine::PENDING:
case VirtualMachine::CLONING:
@ -1223,6 +1203,10 @@ int DispatchManager::delete_recreate(unique_ptr<VirtualMachine> vm,
break;
case VirtualMachine::STOPPED:
vm->release_vnc_port();
[[fallthrough]];
case VirtualMachine::UNDEPLOYED:
vm_uid = vm->get_uid();
vm_gid = vm->get_gid();
@ -1255,6 +1239,8 @@ int DispatchManager::delete_recreate(unique_ptr<VirtualMachine> vm,
}
break;
case VirtualMachine::POWEROFF:
case VirtualMachine::SUSPENDED:
case VirtualMachine::ACTIVE: //Cleanup VM resources before PENDING
lcm->trigger_delete_recreate(vm->get_oid(), ra);
break;

@ -948,9 +948,13 @@ void LifeCycleManager::trigger_delete_recreate(int vid,
if ( auto vm = vmpool->get(vid) )
{
if ( vm->get_state() != VirtualMachine::ACTIVE )
auto state = vm->get_state();
if ( state != VirtualMachine::ACTIVE &&
state != VirtualMachine::POWEROFF &&
state != VirtualMachine::SUSPENDED)
{
vm->log("LCM", Log::ERROR, "clean_action, VM in a wrong state.");
vm->log("LCM", Log::ERROR, "clean_action, VM in a wrong state " + vm->state_str());
return;
}
@ -958,7 +962,7 @@ void LifeCycleManager::trigger_delete_recreate(int vid,
switch (vm->get_lcm_state())
{
case VirtualMachine::CLEANUP_DELETE:
vm->log("LCM", Log::ERROR, "clean_action, VM in a wrong state.");
vm->log("LCM", Log::ERROR, "clean_action, VM in a wrong state " + vm->state_str());
break;
case VirtualMachine::CLEANUP_RESUBMIT:
@ -1015,20 +1019,21 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm, bool dispose,
{
HostShareCapacity sr;
unsigned int port;
time_t the_time = time(0);
VirtualMachine::LcmState state = vm->get_lcm_state();
VirtualMachine::VmState state = vm->get_state();
VirtualMachine::LcmState lcmstate = vm->get_lcm_state();
int vid = vm->get_oid();
if (dispose)
{
vm->set_state(VirtualMachine::ACTIVE);
vm->set_state(VirtualMachine::CLEANUP_DELETE);
vm->set_action(VMActions::DELETE_ACTION, uid, gid, req_id);
}
else
{
vm->set_state(VirtualMachine::ACTIVE);
vm->set_state(VirtualMachine::CLEANUP_RESUBMIT);
vm->set_action(VMActions::DELETE_RECREATE_ACTION, uid, gid, req_id);
}
@ -1049,15 +1054,23 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm, bool dispose,
hpool->del_capacity(vm->get_hid(), sr);
VectorAttribute * graphics = vm->get_template_attribute("GRAPHICS");
vm->release_vnc_port();
if ( graphics != 0 && (graphics->vector_value("PORT", port) == 0))
if (state == VirtualMachine::POWEROFF ||
state == VirtualMachine::SUSPENDED)
{
graphics->remove("PORT");
clpool->release_vnc_port(vm->get_cid(), port);
}
float memory, cpu;
switch (state)
vm->get_template_attribute("MEMORY", memory);
vm->get_template_attribute("CPU", cpu);
quota_tmpl.add("RUNNING_MEMORY", -memory);
quota_tmpl.add("RUNNING_CPU", -cpu);
quota_tmpl.add("RUNNING_VMS", -1);
vmm->trigger_cleanup(vid, false);
}
else switch (lcmstate)
{
case VirtualMachine::PROLOG:
case VirtualMachine::PROLOG_RESUME:

@ -860,7 +860,6 @@ void LifeCycleManager::trigger_epilog_success(int vid)
HostShareCapacity sr;
time_t the_time = time(0);
unsigned int port;
VirtualMachine::LcmState state;
void (DispatchManager::*action)(int);
@ -921,14 +920,10 @@ void LifeCycleManager::trigger_epilog_success(int vid)
vm->set_etime(the_time);
VectorAttribute * graphics = vm->get_template_attribute("GRAPHICS");
//Do not free VNC ports for STOP as it is stored in checkpoint file
if ( graphics != nullptr && (graphics->vector_value("PORT", port) == 0) &&
state != VirtualMachine::EPILOG_STOP )
if ( state != VirtualMachine::EPILOG_STOP )
{
graphics->remove("PORT");
clpool->release_vnc_port(vm->get_cid(), port);
vm->release_vnc_port();
}
vmpool->update_history(vm.get());

@ -4183,8 +4183,40 @@ void VirtualMachine::get_quota_template(VirtualMachineTemplate& quota_tmpl,
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachine::release_vnc_port()
{
if (!hasHistory())
{
return;
}
ClusterPool * cpool = Nebula::instance().get_clpool();
VectorAttribute * graphics = get_template_attribute("GRAPHICS");
unsigned int port;
if (graphics == nullptr ||
graphics->vector_value("PORT", port) != 0)
{
return;
}
cpool->release_vnc_port(get_cid(), port);
graphics->remove("PORT");
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachine::release_previous_vnc_port()
{
if (!hasPreviousHistory())
{
return;
}
ClusterPool * cpool = Nebula::instance().get_clpool();
VectorAttribute * graphics = get_template_attribute("GRAPHICS");

@ -1353,7 +1353,7 @@ void VirtualMachineManager::trigger_driver_cancel(int vid)
return;
error_history:
os << "driver_cacncel_action, VM has no history";
os << "driver_cancel_action, VM has no history";
goto error_common;
error_driver: