mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
B #5006: Increment running quotas through monitor
This commit is contained in:
parent
0958011a3d
commit
aa9be35504
@ -597,14 +597,6 @@ private:
|
||||
|
||||
void user_action(const ActionRequest& ar);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
};
|
||||
|
||||
#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
|
||||
// ------------------------------------------------------------------------
|
||||
|
@ -114,41 +114,6 @@ void DispatchManager::init_managers()
|
||||
upool = nd.get_upool();
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void DispatchManager::get_quota_template(VirtualMachine * vm,
|
||||
VirtualMachineTemplate& quota_tmpl, bool only_running)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -66,7 +66,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(LCMAction::DEPLOY, vid, ra);
|
||||
@ -149,7 +149,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;
|
||||
}
|
||||
@ -1231,7 +1231,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;
|
||||
|
||||
|
@ -42,7 +42,7 @@ void DispatchManager::suspend_success_action(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);
|
||||
vm->get_quota_template(quota_tmpl, true);
|
||||
|
||||
vm->set_state(VirtualMachine::SUSPENDED);
|
||||
|
||||
@ -94,7 +94,7 @@ void DispatchManager::stop_success_action(int vid)
|
||||
(vm->get_lcm_state() == VirtualMachine::EPILOG_STOP ||
|
||||
vm->get_lcm_state() == VirtualMachine::PROLOG_RESUME))
|
||||
{
|
||||
get_quota_template(vm, quota_tmpl, true);
|
||||
vm->get_quota_template(quota_tmpl, true);
|
||||
|
||||
vm->set_state(VirtualMachine::STOPPED);
|
||||
|
||||
@ -154,7 +154,7 @@ void DispatchManager::undeploy_success_action(int vid)
|
||||
vm->get_lcm_state() == VirtualMachine::DISK_RESIZE_UNDEPLOYED ||
|
||||
vm->get_lcm_state() == VirtualMachine::PROLOG_UNDEPLOY))
|
||||
{
|
||||
get_quota_template(vm, quota_tmpl, true);
|
||||
vm->get_quota_template(quota_tmpl, true);
|
||||
|
||||
vm->set_state(VirtualMachine::UNDEPLOYED);
|
||||
|
||||
@ -225,7 +225,7 @@ void DispatchManager::poweroff_success_action(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);
|
||||
vm->get_quota_template(quota_tmpl, true);
|
||||
|
||||
vm->set_state(VirtualMachine::POWEROFF);
|
||||
|
||||
|
@ -1141,6 +1141,14 @@ void LifeCycleManager::monitor_poweron_action(int vid)
|
||||
{
|
||||
vm->log("VMM",Log::INFO,"VM found again by the drivers");
|
||||
|
||||
VirtualMachineTemplate quota_tmpl;
|
||||
|
||||
string error;
|
||||
|
||||
int uid = vm->get_uid();
|
||||
|
||||
int gid = vm->get_gid();
|
||||
|
||||
time_t the_time = time(0);
|
||||
|
||||
vm->set_state(VirtualMachine::ACTIVE);
|
||||
@ -1159,7 +1167,11 @@ void LifeCycleManager::monitor_poweron_action(int vid)
|
||||
|
||||
vmpool->insert_history(vm);
|
||||
|
||||
vm->get_quota_template(quota_tmpl, true);
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
Quotas::vm_check(uid, gid, "a_tmpl, error);
|
||||
}
|
||||
else if ( vm->get_state() == VirtualMachine::ACTIVE )
|
||||
{
|
||||
|
@ -3621,3 +3621,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…
x
Reference in New Issue
Block a user