2012-06-05 19:04:02 +02:00
/* -------------------------------------------------------------------------- */
2018-01-02 18:27:37 +01:00
/* Copyright 2002-2018, OpenNebula Project, OpenNebula Systems */
2012-06-05 19:04:02 +02: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 = [
2015-07-21 11:10:22 +02:00
* VMS = < Max . number of VMs >
* MEMORY = < Max . number of MB requested by VMs >
* CPU = < Max . number of CPU units requested by VMs >
* SYSTEM_DISK_SIZE = < Max . number of system disk MB >
* VMS_USED = Current number of VMs
* MEMORY_USED = Overall Memory requested
* CPU_USED = Overall CPU requested
* SYSTEM_DISK_SIZE_USED = Overall system disk requested
2012-06-05 19:04:02 +02:00
* ]
*
* 0 = unlimited , default if missing
*/
class QuotaVirtualMachine : public Quota
{
public :
2012-11-30 00:16:52 +01:00
QuotaVirtualMachine ( bool is_default ) :
Quota ( " VM_QUOTA " ,
" VM " ,
VM_METRICS ,
NUM_VM_METRICS ,
is_default )
2012-06-05 19:04:02 +02:00
{ } ;
~ QuotaVirtualMachine ( ) { } ;
/**
2012-11-30 00:16:52 +01:00
* Check if the resource allocation will exceed the quota limits . If not
2012-06-05 19:04:02 +02:00
* the usage counters are updated
* @ param tmpl template for the resource
2012-11-19 16:38:39 +01:00
* @ param default_quotas Quotas that contain the default limits
2012-11-30 00:16:52 +01:00
* @ param error string
2012-06-05 19:04:02 +02:00
* @ return true if the operation can be performed
*/
2012-11-19 16:38:39 +01:00
bool check ( Template * tmpl , Quotas & default_quotas , string & error ) ;
2012-06-05 19:04:02 +02:00
2013-07-22 22:08:01 +02: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
*/
bool update ( Template * tmpl , Quotas & default_quotas , string & error ) ;
2012-06-05 19:04:02 +02:00
/**
* Decrement usage counters when deallocating image
* @ param tmpl template for the resource
*/
void del ( Template * tmpl ) ;
/**
2012-06-05 23:06:14 +02:00
* Gets a quota , overrides base to not to use ID .
2012-06-19 17:41:42 +02:00
* @ param id of the quota , ignored
* @ param va The quota
*
2012-06-05 19:04:02 +02:00
* @ return a pointer to the quota or 0 if not found
*/
int get_quota ( const string & id , VectorAttribute * * va ) ;
2012-11-19 15:19:09 +01:00
protected :
2012-06-19 17:41:42 +02: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 (
const string & id ,
VectorAttribute * * va ,
map < string , Attribute * > : : iterator & it )
{
2012-06-21 16:32:01 +02:00
it = attributes . begin ( ) ;
2012-06-19 17:41:42 +02:00
return get_quota ( id , va ) ;
}
2012-11-19 15:19:09 +01:00
/**
* Gets the default quota identified by its ID .
*
* @ param id of the quota
2012-11-19 16:38:39 +01:00
* @ param default_quotas Quotas that contain the default limits
2012-11-19 15:19:09 +01:00
* @ param va The quota , if it is found
*
* @ return 0 on success , - 1 if not found
*/
2012-11-30 00:16:52 +01:00
int get_default_quota (
const string & id ,
Quotas & default_quotas ,
VectorAttribute * * va ) ;
2012-11-19 15:19:09 +01:00
2012-06-05 19:04:02 +02:00
static const char * VM_METRICS [ ] ;
static const int NUM_VM_METRICS ;
} ;
2012-06-19 17:41:42 +02:00
# endif /*QUOTA_VIRTUALMACHINE_H_*/