mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-29 18:50:08 +03:00
Feagture #1611: Make the default quotas work for both user and group
This commit is contained in:
parent
c04f35d5ed
commit
8ed9fa884a
@ -318,6 +318,11 @@ public:
|
||||
return default_user_quota;
|
||||
};
|
||||
|
||||
const Quotas& get_default_group_quota()
|
||||
{
|
||||
return default_group_quota;
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
@ -19,6 +19,9 @@
|
||||
|
||||
#include "Template.h"
|
||||
|
||||
// Forward declaration to avoid include cycle
|
||||
class Quotas;
|
||||
|
||||
/**
|
||||
* Base class for resource quotas, it provides basic storage and management of
|
||||
* the quotas. Each resource MUST inherit from it to implement check and
|
||||
@ -41,10 +44,11 @@ public:
|
||||
* Check if the resource allocation will exceed the quota limits. If not
|
||||
* the usage counters are updated
|
||||
* @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
|
||||
*/
|
||||
virtual bool check(Template* tmpl, string& error) = 0;
|
||||
virtual bool check(Template* tmpl, Quotas& default_quotas, string& error) = 0;
|
||||
|
||||
/**
|
||||
* Decrement usage counters when deallocating image
|
||||
@ -118,10 +122,13 @@ protected:
|
||||
* request does not exceed quota limits
|
||||
* @param qid id that identifies the quota, to be used by get_quota
|
||||
* @param usage_req usage for each metric
|
||||
* @param default_quotas Quotas that contain the default limits
|
||||
* @param error string describing the error
|
||||
* @return true if the request does not exceed current limits
|
||||
*/
|
||||
bool check_quota(const string& qid,
|
||||
map<string, float>& usage_req,
|
||||
Quotas& default_quotas,
|
||||
string& error);
|
||||
|
||||
/**
|
||||
@ -136,11 +143,14 @@ protected:
|
||||
* Gets the default quota identified by its ID.
|
||||
*
|
||||
* @param id of the quota
|
||||
* @param default_quotas Quotas that contain the default limits
|
||||
* @param va The quota, if it is found
|
||||
*
|
||||
* @return 0 on success, -1 if not found
|
||||
*/
|
||||
virtual int get_default_quota(const string& id, VectorAttribute **va) = 0;
|
||||
virtual int get_default_quota(const string& id,
|
||||
Quotas& default_quotas,
|
||||
VectorAttribute **va) = 0;
|
||||
|
||||
/**
|
||||
* Gets a quota identified by its ID.
|
||||
|
@ -48,10 +48,11 @@ public:
|
||||
* Check if the resource allocation will exceed the quota limits. If not
|
||||
* the usage counters are updated
|
||||
* @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(Template* tmpl, string& error);
|
||||
bool check(Template* tmpl, Quotas& default_quotas, string& error);
|
||||
|
||||
/**
|
||||
* Decrement usage counters when deallocating image
|
||||
@ -65,11 +66,14 @@ protected:
|
||||
* Gets the default quota identified by its ID.
|
||||
*
|
||||
* @param id of the quota
|
||||
* @param default_quotas Quotas that contain the default limits
|
||||
* @param va The quota, if it is found
|
||||
*
|
||||
* @return 0 on success, -1 if not found
|
||||
*/
|
||||
int get_default_quota(const string& id, VectorAttribute **va);
|
||||
int get_default_quota(const string& id,
|
||||
Quotas& default_quotas,
|
||||
VectorAttribute **va);
|
||||
|
||||
static const char * DS_METRICS[];
|
||||
|
||||
|
@ -46,10 +46,11 @@ public:
|
||||
* Check if the resource allocation will exceed the quota limits. If not
|
||||
* the usage counters are updated
|
||||
* @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(Template* tmpl, string& error);
|
||||
bool check(Template* tmpl, Quotas& default_quotas, string& error);
|
||||
|
||||
/**
|
||||
* Decrement usage counters when deallocating image
|
||||
@ -63,11 +64,14 @@ protected:
|
||||
* Gets the default quota identified by its ID.
|
||||
*
|
||||
* @param id of the quota
|
||||
* @param default_quotas Quotas that contain the default limits
|
||||
* @param va The quota, if it is found
|
||||
*
|
||||
* @return 0 on success, -1 if not found
|
||||
*/
|
||||
int get_default_quota(const string& id, VectorAttribute **va);
|
||||
int get_default_quota(const string& id,
|
||||
Quotas& default_quotas,
|
||||
VectorAttribute **va);
|
||||
|
||||
static const char * IMAGE_METRICS[];
|
||||
|
||||
|
@ -46,10 +46,11 @@ public:
|
||||
* Check if the resource allocation will exceed the quota limits. If not
|
||||
* the usage counters are updated
|
||||
* @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(Template* tmpl, string& error);
|
||||
bool check(Template* tmpl, Quotas& default_quotas, string& error);
|
||||
|
||||
/**
|
||||
* Decrement usage counters when deallocating image
|
||||
@ -63,11 +64,14 @@ protected:
|
||||
* Gets the default quota identified by its ID.
|
||||
*
|
||||
* @param id of the quota
|
||||
* @param default_quotas Quotas that contain the default limits
|
||||
* @param va The quota, if it is found
|
||||
*
|
||||
* @return 0 on success, -1 if not found
|
||||
*/
|
||||
int get_default_quota(const string& id, VectorAttribute **va);
|
||||
int get_default_quota(const string& id,
|
||||
Quotas& default_quotas,
|
||||
VectorAttribute **va);
|
||||
|
||||
static const char * NET_METRICS[];
|
||||
|
||||
|
@ -49,10 +49,11 @@ public:
|
||||
* Check if the resource allocation will exceed the quota limits. If not
|
||||
* the usage counters are updated
|
||||
* @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(Template* tmpl, string& error);
|
||||
bool check(Template* tmpl, Quotas& default_quotas, string& error);
|
||||
|
||||
/**
|
||||
* Decrement usage counters when deallocating image
|
||||
@ -94,11 +95,12 @@ protected:
|
||||
* Gets the default quota identified by its ID.
|
||||
*
|
||||
* @param id of the quota
|
||||
* @param default_quotas Quotas that contain the default limits
|
||||
* @param va The quota, if it is found
|
||||
*
|
||||
* @return 0 on success, -1 if not found
|
||||
*/
|
||||
int get_default_quota(const string& id, VectorAttribute **va);
|
||||
int get_default_quota(const string& id, Quotas& default_quotas, VectorAttribute **va);
|
||||
|
||||
static const char * VM_METRICS[];
|
||||
|
||||
|
@ -59,18 +59,6 @@ public:
|
||||
*/
|
||||
int set(Template *tmpl, string& error);
|
||||
|
||||
/**
|
||||
* Check Datastore quotas, it updates usage counters if quotas are not
|
||||
* exceeded.
|
||||
* @param tmpl template for the image
|
||||
* @param reason string describing the error
|
||||
* @return true if image can be allocated, false otherwise
|
||||
*/
|
||||
bool ds_check(Template * tmpl, string& reason)
|
||||
{
|
||||
return datastore_quota.check(tmpl, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete usage from quota counters.
|
||||
* @param tmpl template for the image, with usage
|
||||
@ -93,18 +81,6 @@ public:
|
||||
return datastore_quota.get_quota(id, va);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Virtual Machine quotas (network, image and compute), it updates
|
||||
* usage counters if quotas are not exceeded.
|
||||
* @param tmpl template for the VirtualMachine
|
||||
* @param error_str string describing the error
|
||||
* @return true if VM can be allocated, false otherwise
|
||||
*/
|
||||
bool vm_check(Template * tmpl, string& error_str)
|
||||
{
|
||||
return quota_check(VIRTUALMACHINE, tmpl, error_str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete VM related usage (network, image and compute) from quota counters.
|
||||
* @param tmpl template for the image, with usage
|
||||
@ -159,10 +135,14 @@ public:
|
||||
* Check quota, it updates usage counters if quotas are not exceeded.
|
||||
* @param type the quota to work with
|
||||
* @param tmpl template for the VirtualMachine
|
||||
* @param default_quotas Quotas that contain the default limits
|
||||
* @param error_str string describing the error
|
||||
* @return true if VM can be allocated, false otherwise
|
||||
*/
|
||||
bool quota_check(QuotaType type, Template *tmpl, string& error_str);
|
||||
bool quota_check(QuotaType type,
|
||||
Template *tmpl,
|
||||
Quotas& default_quotas,
|
||||
string& error_str);
|
||||
|
||||
/**
|
||||
* Delete usage from the given quota counters.
|
||||
|
@ -278,7 +278,9 @@ bool Request::user_quota_authorization (Template * tmpl,
|
||||
return false;
|
||||
}
|
||||
|
||||
rc = user->quota.quota_check(qtype, tmpl, error_str);
|
||||
Quotas default_user_quotas = nd.get_default_user_quota();
|
||||
|
||||
rc = user->quota.quota_check(qtype, tmpl, default_user_quotas, error_str);
|
||||
|
||||
if (rc == true)
|
||||
{
|
||||
@ -320,7 +322,9 @@ bool Request::group_quota_authorization (Template * tmpl,
|
||||
return false;
|
||||
}
|
||||
|
||||
rc = group->quota.quota_check(qtype, tmpl, error_str);
|
||||
Quotas default_group_quotas = nd.get_default_group_quota();
|
||||
|
||||
rc = group->quota.quota_check(qtype, tmpl, default_group_quotas, error_str);
|
||||
|
||||
if (rc == true)
|
||||
{
|
||||
|
@ -152,6 +152,7 @@ error_limits:
|
||||
|
||||
bool Quota::check_quota(const string& qid,
|
||||
map<string, float>& usage_req,
|
||||
Quotas& default_quotas,
|
||||
string& error)
|
||||
{
|
||||
VectorAttribute * q;
|
||||
@ -172,7 +173,7 @@ bool Quota::check_quota(const string& qid,
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( get_default_quota(qid, &default_q) == -1 )
|
||||
if ( get_default_quota(qid, default_quotas, &default_q) == -1 )
|
||||
{
|
||||
default_q = 0;
|
||||
}
|
||||
|
@ -16,7 +16,6 @@
|
||||
|
||||
#include "QuotaDatastore.h"
|
||||
#include "Quotas.h"
|
||||
#include "Nebula.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -28,7 +27,7 @@ const int QuotaDatastore::NUM_DS_METRICS = 2;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
bool QuotaDatastore::check(Template * tmpl, string& error)
|
||||
bool QuotaDatastore::check(Template * tmpl, Quotas& default_quotas, string& error)
|
||||
{
|
||||
map<string, float> ds_request;
|
||||
|
||||
@ -51,8 +50,8 @@ bool QuotaDatastore::check(Template * tmpl, string& error)
|
||||
|
||||
ds_request.insert(make_pair("IMAGES",1));
|
||||
ds_request.insert(make_pair("SIZE", size));
|
||||
|
||||
return check_quota(ds_id, ds_request, error);
|
||||
|
||||
return check_quota(ds_id, ds_request, default_quotas, error);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -86,10 +85,11 @@ void QuotaDatastore::del(Template * tmpl)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int QuotaDatastore::get_default_quota(const string& id, VectorAttribute **va)
|
||||
int QuotaDatastore::get_default_quota(
|
||||
const string& id,
|
||||
Quotas& default_quotas,
|
||||
VectorAttribute **va)
|
||||
{
|
||||
// TODO: We need to know if this is a user or group quota
|
||||
Quotas default_quotas = Nebula::instance().get_default_user_quota();
|
||||
return default_quotas.ds_get(id, va);
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,6 @@
|
||||
|
||||
#include "QuotaImage.h"
|
||||
#include "Quotas.h"
|
||||
#include "Nebula.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -28,7 +27,7 @@ const int QuotaImage::NUM_IMAGE_METRICS = 1;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
bool QuotaImage::check(Template * tmpl, string& error)
|
||||
bool QuotaImage::check(Template * tmpl, Quotas& default_quotas, string& error)
|
||||
{
|
||||
vector<Attribute*> disks;
|
||||
VectorAttribute * disk;
|
||||
@ -55,7 +54,7 @@ bool QuotaImage::check(Template * tmpl, string& error)
|
||||
|
||||
if ( !image_id.empty() )
|
||||
{
|
||||
if ( !check_quota(image_id, image_request, error) )
|
||||
if ( !check_quota(image_id, image_request, default_quotas, error) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -101,10 +100,8 @@ void QuotaImage::del(Template * tmpl)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int QuotaImage::get_default_quota(const string& id, VectorAttribute **va)
|
||||
int QuotaImage::get_default_quota(const string& id, Quotas& default_quotas, VectorAttribute **va)
|
||||
{
|
||||
// TODO: We need to know if this is a user or group quota
|
||||
Quotas default_quotas = Nebula::instance().get_default_user_quota();
|
||||
return default_quotas.image_get(id, va);
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,6 @@
|
||||
|
||||
#include "QuotaNetwork.h"
|
||||
#include "Quotas.h"
|
||||
#include "Nebula.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -28,7 +27,7 @@ const int QuotaNetwork::NUM_NET_METRICS = 1;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
bool QuotaNetwork::check(Template * tmpl, string& error)
|
||||
bool QuotaNetwork::check(Template * tmpl, Quotas& default_quotas, string& error)
|
||||
{
|
||||
vector<Attribute*> nics;
|
||||
VectorAttribute * nic;
|
||||
@ -55,7 +54,7 @@ bool QuotaNetwork::check(Template * tmpl, string& error)
|
||||
|
||||
if ( !net_id.empty() )
|
||||
{
|
||||
if ( !check_quota(net_id, net_request, error) )
|
||||
if ( !check_quota(net_id, net_request, default_quotas, error) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -101,10 +100,11 @@ void QuotaNetwork::del(Template * tmpl)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int QuotaNetwork::get_default_quota(const string& id, VectorAttribute **va)
|
||||
int QuotaNetwork::get_default_quota(
|
||||
const string& id,
|
||||
Quotas& default_quotas,
|
||||
VectorAttribute **va)
|
||||
{
|
||||
// TODO: We need to know if this is a user or group quota
|
||||
Quotas default_quotas = Nebula::instance().get_default_user_quota();
|
||||
return default_quotas.network_get(id, va);
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,6 @@
|
||||
|
||||
#include "QuotaVirtualMachine.h"
|
||||
#include "Quotas.h"
|
||||
#include "Nebula.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -50,7 +49,9 @@ int QuotaVirtualMachine::get_quota(const string& id, VectorAttribute **va)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
bool QuotaVirtualMachine::check(Template * tmpl, string& error)
|
||||
bool QuotaVirtualMachine::check(Template * tmpl,
|
||||
Quotas& default_quotas,
|
||||
string& error)
|
||||
{
|
||||
map<string, float> vm_request;
|
||||
|
||||
@ -73,7 +74,7 @@ bool QuotaVirtualMachine::check(Template * tmpl, string& error)
|
||||
vm_request.insert(make_pair("MEMORY", memory));
|
||||
vm_request.insert(make_pair("CPU", cpu));
|
||||
|
||||
return check_quota("", vm_request, error);
|
||||
return check_quota("", vm_request, default_quotas, error);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -106,10 +107,8 @@ void QuotaVirtualMachine::del(Template * tmpl)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int QuotaVirtualMachine::get_default_quota(const string& id, VectorAttribute **va)
|
||||
int QuotaVirtualMachine::get_default_quota(const string& id, Quotas& default_quotas, VectorAttribute **va)
|
||||
{
|
||||
// TODO: We need to know if this is a user or group quota
|
||||
Quotas default_quotas = Nebula::instance().get_default_user_quota();
|
||||
return default_quotas.vm_get(id, va);
|
||||
}
|
||||
|
||||
|
@ -173,35 +173,38 @@ void Quotas::quota_del(QuotaType type, Template *tmpl)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
bool Quotas::quota_check(QuotaType type, Template *tmpl, string& error_str)
|
||||
bool Quotas::quota_check(QuotaType type,
|
||||
Template *tmpl,
|
||||
Quotas &default_quotas,
|
||||
string &error_str)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case DATASTORE:
|
||||
return datastore_quota.check(tmpl, error_str);
|
||||
return datastore_quota.check(tmpl, default_quotas, error_str);
|
||||
|
||||
case NETWORK:
|
||||
return network_quota.check(tmpl, error_str);
|
||||
return network_quota.check(tmpl, default_quotas, error_str);
|
||||
|
||||
case IMAGE:
|
||||
return image_quota.check(tmpl, error_str);
|
||||
return image_quota.check(tmpl, default_quotas, error_str);
|
||||
|
||||
case VM:
|
||||
return vm_quota.check(tmpl, error_str);
|
||||
return vm_quota.check(tmpl, default_quotas, error_str);
|
||||
|
||||
case VIRTUALMACHINE:
|
||||
if ( network_quota.check(tmpl, error_str) == false )
|
||||
if ( network_quota.check(tmpl, default_quotas, error_str) == false )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( vm_quota.check(tmpl, error_str) == false )
|
||||
if ( vm_quota.check(tmpl, default_quotas, error_str) == false )
|
||||
{
|
||||
network_quota.del(tmpl);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( image_quota.check(tmpl, error_str) == false )
|
||||
if ( image_quota.check(tmpl, default_quotas, error_str) == false )
|
||||
{
|
||||
network_quota.del(tmpl);
|
||||
vm_quota.del(tmpl);
|
||||
|
Loading…
x
Reference in New Issue
Block a user