diff options
| author | Eoghan Glynn <eglynn@redhat.com> | 2012-08-16 16:11:03 +0100 |
|---|---|---|
| committer | Vishvananda Ishaya <vishvananda@gmail.com> | 2012-08-16 22:51:02 -0700 |
| commit | 1cf475d7a135c1078cf7df11c261618af501dc37 (patch) | |
| tree | 2edca13cb18fd30557f745db9cf5ace886b1e82c /nova/api | |
| parent | 06d1f0dfd5d22ace96b414fd0b71fbaa668b95ce (diff) | |
Revert per-user-quotas
See bug 1034384, bug 1037590.
This reverts commit https://github.com/openstack/nova/commit/391f345d,
but leaves the DB migration in place while adding a further
migration to reverse it.
The motivation for reversion is that the per-user quota logic would
totally undermine the per-project quotas set for a pre-existing
openstack install.
The per-user quota logic could be re-introduced in a fixed state
after Folsom-3.
Change-Id: Idd4b55a2404a25f43f6737b661f828c28501066f
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/compute/contrib/quotas.py | 78 | ||||
| -rw-r--r-- | nova/api/openstack/compute/limits.py | 15 |
2 files changed, 14 insertions, 79 deletions
diff --git a/nova/api/openstack/compute/contrib/quotas.py b/nova/api/openstack/compute/contrib/quotas.py index 56583ff79..33584badc 100644 --- a/nova/api/openstack/compute/contrib/quotas.py +++ b/nova/api/openstack/compute/contrib/quotas.py @@ -15,7 +15,6 @@ # License for the specific language governing permissions and limitations # under the License. -import urlparse import webob from nova.api.openstack import extensions @@ -25,15 +24,13 @@ from nova import db from nova.db.sqlalchemy import api as sqlalchemy_api from nova import exception from nova import quota -from nova import utils QUOTAS = quota.QUOTAS -def authorize_action(context, action_name): - action = 'quotas:%s' % action_name - extensions.extension_authorizer('compute', action)(context) +authorize_update = extensions.extension_authorizer('compute', 'quotas:update') +authorize_show = extensions.extension_authorizer('compute', 'quotas:show') class QuotaTemplate(xmlutil.TemplateBuilder): @@ -60,102 +57,51 @@ class QuotaSetsController(object): return dict(quota_set=result) - def _validate_quota_limit(self, limit, remain, quota): + def _validate_quota_limit(self, limit): # NOTE: -1 is a flag value for unlimited if limit < -1: msg = _("Quota limit must be -1 or greater.") raise webob.exc.HTTPBadRequest(explanation=msg) - # Quota limit must be less than the remains of the project. - if remain != -1 and remain < limit - quota: - msg = _("Quota limit exceed the remains of the project.") - raise webob.exc.HTTPBadRequest(explanation=msg) - - def _get_quotas(self, context, id, user_id=None, remaining=False, - usages=False): - # Get the remaining quotas for a project. - if remaining: - values = QUOTAS.get_remaining_quotas(context, id) - return values - - if user_id: - # If user_id, return quotas for the given user. - values = QUOTAS.get_user_quotas(context, user_id, id, - usages=usages) - else: - values = QUOTAS.get_project_quotas(context, id, usages=usages) + def _get_quotas(self, context, id, usages=False): + values = QUOTAS.get_project_quotas(context, id, usages=usages) if usages: return values else: return dict((k, v['limit']) for k, v in values.items()) - def _request_params(self, req): - qs = req.environ.get('QUERY_STRING', '') - return urlparse.parse_qs(qs) - @wsgi.serializers(xml=QuotaTemplate) def show(self, req, id): context = req.environ['nova.context'] - authorize_action(context, 'show') - params = self._request_params(req) - remaining = False - if 'remaining' in params: - remaining = utils.bool_from_str(params["remaining"][0]) - user_id = None - if 'user_id' in params: - user_id = params["user_id"][0] + authorize_show(context) try: sqlalchemy_api.authorize_project_context(context, id) - return self._format_quota_set(id, - self._get_quotas(context, id, user_id, remaining)) + return self._format_quota_set(id, self._get_quotas(context, id)) except exception.NotAuthorized: raise webob.exc.HTTPForbidden() @wsgi.serializers(xml=QuotaTemplate) def update(self, req, id, body): context = req.environ['nova.context'] - params = self._request_params(req) + authorize_update(context) project_id = id - user_id = None - remains = {} - quotas = {} - if 'user_id' in params: - # Project admins are able to modify per-user quotas. - authorize_action(context, 'update_for_user') - user_id = params["user_id"][0] - remains = self._get_quotas(context, project_id, remaining=True) - quotas = db.quota_get_all_by_user(context, user_id, project_id) - else: - # Only admins are able to modify per-project quotas. - authorize_action(context, 'update_for_project') - for key in body['quota_set'].keys(): if key in QUOTAS: value = int(body['quota_set'][key]) + self._validate_quota_limit(value) try: - if user_id: - self._validate_quota_limit(value, remains.get(key, 0), - quotas.get(key, 0)) - db.quota_update_for_user(context, user_id, - project_id, key, value) - else: - self._validate_quota_limit(value, remains.get(key, -1), - quotas.get(key, 0)) - db.quota_update(context, project_id, key, value) + db.quota_update(context, project_id, key, value) except exception.ProjectQuotaNotFound: db.quota_create(context, project_id, key, value) - except exception.UserQuotaNotFound: - db.quota_create_for_user(context, user_id, - project_id, key, value) except exception.AdminRequired: raise webob.exc.HTTPForbidden() - return {'quota_set': self._get_quotas(context, id, user_id)} + return {'quota_set': self._get_quotas(context, id)} @wsgi.serializers(xml=QuotaTemplate) def defaults(self, req, id): context = req.environ['nova.context'] - authorize_action(context, 'show') + authorize_show(context) return self._format_quota_set(id, QUOTAS.get_defaults(context)) diff --git a/nova/api/openstack/compute/limits.py b/nova/api/openstack/compute/limits.py index 990c08a10..c0ef65670 100644 --- a/nova/api/openstack/compute/limits.py +++ b/nova/api/openstack/compute/limits.py @@ -23,7 +23,6 @@ import httplib import math import re import time -import urlparse import webob.dec import webob.exc @@ -86,18 +85,8 @@ class LimitsController(object): Return all global and rate limit information. """ context = req.environ['nova.context'] - qs = req.environ.get('QUERY_STRING', '') - params = urlparse.parse_qs(qs) - if 'user_id' in params: - user_id = params["user_id"][0] - quotas = QUOTAS.get_user_quotas(context, user_id, - context.project_id, - usages=False) - else: - quotas = QUOTAS.get_project_quotas(context, - context.project_id, - usages=False) - + quotas = QUOTAS.get_project_quotas(context, context.project_id, + usages=False) abs_limits = dict((k, v['limit']) for k, v in quotas.items()) rate_limits = req.environ.get("nova.limits", []) |
