From 1235866e51fda8302a3bf415c81b9fe1630b4724 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Wed, 5 Sep 2018 15:14:39 +0200 Subject: [PATCH] F #2228: Added new VM quota - RUNNING_MEMORY, RUNNING_CPU and RUNNING_VMS. These running quotas are for all states included in ACTIVE and VMS being scheduled (PENDING and HOLD) as those states consume the same resources (in terms of allocation) as running VMs. Author: juanmont --- include/DispatchManager.h | 17 +- include/QuotaVirtualMachine.h | 21 +- include/Quotas.h | 28 ++- src/cli/one_helper/onegroup_helper.rb | 54 +++-- src/cli/one_helper/onequota_helper.rb | 115 +++++++++- src/cli/one_helper/oneuser_helper.rb | 54 +++-- src/dm/DispatchManager.cc | 40 ++++ src/dm/DispatchManagerActions.cc | 96 ++++++++- src/dm/DispatchManagerStates.cc | 59 ++++- src/rm/RequestManagerAllocate.cc | 10 + src/rm/RequestManagerClone.cc | 1 - src/rm/RequestManagerVMTemplate.cc | 9 + src/rm/RequestManagerVirtualMachine.cc | 31 ++- .../public/app/utils/quotas/quota-defaults.js | 29 ++- .../public/app/utils/quotas/quota-widgets.js | 202 ++++++++++++++++-- src/um/QuotaVirtualMachine.cc | 91 ++++++-- src/um/Quotas.cc | 42 ++++ src/vm/VirtualMachine.cc | 3 + 18 files changed, 799 insertions(+), 103 deletions(-) diff --git a/include/DispatchManager.h b/include/DispatchManager.h index d1cfc580c7..194e4484b8 100644 --- a/include/DispatchManager.h +++ b/include/DispatchManager.h @@ -22,6 +22,7 @@ #include "VirtualMachinePool.h" #include "VirtualRouterPool.h" #include "ClusterPool.h" +#include "UserPool.h" using namespace std; @@ -493,10 +494,15 @@ private: HostPool * hpool; /** - * Pointer to the Virtual Machine Pool, to access hosts + * Pointer to the Virtual Machine Pool, to access VMs */ VirtualMachinePool * vmpool; + /** + * Pointer to the User Pool, to access user + */ + UserPool * upool; + /** * Pointer to the Cluster Pool */ @@ -568,6 +574,15 @@ 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*/ diff --git a/include/QuotaVirtualMachine.h b/include/QuotaVirtualMachine.h index 6ae6030f00..19440ecd26 100644 --- a/include/QuotaVirtualMachine.h +++ b/include/QuotaVirtualMachine.h @@ -22,13 +22,19 @@ /** * VM Quotas, defined as: * VM = [ - * VMS = - * MEMORY = - * CPU = - * SYSTEM_DISK_SIZE = - * VMS_USED = Current number of VMs - * MEMORY_USED = Overall Memory requested - * CPU_USED = Overall CPU requested + * VMS = + * RUNNING_VMS = + * MEMORY = + * RUNNING_MEMORY = + * CPU = + * RUNNING_CPU = + * SYSTEM_DISK_SIZE = + * VMS_USED = Current number of VMs + * RUNNING_VMS_USED = Current number of running VMs + * MEMORY_USED = Overall Memory requested + * RUNNING_MEMORY_USED = Overall running Memory requested + * CPU_USED = Overall CPU requested + * RUNNING_CPU_USED = Overall running CPU requested * SYSTEM_DISK_SIZE_USED = Overall system disk requested * ] * @@ -121,6 +127,7 @@ protected: static const char * VM_METRICS[]; static const int NUM_VM_METRICS; + }; #endif /*QUOTA_VIRTUALMACHINE_H_*/ diff --git a/include/Quotas.h b/include/Quotas.h index 11004a61e5..1c75df9543 100644 --- a/include/Quotas.h +++ b/include/Quotas.h @@ -162,13 +162,26 @@ public: * for the given user and group * @param uid of the user * @param gid of the group - * @param tmpl template for the image, with usage + * @param tmpl template for the vm with usage */ static void vm_del(int uid, int gid, Template * tmpl) { quota_del(VIRTUALMACHINE, uid, gid, tmpl); } + /** + * Check VM related usage (network, image and compute) from quota counters + * for the given user and group. Quotas are updated if not exceeded. + * @param uid of the user + * @param gid of the group + * @param tmpl template for the vm with usage + * @param error string + */ + static void vm_check(int uid, int gid, Template * tmpl, string& error) + { + quota_check(VIRTUALMACHINE, uid, gid, tmpl, error); + } + /** * Delete Datastore related usage from quota counters. * for the given user and group @@ -209,8 +222,7 @@ public: static void ds_del_recreate(int uid, int gid, vector