mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-22 13:33:52 +03:00
B #5006: Increment running quotas through monitor
(cherry picked from commit aa9be35504
)
This commit is contained in:
parent
998f2ddd1e
commit
22ff6b50f2
@ -486,14 +486,37 @@ private:
|
||||
*/
|
||||
void free_vm_resources(VirtualMachine * vm, bool check_images);
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// DM Actions associated with a VM state transition
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
void suspend_success_action(int vid);
|
||||
|
||||
void stop_success_action(int vid);
|
||||
|
||||
void undeploy_success_action(int vid);
|
||||
|
||||
void poweroff_success_action(int vid);
|
||||
|
||||
void done_action(int vid);
|
||||
|
||||
void resubmit_action(int vid);
|
||||
|
||||
/**
|
||||
* Fill a template only with the necessary attributes to update the quotas
|
||||
* @param vm with the attributes
|
||||
* @param template that will be filled
|
||||
* @param only_running true to not add CPU, MEMORY and VMS counters
|
||||
*/
|
||||
void get_quota_template(VirtualMachine * vm,
|
||||
VirtualMachineTemplate& quota_tmpl, bool only_running) const;
|
||||
* Function to execute the Manager action loop method within a new pthread
|
||||
* (requires C linkage)
|
||||
*/
|
||||
friend void * dm_action_loop(void *arg);
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Action Listener interface
|
||||
// -------------------------------------------------------------------------
|
||||
void finalize_action(const ActionRequest& ar)
|
||||
{
|
||||
NebulaLog::log("DiM",Log::INFO,"Stopping Dispatch Manager...");
|
||||
};
|
||||
|
||||
void user_action(const ActionRequest& ar);
|
||||
};
|
||||
|
||||
#endif /*DISPATCH_MANAGER_H*/
|
||||
|
@ -1020,6 +1020,13 @@ public:
|
||||
*/
|
||||
bool is_pinned() const;
|
||||
|
||||
/**
|
||||
* Fill a template only with the necessary attributes to update the quotas
|
||||
* @param qtmpl template that will be filled
|
||||
* @param only_running true to not add CPU, MEMORY and VMS counters
|
||||
*/
|
||||
void get_quota_template(VirtualMachineTemplate& qtmpl, bool only_running);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Virtual Machine Disks
|
||||
// ------------------------------------------------------------------------
|
||||
|
@ -55,39 +55,3 @@ void DispatchManager::init_managers()
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void DispatchManager::get_quota_template(VirtualMachine * vm,
|
||||
VirtualMachineTemplate& quota_tmpl, bool only_running) const
|
||||
{
|
||||
std::string memory, cpu;
|
||||
|
||||
vm->get_template_attribute("MEMORY", memory);
|
||||
vm->get_template_attribute("CPU", cpu);
|
||||
|
||||
if ( (vm->get_state() == VirtualMachine::ACTIVE) ||
|
||||
(vm->get_state() == VirtualMachine::PENDING) ||
|
||||
(vm->get_state() == VirtualMachine::CLONING) ||
|
||||
(vm->get_state() == VirtualMachine::CLONING_FAILURE) ||
|
||||
(vm->get_state() == VirtualMachine::HOLD) )
|
||||
{
|
||||
quota_tmpl.add("RUNNING_MEMORY", memory);
|
||||
quota_tmpl.add("RUNNING_CPU", cpu);
|
||||
quota_tmpl.add("RUNNING_VMS", 1);
|
||||
|
||||
if (only_running)
|
||||
{
|
||||
quota_tmpl.add("MEMORY", 0);
|
||||
quota_tmpl.add("CPU", 0);
|
||||
quota_tmpl.add("VMS", 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
quota_tmpl.add("MEMORY", memory);
|
||||
quota_tmpl.add("CPU", cpu);
|
||||
quota_tmpl.add("VMS", 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
|
@ -73,7 +73,7 @@ int DispatchManager::deploy(VirtualMachine * vm, const RequestAttributes& ra)
|
||||
uid = vm->get_uid();
|
||||
gid = vm->get_gid();
|
||||
|
||||
get_quota_template(vm, quota_tmpl, true);
|
||||
vm->get_quota_template(quota_tmpl, true);
|
||||
}
|
||||
|
||||
lcm->trigger_deploy(vid);
|
||||
@ -156,7 +156,7 @@ int DispatchManager::import(VirtualMachine * vm, const RequestAttributes& ra)
|
||||
uid = vm->get_uid();
|
||||
gid = vm->get_gid();
|
||||
|
||||
get_quota_template(vm, quota_tmpl, true);
|
||||
vm->get_quota_template(quota_tmpl, true);
|
||||
|
||||
do_quotas = true;
|
||||
}
|
||||
@ -1248,7 +1248,7 @@ int DispatchManager::delete_recreate(VirtualMachine * vm,
|
||||
|
||||
if ( do_quotas )
|
||||
{
|
||||
get_quota_template(vm, quota_tmpl, true);
|
||||
vm->get_quota_template(quota_tmpl, true);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -26,11 +26,6 @@ using namespace std;
|
||||
void DispatchManager::trigger_suspend_success(int vid)
|
||||
{
|
||||
trigger([this, vid] {
|
||||
VirtualMachineTemplate quota_tmpl;
|
||||
string error_str;
|
||||
|
||||
int uid, gid;
|
||||
|
||||
VirtualMachine * vm = vmpool->get(vid);
|
||||
|
||||
if (vm == nullptr)
|
||||
@ -46,13 +41,22 @@ void DispatchManager::trigger_suspend_success(int vid)
|
||||
vm->get_lcm_state() == VirtualMachine::DISK_SNAPSHOT_REVERT_SUSPENDED||
|
||||
vm->get_lcm_state() == VirtualMachine::DISK_SNAPSHOT_DELETE_SUSPENDED))
|
||||
{
|
||||
get_quota_template(vm, quota_tmpl, true);
|
||||
VirtualMachineTemplate quota_tmpl;
|
||||
|
||||
vm->get_quota_template(quota_tmpl, true);
|
||||
|
||||
vm->set_state(VirtualMachine::SUSPENDED);
|
||||
|
||||
vm->set_state(VirtualMachine::LCM_INIT);
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
int uid = vm->get_uid();
|
||||
int gid = vm->get_gid();
|
||||
|
||||
vm->unlock();
|
||||
|
||||
Quotas::vm_del(uid, gid, "a_tmpl);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -65,13 +69,6 @@ void DispatchManager::trigger_suspend_success(int vid)
|
||||
vm->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
uid = vm->get_uid();
|
||||
gid = vm->get_gid();
|
||||
|
||||
vm->unlock();
|
||||
|
||||
Quotas::vm_del(uid, gid, "a_tmpl);
|
||||
});
|
||||
}
|
||||
|
||||
@ -81,11 +78,6 @@ void DispatchManager::trigger_suspend_success(int vid)
|
||||
void DispatchManager::trigger_stop_success(int vid)
|
||||
{
|
||||
trigger([this, vid] {
|
||||
VirtualMachineTemplate quota_tmpl;
|
||||
string error_str;
|
||||
|
||||
int uid, gid;
|
||||
|
||||
VirtualMachine * vm = vmpool->get(vid);
|
||||
|
||||
if (vm == nullptr)
|
||||
@ -97,7 +89,9 @@ void DispatchManager::trigger_stop_success(int vid)
|
||||
(vm->get_lcm_state() == VirtualMachine::EPILOG_STOP ||
|
||||
vm->get_lcm_state() == VirtualMachine::PROLOG_RESUME))
|
||||
{
|
||||
get_quota_template(vm, quota_tmpl, true);
|
||||
VirtualMachineTemplate quota_tmpl;
|
||||
|
||||
vm->get_quota_template(quota_tmpl, true);
|
||||
|
||||
vm->set_state(VirtualMachine::STOPPED);
|
||||
|
||||
@ -112,6 +106,13 @@ void DispatchManager::trigger_stop_success(int vid)
|
||||
}
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
int uid = vm->get_uid();
|
||||
int gid = vm->get_gid();
|
||||
|
||||
vm->unlock();
|
||||
|
||||
Quotas::vm_del(uid, gid, "a_tmpl);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -123,13 +124,6 @@ void DispatchManager::trigger_stop_success(int vid)
|
||||
vm->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
uid = vm->get_uid();
|
||||
gid = vm->get_gid();
|
||||
|
||||
vm->unlock();
|
||||
|
||||
Quotas::vm_del(uid, gid, "a_tmpl);
|
||||
});
|
||||
}
|
||||
|
||||
@ -139,11 +133,6 @@ void DispatchManager::trigger_stop_success(int vid)
|
||||
void DispatchManager::trigger_undeploy_success(int vid)
|
||||
{
|
||||
trigger([this, vid] {
|
||||
VirtualMachineTemplate quota_tmpl;
|
||||
string error_str;
|
||||
|
||||
int uid, gid;
|
||||
|
||||
VirtualMachine * vm = vmpool->get(vid);
|
||||
|
||||
if (vm == nullptr)
|
||||
@ -156,7 +145,9 @@ void DispatchManager::trigger_undeploy_success(int vid)
|
||||
vm->get_lcm_state() == VirtualMachine::DISK_RESIZE_UNDEPLOYED ||
|
||||
vm->get_lcm_state() == VirtualMachine::PROLOG_UNDEPLOY))
|
||||
{
|
||||
get_quota_template(vm, quota_tmpl, true);
|
||||
VirtualMachineTemplate quota_tmpl;
|
||||
|
||||
vm->get_quota_template(quota_tmpl, true);
|
||||
|
||||
vm->set_state(VirtualMachine::UNDEPLOYED);
|
||||
|
||||
@ -171,6 +162,13 @@ void DispatchManager::trigger_undeploy_success(int vid)
|
||||
}
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
int uid = vm->get_uid();
|
||||
int gid = vm->get_gid();
|
||||
|
||||
vm->unlock();
|
||||
|
||||
Quotas::vm_del(uid, gid, "a_tmpl);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -183,13 +181,6 @@ void DispatchManager::trigger_undeploy_success(int vid)
|
||||
vm->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
uid = vm->get_uid();
|
||||
gid = vm->get_gid();
|
||||
|
||||
vm->unlock();
|
||||
|
||||
Quotas::vm_del(uid, gid, "a_tmpl);
|
||||
});
|
||||
}
|
||||
|
||||
@ -199,11 +190,6 @@ void DispatchManager::trigger_undeploy_success(int vid)
|
||||
void DispatchManager::trigger_poweroff_success(int vid)
|
||||
{
|
||||
trigger([this, vid] {
|
||||
VirtualMachineTemplate quota_tmpl;
|
||||
string error_str;
|
||||
|
||||
int uid, gid;
|
||||
|
||||
VirtualMachine * vm = vmpool->get(vid);
|
||||
|
||||
if (vm == nullptr)
|
||||
@ -225,13 +211,27 @@ void DispatchManager::trigger_poweroff_success(int vid)
|
||||
vm->get_lcm_state() == VirtualMachine::HOTPLUG_NIC_POWEROFF ||
|
||||
vm->get_lcm_state() == VirtualMachine::PROLOG_MIGRATE_POWEROFF_FAILURE))
|
||||
{
|
||||
get_quota_template(vm, quota_tmpl, true);
|
||||
VirtualMachineTemplate quota_tmpl;
|
||||
|
||||
vm->get_quota_template(quota_tmpl, true);
|
||||
|
||||
vm->set_state(VirtualMachine::POWEROFF);
|
||||
|
||||
vm->set_state(VirtualMachine::LCM_INIT);
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
int uid = vm->get_uid();
|
||||
int gid = vm->get_gid();
|
||||
|
||||
vm->unlock();
|
||||
|
||||
if (prev_state != VirtualMachine::DISK_SNAPSHOT_POWEROFF &&
|
||||
prev_state != VirtualMachine::DISK_SNAPSHOT_REVERT_POWEROFF &&
|
||||
prev_state != VirtualMachine::DISK_SNAPSHOT_DELETE_POWEROFF)
|
||||
{
|
||||
Quotas::vm_del(uid, gid, "a_tmpl);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -244,18 +244,6 @@ void DispatchManager::trigger_poweroff_success(int vid)
|
||||
vm->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
uid = vm->get_uid();
|
||||
gid = vm->get_gid();
|
||||
|
||||
vm->unlock();
|
||||
|
||||
if (prev_state != VirtualMachine::DISK_SNAPSHOT_POWEROFF &&
|
||||
prev_state != VirtualMachine::DISK_SNAPSHOT_REVERT_POWEROFF &&
|
||||
prev_state != VirtualMachine::DISK_SNAPSHOT_DELETE_POWEROFF)
|
||||
{
|
||||
Quotas::vm_del(uid, gid, "a_tmpl);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -265,11 +253,6 @@ void DispatchManager::trigger_poweroff_success(int vid)
|
||||
void DispatchManager::trigger_done(int vid)
|
||||
{
|
||||
trigger([this, vid] {
|
||||
string error_str;
|
||||
|
||||
VirtualMachine::LcmState lcm_state;
|
||||
VirtualMachine::VmState dm_state;
|
||||
|
||||
VirtualMachine * vm = vmpool->get(vid);
|
||||
|
||||
if (vm == nullptr)
|
||||
@ -277,8 +260,8 @@ void DispatchManager::trigger_done(int vid)
|
||||
return;
|
||||
}
|
||||
|
||||
lcm_state = vm->get_lcm_state();
|
||||
dm_state = vm->get_state();
|
||||
VirtualMachine::LcmState lcm_state = vm->get_lcm_state();
|
||||
VirtualMachine::VmState dm_state = vm->get_state();
|
||||
|
||||
if ((dm_state == VirtualMachine::ACTIVE) &&
|
||||
(lcm_state == VirtualMachine::EPILOG ||
|
||||
|
@ -1150,9 +1150,7 @@ void LifeCycleManager::trigger_monitor_poweroff(int vid)
|
||||
void LifeCycleManager::trigger_monitor_poweron(int vid)
|
||||
{
|
||||
trigger([this, vid] {
|
||||
VirtualMachine * vm;
|
||||
|
||||
vm = vmpool->get(vid);
|
||||
VirtualMachine * vm = vmpool->get(vid);
|
||||
|
||||
if ( vm == nullptr )
|
||||
{
|
||||
@ -1162,6 +1160,12 @@ void LifeCycleManager::trigger_monitor_poweron(int vid)
|
||||
if ( vm->get_state() == VirtualMachine::POWEROFF ||
|
||||
vm->get_state() == VirtualMachine::SUSPENDED )
|
||||
{
|
||||
VirtualMachineTemplate quota_tmpl;
|
||||
string error;
|
||||
|
||||
int uid = vm->get_uid();
|
||||
int gid = vm->get_gid();
|
||||
|
||||
vm->log("VMM",Log::INFO,"VM found again by the drivers");
|
||||
|
||||
time_t the_time = time(0);
|
||||
@ -1183,6 +1187,12 @@ void LifeCycleManager::trigger_monitor_poweron(int vid)
|
||||
vmpool->insert_history(vm);
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
vm->get_quota_template(quota_tmpl, true);
|
||||
|
||||
vm->unlock();
|
||||
|
||||
Quotas::vm_check(uid, gid, "a_tmpl, error);
|
||||
}
|
||||
else if ( vm->get_state() == VirtualMachine::ACTIVE )
|
||||
{
|
||||
@ -1213,9 +1223,9 @@ void LifeCycleManager::trigger_monitor_poweron(int vid)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
vm->unlock();
|
||||
vm->unlock();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -3623,3 +3623,39 @@ void VirtualMachine::decrypt()
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
void VirtualMachine::get_quota_template(VirtualMachineTemplate& quota_tmpl,
|
||||
bool only_running)
|
||||
{
|
||||
std::string memory, cpu;
|
||||
|
||||
get_template_attribute("MEMORY", memory);
|
||||
get_template_attribute("CPU", cpu);
|
||||
|
||||
if ((state == VirtualMachine::ACTIVE) ||
|
||||
(state == VirtualMachine::PENDING) ||
|
||||
(state == VirtualMachine::CLONING) ||
|
||||
(state == VirtualMachine::CLONING_FAILURE) ||
|
||||
(state == VirtualMachine::HOLD) )
|
||||
{
|
||||
quota_tmpl.add("RUNNING_MEMORY", memory);
|
||||
quota_tmpl.add("RUNNING_CPU", cpu);
|
||||
quota_tmpl.add("RUNNING_VMS", 1);
|
||||
|
||||
if (only_running)
|
||||
{
|
||||
quota_tmpl.add("MEMORY", 0);
|
||||
quota_tmpl.add("CPU", 0);
|
||||
quota_tmpl.add("VMS", 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
quota_tmpl.add("MEMORY", memory);
|
||||
quota_tmpl.add("CPU", cpu);
|
||||
quota_tmpl.add("VMS", 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user