diff --git a/include/Nebula.h b/include/Nebula.h index 7bd3ac2557..d1f5560a87 100644 --- a/include/Nebula.h +++ b/include/Nebula.h @@ -318,6 +318,11 @@ public: return default_user_quota; }; + const Quotas& get_default_group_quota() + { + return default_group_quota; + }; + private: // ----------------------------------------------------------------------- diff --git a/include/Quota.h b/include/Quota.h index 2d7aed1112..bc22e911dc 100644 --- a/include/Quota.h +++ b/include/Quota.h @@ -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& 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. diff --git a/include/QuotaDatastore.h b/include/QuotaDatastore.h index e70925479c..fcd5a7f7ab 100644 --- a/include/QuotaDatastore.h +++ b/include/QuotaDatastore.h @@ -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[]; diff --git a/include/QuotaImage.h b/include/QuotaImage.h index cab4a93ed8..39b87ce6ac 100644 --- a/include/QuotaImage.h +++ b/include/QuotaImage.h @@ -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[]; diff --git a/include/QuotaNetwork.h b/include/QuotaNetwork.h index 082b908aeb..afa92e5874 100644 --- a/include/QuotaNetwork.h +++ b/include/QuotaNetwork.h @@ -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[]; diff --git a/include/QuotaVirtualMachine.h b/include/QuotaVirtualMachine.h index a1368c6673..fa085c0421 100644 --- a/include/QuotaVirtualMachine.h +++ b/include/QuotaVirtualMachine.h @@ -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[]; diff --git a/include/Quotas.h b/include/Quotas.h index 16cd6032b2..1097ea9306 100644 --- a/include/Quotas.h +++ b/include/Quotas.h @@ -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. diff --git a/src/rm/Request.cc b/src/rm/Request.cc index 5600c497b6..21c3624c65 100644 --- a/src/rm/Request.cc +++ b/src/rm/Request.cc @@ -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) { diff --git a/src/um/Quota.cc b/src/um/Quota.cc index c821521078..326bd5c47e 100644 --- a/src/um/Quota.cc +++ b/src/um/Quota.cc @@ -152,6 +152,7 @@ error_limits: bool Quota::check_quota(const string& qid, map& 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; } diff --git a/src/um/QuotaDatastore.cc b/src/um/QuotaDatastore.cc index fa2f131656..feabd98c00 100644 --- a/src/um/QuotaDatastore.cc +++ b/src/um/QuotaDatastore.cc @@ -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 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); } diff --git a/src/um/QuotaImage.cc b/src/um/QuotaImage.cc index ee78395027..0b6774524f 100644 --- a/src/um/QuotaImage.cc +++ b/src/um/QuotaImage.cc @@ -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 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); } diff --git a/src/um/QuotaNetwork.cc b/src/um/QuotaNetwork.cc index d560d062b8..97dd50b1b1 100644 --- a/src/um/QuotaNetwork.cc +++ b/src/um/QuotaNetwork.cc @@ -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 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); } diff --git a/src/um/QuotaVirtualMachine.cc b/src/um/QuotaVirtualMachine.cc index 4a8ccd8875..14c0335aee 100644 --- a/src/um/QuotaVirtualMachine.cc +++ b/src/um/QuotaVirtualMachine.cc @@ -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 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); } diff --git a/src/um/Quotas.cc b/src/um/Quotas.cc index b1a2b817c4..baa46e0bf2 100644 --- a/src/um/Quotas.cc +++ b/src/um/Quotas.cc @@ -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);