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_NETWORK_H_
# define QUOTA_NETWORK_H_
# include "Quota.h"
2016-02-01 19:07:04 +03:00
# include "PoolObjectSQL.h"
2012-06-05 21:04:02 +04:00
/**
* DataStore Quotas , defined as :
* NETWORK = [
* ID = < ID of the datastore >
* LEASES = < Max . number of IPs that can be leased from net >
* LEASES_USED = Current number of IPs
* ]
*
* 0 = unlimited , default if missing
*/
2024-01-08 15:56:40 +03:00
class QuotaNetwork : public Quota
2012-06-05 21:04:02 +04:00
{
public :
2024-01-08 15:56:40 +03:00
QuotaNetwork ( bool is_default )
: Quota ( " NETWORK_QUOTA " , " NETWORK " , NET_METRICS , is_default )
{ }
2012-11-30 03:16:52 +04:00
2024-06-03 12:40:24 +03:00
virtual ~ QuotaNetwork ( ) { } ;
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
2016-02-03 12:28:54 +03:00
* the usage counters are updated . Assumes calling object is a VM
2012-06-05 21:04:02 +04:00
* @ 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 & err ) override
2016-02-03 12:28:54 +03:00
{
return check ( PoolObjectSQL : : VM , tmpl , default_quotas , err ) ;
}
2012-06-05 21:04:02 +04:00
/**
2016-02-03 12:28:54 +03:00
* Decrement usage counters when freeing a lease . This method considers
* the object type to accounto for FLOATING IP addresses or not
2012-06-05 21:04:02 +04:00
* @ param tmpl template for the resource
*/
2023-02-07 10:50:30 +03:00
void del ( Template * tmpl ) override
2016-02-03 12:28:54 +03:00
{
del ( PoolObjectSQL : : VM , tmpl ) ;
}
2012-06-05 21:04:02 +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 ,
2024-06-03 12:40:24 +03:00
Quotas & default_quotas ,
VectorAttribute * * va ) override ;
2012-11-19 18:19:09 +04:00
2024-01-08 15:56:40 +03:00
static const std : : vector < std : : string > NET_METRICS ;
2016-02-03 12:28:54 +03:00
private :
/**
* Friends are decorators for the QuotaNetwork . They can access specialized
* methods to operate over the same quota counters ( base Template class )
*/
friend class QuotaNetworkVirtualRouter ;
/**
* Check if the resource allocation will exceed the quota limits . If not
* the usage counters are updated . This method considers the object type to
* accounto for FLOATING IP addresses or not
* @ param otype object type , VM or VRouter
* @ param tmpl template for the resource
* @ param default_quotas Quotas that contain the default limits
* @ param error string
* @ return true if the operation can be performed
*/
bool check ( PoolObjectSQL : : ObjectType otype , Template * tmpl ,
2024-06-03 12:40:24 +03:00
Quotas & default_quotas , std : : string & error ) ;
2016-02-03 12:28:54 +03:00
/**
* Decrement usage counters when freeing a lease . This method considers
* the object type to accounto for FLOATING IP addresses or not
* @ param otype object type , VM or VRouter
* @ param tmpl template for the resource
*/
void del ( PoolObjectSQL : : ObjectType otype , Template * tmpl ) ;
} ;
/**
* Decorates the QuotaNetwork object to consider the FLOATING_IP attribute
* of the NIC attributes . It must be instantiated using an exisiting QuotaNetwork
* object
*/
class QuotaNetworkVirtualRouter : public QuotaDecorator
{
public :
2024-06-03 12:40:24 +03:00
QuotaNetworkVirtualRouter ( QuotaNetwork * qn ) : QuotaDecorator ( qn ) { } ;
2016-02-03 12:28:54 +03:00
2024-06-03 12:40:24 +03:00
virtual ~ QuotaNetworkVirtualRouter ( ) { } ;
2016-02-03 12:28:54 +03:00
2023-02-07 10:50:30 +03:00
bool check ( Template * tmpl , Quotas & default_quotas , std : : string & err ) override
2016-02-03 12:28:54 +03:00
{
QuotaNetwork * qn = static_cast < QuotaNetwork * > ( quota ) ;
return qn - > check ( PoolObjectSQL : : VROUTER , tmpl , default_quotas , err ) ;
}
2024-06-03 12:40:24 +03:00
void del ( Template * tmpl ) override
2016-02-03 12:28:54 +03:00
{
QuotaNetwork * qn = static_cast < QuotaNetwork * > ( quota ) ;
qn - > del ( PoolObjectSQL : : VROUTER , tmpl ) ;
}
2012-06-05 21:04:02 +04:00
} ;
# endif /*QUOTA_NETWORK_H_*/