Feagture #1611: Make the default quotas work for both user and group

This commit is contained in:
Carlos Martín committed 2012-11-19 16:38:39 +01:00
1 parent c04f35d5ed
commit 8ed9fa884a
14 files changed
+84 -71

No files matched your search

+6 -2
View File
@@ -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)
{
+2 -1
View File
@@ -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;
}
+7 -7
View File
@@ -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);
}
+3 -6
View File
@@ -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);
}
+6 -6
View File
@@ -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);
}
+5 -6
View File
@@ -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);
}
+11 -8
View File
@@ -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);