mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-22 13:33:52 +03:00
B OpenNebula/one#6542: Fix scheduled actions for VM in done state (#3008)
* Do not allow creating a Scheduled Action for VM in done state * Fix removing of Scheduled Action, while terminating VM * Fix failure output for new object types
This commit is contained in:
parent
be64cbdf04
commit
0b3d6136e9
@ -30,6 +30,7 @@
|
||||
#include "VirtualNetworkPool.h"
|
||||
#include "VirtualRouterPool.h"
|
||||
#include "SecurityGroupPool.h"
|
||||
#include "ScheduledActionPool.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -368,6 +369,8 @@ void DispatchManager::free_vm_resources(unique_ptr<VirtualMachine> vm,
|
||||
vrid = vm->get_vrouter_id();
|
||||
}
|
||||
|
||||
std::set<int> sa_ids(vm->sched_actions().get_collection());
|
||||
|
||||
vm.reset(); //force unlock of vm mutex
|
||||
|
||||
Quotas::vm_del(uid, gid, quota_tmpl.get());
|
||||
@ -391,6 +394,28 @@ void DispatchManager::free_vm_resources(unique_ptr<VirtualMachine> vm,
|
||||
vrouterpool->update(vr.get());
|
||||
}
|
||||
}
|
||||
|
||||
auto sapool = Nebula::instance().get_sapool();
|
||||
|
||||
int rc = 0;
|
||||
string error;
|
||||
|
||||
for (const auto& id: sa_ids)
|
||||
{
|
||||
if (auto sa = sapool->get(id))
|
||||
{
|
||||
rc += sapool->drop(sa.get(), error);
|
||||
}
|
||||
}
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
oss << "Some schedules for VM " << vmid << " could not be removed";
|
||||
NebulaLog::log("DiM", Log::ERROR, oss);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include "Quotas.h"
|
||||
#include "Nebula.h"
|
||||
#include "VirtualMachinePool.h"
|
||||
#include "ScheduledActionPool.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -271,30 +270,7 @@ void DispatchManager::trigger_done(int vid)
|
||||
(lcm_state == VirtualMachine::EPILOG ||
|
||||
lcm_state == VirtualMachine::CLEANUP_DELETE))
|
||||
{
|
||||
string error;
|
||||
int rc = 0;
|
||||
|
||||
std::set<int> sa_ids(vm->sched_actions().get_collection());
|
||||
|
||||
free_vm_resources(std::move(vm), true);
|
||||
|
||||
auto sapool = Nebula::instance().get_sapool();
|
||||
|
||||
for (const auto& id: sa_ids)
|
||||
{
|
||||
if (auto sa = sapool->get(id))
|
||||
{
|
||||
rc += sapool->drop(sa.get(), error);
|
||||
}
|
||||
}
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
oss << "Some schedules for VM " << vid << " could not be removed";
|
||||
NebulaLog::log("DiM", Log::ERROR, oss);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -81,6 +81,10 @@ string Request::object_name(PoolObjectSQL::ObjectType ob)
|
||||
return "virtual network template";
|
||||
case PoolObjectSQL::HOOK:
|
||||
return "hook";
|
||||
case PoolObjectSQL::BACKUPJOB:
|
||||
return "backup job";
|
||||
case PoolObjectSQL::SCHEDULEDACTION:
|
||||
return "scheduled action";
|
||||
default:
|
||||
return "-";
|
||||
}
|
||||
|
@ -36,6 +36,16 @@ void RequestManagerSchedAdd::request_execute(xmlrpc_c::paramList const& paramLis
|
||||
if ( auto vm = pool->get_ro<VirtualMachine>(oid) )
|
||||
{
|
||||
stime = vm->get_stime();
|
||||
|
||||
if (vm->get_state() == VirtualMachine::DONE)
|
||||
{
|
||||
att.resp_id = oid;
|
||||
att.resp_msg = "Unable to create Scheduled Action for Virtual Machine "
|
||||
+ to_string(oid) + ", it's in DONE state";
|
||||
|
||||
failure_response(INTERNAL, att);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -154,6 +164,14 @@ void RequestManagerSchedDelete::request_execute(xmlrpc_c::paramList const& param
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_obj = PoolObjectSQL::SCHEDULEDACTION;
|
||||
att.resp_id = sched_id;
|
||||
failure_response(NO_EXISTS, att);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
att.resp_obj = PoolObjectSQL::SCHEDULEDACTION;
|
||||
att.resp_id = sched_id;
|
||||
|
Loading…
Reference in New Issue
Block a user