2012-05-28 01:15:05 +04:00
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) */
/* */
/* 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-06-02 04:58:46 +04:00
QuotaDatastore ( ) : Quota ( " DATASTORE_QUOTA " ) { } ;
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-05-29 02:36:13 +04:00
* Check if the resource allocation will exceed the quota limits . If not
* the usage counters are updated
* @ param tmpl template for the resource
2012-05-28 01:15:05 +04:00
* @ param error string
* @ return true if the operation can be performed
*/
2012-06-04 02:45:56 +04:00
bool check ( Template * tmpl , 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 :
/**
* Sets new limit values for the quota
* @ param quota to be updated
* @ param va attribute with the new limits
* @ return 0 on success or - 1 if wrong limits
*/
2012-06-05 03:58:37 +04:00
/*int update_limits(VectorAttribute* quota,
const VectorAttribute * va ) ; */
2012-05-28 01:15:05 +04:00
/**
* Creates an empty quota based on the given attribute . The attribute va
* contains the limits for the quota .
* @ param va limits for the new quota if 0 limits will be 0
* @ return a new attribute representing the quota
*/
2012-06-04 02:45:56 +04:00
VectorAttribute * new_quota ( VectorAttribute * va ) ;
2012-05-28 01:15:05 +04:00
private :
2012-06-02 04:58:46 +04:00
2012-05-28 01:15:05 +04:00
/**
* Return the limits for image and size stored in the a given quota .
* @ param va_ptr the attribute that stores the quota
2012-06-04 02:45:56 +04:00
* @ param ds the id of the DATASTORE quota
* @ param imgs the limit for the number of images
2012-05-28 01:15:05 +04:00
* @ param size the limit for the total storage size
*
* @ return - 1 if the limits are wrong 0 otherwise
*/
2012-06-04 02:45:56 +04:00
int get_limits ( const VectorAttribute * va ,
string & ds ,
string & imgs ,
string & size ) ;
2012-05-28 01:15:05 +04:00
} ;
2012-06-02 04:58:46 +04:00
# endif /*QUOTA_DATASTORE_H_*/