2012-05-28 01:15:05 +04:00
/* -------------------------------------------------------------------------- */
2022-04-07 20:49:58 +03:00
/* Copyright 2002-2022, OpenNebula Project, OpenNebula Systems */
2012-05-28 01:15:05 +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. */
/* -------------------------------------------------------------------------- */
2012-06-02 04:58:46 +04:00
# ifndef QUOTA_DATASTORE_H_
# define QUOTA_DATASTORE_H_
2012-05-28 01:15:05 +04:00
# include "Quota.h"
/**
2012-06-02 04:58:46 +04:00
* DataStore Quotas , defined as :
* DATASTORE = [
2012-06-04 02:45:56 +04:00
* ID = < ID of the datastore >
2012-05-28 01:15:05 +04:00
* IMAGES = < Max . number of images allowed in the datastore >
* SIZE = < Max . number of MB used in the datastore >
* IMAGES_USED = Current number of images in the datastore
* SIZE_USED = Current storage capacity un the datastore
* ]
*
* 0 = unlimited , default if missing
*/
2012-06-02 04:58:46 +04:00
class QuotaDatastore : public Quota
2012-05-28 01:15:05 +04:00
{
2012-05-28 02:13:38 +04:00
public :
2012-11-30 03:16:52 +04:00
QuotaDatastore ( bool is_default ) :
Quota ( " DATASTORE_QUOTA " ,
" DATASTORE " ,
DS_METRICS ,
NUM_DS_METRICS ,
is_default )
2012-06-05 15:34:28 +04:00
{ } ;
2012-05-28 01:15:05 +04:00
2012-06-02 04:58:46 +04:00
~ QuotaDatastore ( ) { } ;
2012-05-28 01:15:05 +04:00
/**
2012-11-30 03:16:52 +04:00
* Check if the resource allocation will exceed the quota limits . If not
2012-05-29 02:36:13 +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-05-28 01:15:05 +04:00
* @ return true if the operation can be performed
*/
2020-07-02 23:42:10 +03:00
bool check ( Template * tmpl , Quotas & default_quotas , std : : string & error ) ;
2012-05-28 01:15:05 +04:00
/**
* Decrement usage counters when deallocating image
2012-05-29 02:36:13 +04:00
* @ param tmpl template for the resource
2012-05-28 01:15:05 +04:00
*/
2012-05-30 04:20:16 +04:00
void del ( Template * tmpl ) ;
2012-05-28 01:15:05 +04:00
protected :
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
*/
2020-07-02 23:42:10 +03:00
int get_default_quota ( const std : : string & id ,
2012-11-19 19:38:39 +04:00
Quotas & default_quotas ,
VectorAttribute * * va ) ;
2012-11-19 18:19:09 +04:00
2012-06-05 15:34:28 +04:00
static const char * DS_METRICS [ ] ;
2012-05-28 01:15:05 +04:00
2012-06-05 15:34:28 +04:00
static const int NUM_DS_METRICS ;
2012-05-28 01:15:05 +04:00
} ;
2012-11-19 18:19:09 +04:00
# endif /*QUOTA_DATASTORE_H_*/