2012-05-27 23:15:05 +02:00
/* -------------------------------------------------------------------------- */
2018-01-02 18:27:37 +01:00
/* Copyright 2002-2018, OpenNebula Project, OpenNebula Systems */
2012-05-27 23:15:05 +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. */
/* -------------------------------------------------------------------------- */
2012-06-02 02:58:46 +02:00
# ifndef QUOTA_DATASTORE_H_
# define QUOTA_DATASTORE_H_
2012-05-27 23:15:05 +02:00
# include "Quota.h"
/**
2012-06-02 02:58:46 +02:00
* DataStore Quotas , defined as :
* DATASTORE = [
2012-06-04 00:45:56 +02:00
* ID = < ID of the datastore >
2012-05-27 23:15:05 +02: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 02:58:46 +02:00
class QuotaDatastore : public Quota
2012-05-27 23:15:05 +02:00
{
2012-05-28 00:13:38 +02:00
public :
2012-11-30 00:16:52 +01:00
QuotaDatastore ( bool is_default ) :
Quota ( " DATASTORE_QUOTA " ,
" DATASTORE " ,
DS_METRICS ,
NUM_DS_METRICS ,
is_default )
2012-06-05 13:34:28 +02:00
{ } ;
2012-05-27 23:15:05 +02:00
2012-06-02 02:58:46 +02:00
~ QuotaDatastore ( ) { } ;
2012-05-27 23:15:05 +02:00
/**
2012-11-30 00:16:52 +01:00
* Check if the resource allocation will exceed the quota limits . If not
2012-05-29 00:36:13 +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-05-27 23:15:05 +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-05-27 23:15:05 +02:00
/**
* Decrement usage counters when deallocating image
2012-05-29 00:36:13 +02:00
* @ param tmpl template for the resource
2012-05-27 23:15:05 +02:00
*/
2012-05-30 02:20:16 +02:00
void del ( Template * tmpl ) ;
2012-05-27 23:15:05 +02:00
protected :
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-19 16:38:39 +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 13:34:28 +02:00
static const char * DS_METRICS [ ] ;
2012-05-27 23:15:05 +02:00
2012-06-05 13:34:28 +02:00
static const int NUM_DS_METRICS ;
2012-05-27 23:15:05 +02:00
} ;
2012-11-19 15:19:09 +01:00
# endif /*QUOTA_DATASTORE_H_*/