2012-06-05 21:04:02 +04:00
/* -------------------------------------------------------------------------- */
2024-07-29 15:25:20 +03:00
/* Copyright 2002-2024, OpenNebula Project, OpenNebula Systems */
2012-06-05 21:04:02 +04:00
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
# ifndef QUOTA_VIRTUALMACHINE_H_
# define QUOTA_VIRTUALMACHINE_H_
# include "Quota.h"
/**
* VM Quotas , defined as :
* VM = [
2018-09-05 16:14:39 +03:00
* VMS = < Max . number of VMs >
* RUNNING_VMS = < Max . number of RUNNING VMS >
* MEMORY = < Max . number of MB requested by VMs >
* RUNNING_MEMORY = < Max . number of MB requested by RUNNING VMs >
* CPU = < Max . number of CPU units requested by VMs >
* RUNNING_CPU = < Max . number of running CPU units requested by VMs >
* SYSTEM_DISK_SIZE = < Max . number of system disk MB >
* 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
2015-07-21 12:10:22 +03:00
* SYSTEM_DISK_SIZE_USED = Overall system disk requested
2012-06-05 21:04:02 +04:00
* ]
*
* 0 = unlimited , default if missing
*/
2024-01-08 15:56:40 +03:00
class QuotaVirtualMachine : public Quota
2012-06-05 21:04:02 +04:00
{
public :
2012-11-30 03:16:52 +04:00
QuotaVirtualMachine ( bool is_default ) :
Quota ( " VM_QUOTA " ,
" VM " ,
VM_METRICS ,
is_default )
2012-06-05 21:04:02 +04:00
{ } ;
2024-06-03 12:40:24 +03:00
~ QuotaVirtualMachine ( ) { } ;
2012-06-05 21:04:02 +04:00
/**
2012-11-30 03:16:52 +04:00
* Check if the resource allocation will exceed the quota limits . If not
2012-06-05 21:04:02 +04:00
* the usage counters are updated
* @ param tmpl template for the resource
2012-11-19 19:38:39 +04:00
* @ param default_quotas Quotas that contain the default limits
2012-11-30 03:16:52 +04:00
* @ param error string
2012-06-05 21:04:02 +04:00
* @ return true if the operation can be performed
*/
2023-02-07 10:50:30 +03:00
bool check ( Template * tmpl , Quotas & default_quotas , std : : string & error ) override ;
2012-06-05 21:04:02 +04:00
2013-07-23 00:08:01 +04:00
/**
* Check if the resource update ( change in MEMORY or CPU ) will exceed the
* quota limits . If not the usage counters are updated
* @ param tmpl with increments in MEMORY and CPU
* @ param default_quotas Quotas that contain the default limits
* @ param error string
* @ return true if the operation can be performed
*/
2023-02-07 10:50:30 +03:00
bool update ( Template * tmpl , Quotas & default_quotas , std : : string & error ) override ;
2013-07-23 00:08:01 +04:00
2023-12-12 18:19:20 +03:00
/**
* Add usage counters . Use carefully this method does not care about exceeding the quota
* @ param tmpl Template with the quota usage
*/
void add ( Template * tmpl ) ;
2012-06-05 21:04:02 +04:00
/**
* Decrement usage counters when deallocating image
* @ param tmpl template for the resource
*/
2023-02-07 10:50:30 +03:00
void del ( Template * tmpl ) override ;
2012-06-05 21:04:02 +04:00
/**
2012-06-06 01:06:14 +04:00
* Gets a quota , overrides base to not to use ID .
2012-06-19 19:41:42 +04:00
* @ param id of the quota , ignored
* @ param va The quota
*
2012-06-05 21:04:02 +04:00
* @ return a pointer to the quota or 0 if not found
*/
2023-02-07 10:50:30 +03:00
int get_quota ( const std : : string & id , VectorAttribute * * va ) override ;
2012-06-05 21:04:02 +04:00
2024-01-08 15:56:40 +03:00
/**
* Add generic quota to metrics . It adds also RUNNING_ quota attribute
* @ param metric Name of the quota metri
*
* @ return 0 success , - 1 if metric already exists
*/
static int add_metric_generic ( const std : : string & metric ) ;
/**
* Return vector of generic quota metrics
*/
static const std : : vector < std : : string > & generic_metrics ( )
{
return VM_GENERIC ;
}
/*
* Add RUNNING_ quotas for generic metrics present in the template
*/
static void add_running_quota_generic ( Template & tmpl ) ;
2012-11-19 18:19:09 +04:00
protected :
2012-06-19 19:41:42 +04:00
/**
* Gets a quota , overrides base to not to use ID .
*
* @ param id of the quota , ignored
* @ param va The quota
* @ param it The quota iterator , if it is found
*
* @ return 0 on success , - 1 if not found
*/
int get_quota (
2020-07-02 23:42:10 +03:00
const std : : string & id ,
2012-06-19 19:41:42 +04:00
VectorAttribute * * va ,
2023-02-07 10:50:30 +03:00
std : : map < std : : string , Attribute * > : : iterator & it ) override
2012-06-19 19:41:42 +04:00
{
2012-06-21 18:32:01 +04:00
it = attributes . begin ( ) ;
2012-06-19 19:41:42 +04:00
return get_quota ( id , va ) ;
}
2012-11-19 18:19:09 +04:00
/**
* Gets the default quota identified by its ID .
*
* @ param id of the quota
2012-11-19 19:38:39 +04:00
* @ param default_quotas Quotas that contain the default limits
2012-11-19 18:19:09 +04:00
* @ param va The quota , if it is found
*
* @ return 0 on success , - 1 if not found
*/
2012-11-30 03:16:52 +04:00
int get_default_quota (
2024-06-03 12:40:24 +03:00
const std : : string & id ,
Quotas & default_quotas ,
VectorAttribute * * va ) override ;
2012-11-19 18:19:09 +04:00
2024-01-08 15:56:40 +03:00
static std : : vector < std : : string > VM_METRICS ;
static std : : vector < std : : string > VM_GENERIC ;
2012-06-05 21:04:02 +04:00
} ;
2012-06-19 19:41:42 +04:00
# endif /*QUOTA_VIRTUALMACHINE_H_*/