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