def get_user_quotas(self, context, resources, user_id, project_id, quota_class=None, defaults=True, usages=True): """ Given a list of resources, retrieve the quotas for the given user. :param context: The request context, for access checks. :param resources: A dictionary of the registered resources. :param project_id: The ID of the project to return quotas for. :param user_id: The ID of the user to return quotas for. :param quota_class: If project_id != context.project_id, the quota class cannot be determined. This parameter allows it to be specified. It will be ignored if project_id == context.project_id. :param defaults: If True, the quota class value (or the default value, if there is no value from the quota class) will be reported if there is no specific value for the resource. :param usages: If True, the current in_use and reserved counts will also be returned. """ user_quotas = db.quota_get_all_by_user(context, user_id, project_id) user_usages = None if usages: user_usages = db.quota_usage_get_all_by_user( context, user_id, project_id) return self._process_quotas(context, resources, project_id, user_quotas, quota_class=quota_class, defaults=defaults, usages=user_usages)
def update(self, req, id, body): context = req.environ['nova.context'] params = self._request_params(req) 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]) 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) 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)}
def get_user_quotas(self, context, resources, user_id, project_id, quota_class=None, defaults=True, usages=True): """ Given a list of resources, retrieve the quotas for the given user. :param context: The request context, for access checks. :param resources: A dictionary of the registered resources. :param project_id: The ID of the project to return quotas for. :param user_id: The ID of the user to return quotas for. :param quota_class: If project_id != context.project_id, the quota class cannot be determined. This parameter allows it to be specified. It will be ignored if project_id == context.project_id. :param defaults: If True, the quota class value (or the default value, if there is no value from the quota class) will be reported if there is no specific value for the resource. :param usages: If True, the current in_use and reserved counts will also be returned. """ user_quotas = db.quota_get_all_by_user(context, user_id, project_id) user_usages = None if usages: user_usages = db.quota_usage_get_all_by_user(context, user_id, project_id) return self._process_quotas(context, resources, project_id, user_quotas, quota_class=quota_class, defaults=defaults, usages=user_usages)