diff --git a/include/Quota.h b/include/Quota.h index ad99b047b8..f61cfc4660 100644 --- a/include/Quota.h +++ b/include/Quota.h @@ -51,20 +51,6 @@ public: */ virtual bool check(Template* tmpl, Quotas& default_quotas, string& error) = 0; - /** - * Check if a resource update in usage counters will exceed the - * quota limits. If not the usage counters are updated for that resource - * @param tmpl with increments in MEMORY and CPU - * @param default_quotas Quotas that contain the default limits - * @param error string - * @return true if the operation can be performed - */ - virtual bool update(Template * tmpl, Quotas& default_quotas, string& error) - { - error = "Update operation for quotas not supported."; - return false; - }; - /** * Decrement usage counters when deallocating image * @param tmpl template for the resource diff --git a/include/QuotaVirtualMachine.h b/include/QuotaVirtualMachine.h index e46c47c0c3..622ea5c439 100644 --- a/include/QuotaVirtualMachine.h +++ b/include/QuotaVirtualMachine.h @@ -57,16 +57,6 @@ public: */ bool check(Template* tmpl, Quotas& default_quotas, string& error); - /** - * Check if the resource update (change in MEMORY or CPU) will exceed the - * quota limits. If not the usage counters are updated - * @param tmpl with increments in MEMORY and CPU - * @param default_quotas Quotas that contain the default limits - * @param error string - * @return true if the operation can be performed - */ - bool update(Template * tmpl, Quotas& default_quotas, string& error); - /** * Decrement usage counters when deallocating image * @param tmpl template for the resource diff --git a/include/Quotas.h b/include/Quotas.h index 02a30e36d7..9dd6c40fac 100644 --- a/include/Quotas.h +++ b/include/Quotas.h @@ -148,20 +148,6 @@ public: Quotas& default_quotas, string& error_str); - /** - * Update usage of an existing quota (e.g. size of an image), it updates - * the 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 resource can be updated, false otherwise - */ - bool quota_update(QuotaType type, - Template *tmpl, - Quotas& default_quotas, - string& error_str); - /** * Delete usage from the given quota counters. * @param type the quota to work with diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index 427b2b3ac7..055a96d5e6 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -1187,9 +1187,6 @@ void VirtualMachineResize::request_execute(xmlrpc_c::paramList const& paramList, int nvcpu, ovcpu; Nebula& nd = Nebula::instance(); - UserPool* upool = nd.get_upool(); - GroupPool* gpool = nd.get_gpool(); - Quotas dquotas = nd.get_default_user_quota(); HostPool * hpool = nd.get_hpool(); Host * host; @@ -1296,6 +1293,10 @@ void VirtualMachineResize::request_execute(xmlrpc_c::paramList const& paramList, deltas.add("MEMORY", dmemory); deltas.add("CPU", dcpu); + // This attribute tells the quotas that we are not allocating a new + // VM, just updating the CPU & MEMORY usage + deltas.add("UPDATE", "YES"); + switch (vm->get_state()) { case VirtualMachine::POWEROFF: //Only check host capacity in POWEROFF @@ -1340,69 +1341,9 @@ void VirtualMachineResize::request_execute(xmlrpc_c::paramList const& paramList, /* Check quotas */ /* ---------------------------------------------------------------------- */ - if (vm_perms.uid != UserPool::ONEADMIN_ID) + if ( quota_authorization(&deltas, Quotas::VIRTUALMACHINE, att) == false ) { - User * user = upool->get(vm_perms.uid, true); - - if ( user != 0 ) - { - rc = user->quota.quota_update(Quotas::VM, &deltas, dquotas, error_str); - - if (rc == false) - { - ostringstream oss; - - oss << object_name(PoolObjectSQL::USER) - << " [" << vm_perms.uid << "] " - << error_str; - - failure_response(AUTHORIZATION, - request_error(oss.str(), ""), - att); - - user->unlock(); - - return; - } - - upool->update(user); - - user->unlock(); - } - } - - if (vm_perms.gid != GroupPool::ONEADMIN_ID) - { - Group * group = gpool->get(vm_perms.gid, true); - - if ( group != 0 ) - { - rc = group->quota.quota_update(Quotas::VM, &deltas, dquotas, error_str); - - if (rc == false) - { - ostringstream oss; - RequestAttributes att_tmp(vm_perms.uid, -1, att); - - oss << object_name(PoolObjectSQL::GROUP) - << " [" << vm_perms.gid << "] " - << error_str; - - failure_response(AUTHORIZATION, - request_error(oss.str(), ""), - att); - - group->unlock(); - - quota_rollback(&deltas, Quotas::VM, att_tmp); - - return; - } - - gpool->update(group); - - group->unlock(); - } + return; } /* ---------------------------------------------------------------------- */ diff --git a/src/um/QuotaVirtualMachine.cc b/src/um/QuotaVirtualMachine.cc index 1df620dba7..d108416d0e 100644 --- a/src/um/QuotaVirtualMachine.cc +++ b/src/um/QuotaVirtualMachine.cc @@ -55,22 +55,32 @@ bool QuotaVirtualMachine::check(Template * tmpl, { map vm_request; - int memory; - float cpu; + int memory; + float cpu; + bool update; - if ( tmpl->get("MEMORY", memory) == false || memory <= 0 ) + // For an update (change in MEMORY or CPU), negative values are allowed, + // and VMS is not updated since a new VM is not being allocated. + + tmpl->get("UPDATE", update); + + if ( tmpl->get("MEMORY", memory) == false || (!update && memory <= 0) ) { error = "MEMORY attribute must be a positive integer value"; return false; } - if ( tmpl->get("CPU", cpu) == false || cpu <= 0 ) + if ( tmpl->get("CPU", cpu) == false || (!update && cpu <= 0) ) { error = "CPU attribute must be a positive float or integer value"; return false; } - vm_request.insert(make_pair("VMS",1)); + if ( !update ) + { + vm_request.insert(make_pair("VMS",1)); + } + vm_request.insert(make_pair("MEMORY", memory)); vm_request.insert(make_pair("CPU", cpu)); @@ -84,8 +94,11 @@ void QuotaVirtualMachine::del(Template * tmpl) { map vm_request; - int memory; - float cpu; + int memory; + float cpu; + bool update; + + tmpl->get("UPDATE", update); if ( tmpl->get("MEMORY", memory) == false ) { @@ -97,7 +110,11 @@ void QuotaVirtualMachine::del(Template * tmpl) cpu = 0; } - vm_request.insert(make_pair("VMS",1)); + if (!update) + { + vm_request.insert(make_pair("VMS",1)); + } + vm_request.insert(make_pair("MEMORY", memory)); vm_request.insert(make_pair("CPU", cpu)); @@ -114,28 +131,3 @@ int QuotaVirtualMachine::get_default_quota( { return default_quotas.vm_get(id, va); } - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - -bool QuotaVirtualMachine::update(Template * tmpl, - Quotas& default_quotas, - string& error) -{ - map vm_request; - - int delta_memory; - float delta_cpu; - - if ( tmpl->get("MEMORY", delta_memory) == true ) - { - vm_request.insert(make_pair("MEMORY", delta_memory)); - } - - if ( tmpl->get("CPU", delta_cpu) == true ) - { - vm_request.insert(make_pair("CPU", delta_cpu)); - } - - return check_quota("", vm_request, default_quotas, error); -} diff --git a/src/um/Quotas.cc b/src/um/Quotas.cc index 90bb22dbb4..dfa038b05c 100644 --- a/src/um/Quotas.cc +++ b/src/um/Quotas.cc @@ -219,31 +219,6 @@ bool Quotas::quota_check(QuotaType type, /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -bool Quotas::quota_update(QuotaType type, - Template *tmpl, - Quotas &default_quotas, - string &error_str) -{ - switch (type) - { - // This is an internal check, should never get in here. - case DATASTORE: - case NETWORK: - case IMAGE: - case VIRTUALMACHINE: - error_str = "Cannot update quota. Not implemented"; - return false; - - case VM: - return vm_quota.update(tmpl, default_quotas, error_str); - } - - return false; -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - void Quotas::quota_del(QuotaType type, int uid, int gid, Template * tmpl) { Nebula& nd = Nebula::instance();