def get_all_class_by_name(cls, context, class_name): api_db_quotas_dict = cls._get_all_class_from_db_by_name(context, class_name) main_db_quotas_dict = db.quota_class_get_all_by_name(context, class_name) for k, v in api_db_quotas_dict.items(): main_db_quotas_dict[k] = v return main_db_quotas_dict
def _process_quotas(self, context, resources, project_id, quotas, quota_class=None, defaults=True, usages=None): """ Given a list of resources, process the quotas for the given quotas and usages. :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 quotas: The quotas dictionary need to be processed. :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 not None, the current in_use and reserved counts will also be returned. """ modified_quotas = {} # Get the quotas for the appropriate class. If the project ID # matches the one in the context, we use the quota_class from # the context, otherwise, we use the provided quota_class (if # any) if project_id == context.project_id: quota_class = context.quota_class if quota_class: class_quotas = db.quota_class_get_all_by_name(context, quota_class) else: class_quotas = {} for resource in resources.values(): # Omit default/quota class values if not defaults and resource.name not in quotas: continue modified_quotas[resource.name] = dict( limit=quotas.get(resource.name, class_quotas.get( resource.name, resource.default)), ) # Include usages if desired. This is optional because one # internal consumer of this interface wants to access the # usages directly from inside a transaction. if usages: usage = usages.get(resource.name, {}) modified_quotas[resource.name].update( in_use=usage.get('in_use', 0), reserved=usage.get('reserved', 0), ) return modified_quotas
def get_class_quotas(context, quota_class, defaults=None): """Update defaults with the quota class values.""" if not defaults: defaults = _get_default_quotas() quota = db.quota_class_get_all_by_name(context, quota_class) for key in defaults.keys(): if key in quota: defaults[key] = quota[key] return defaults
def get_class_quotas(self, context, resources, quota_class, defaults=True): """ Given a list of resources, retrieve the quotas for the given quota class. :param context: The request context, for access checks. :param resources: A dictionary of the registered resources. :param quota_class: The name of the quota class to return quotas for. :param defaults: If True, the default value will be reported if there is no specific value for the resource. """ quotas = {} class_quotas = db.quota_class_get_all_by_name(context, quota_class) for resource in resources.values(): if defaults or resource.name in class_quotas: quotas[resource.name] = class_quotas.get(resource.name, resource.default) return quotas
def get_class_quotas(self, context, resources, quota_class, defaults=True): """ Given a list of resources, retrieve the quotas for the given quota class. :param context: The request context, for access checks. :param resources: A dictionary of the registered resources. :param quota_class: The name of the quota class to return quotas for. :param defaults: If True, the default value will be reported if there is no specific value for the resource. """ quotas = {} class_quotas = db.quota_class_get_all_by_name(context, quota_class) for resource in resources.values(): if defaults or resource.name in class_quotas: quotas[resource.name] = class_quotas.get( resource.name, resource.default) return quotas
def get_project_quotas(self, context, resources, project_id, quota_class=None, defaults=True, usages=True): """ Given a list of resources, retrieve the quotas for the given project. :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 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. """ quotas = {} project_quotas = db.quota_get_all_by_project(context, project_id) if usages: project_usages = db.quota_usage_get_all_by_project( context, project_id) # Get the quotas for the appropriate class. If the project ID # matches the one in the context, we use the quota_class from # the context, otherwise, we use the provided quota_class (if # any) if project_id == context.project_id: quota_class = context.quota_class if quota_class: class_quotas = db.quota_class_get_all_by_name(context, quota_class) else: class_quotas = {} for resource in resources.values(): # Omit default/quota class values if not defaults and resource.name not in project_quotas: continue quotas[resource.name] = dict(limit=project_quotas.get( resource.name, class_quotas.get(resource.name, resource.default)), ) # Include usages if desired. This is optional because one # internal consumer of this interface wants to access the # usages directly from inside a transaction. if usages: usage = project_usages.get(resource.name, {}) quotas[resource.name].update( in_use=usage.get('in_use', 0), reserved=usage.get('reserved', 0), ) return quotas
def get_quotas(self, context, resources, quota_class=None, defaults=True, usages=True): """ Given a list of resources, retrieve the quotas of all projects. :param context: The request context, for access checks. :param resources: A dictionary of the registered resources. :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. """ quotas = {} all_quotas = db.quota_get_all(context) all_usages = {} if usages: all_usages = db.quota_usage_get_all(context) # Get the quotas for the appropriate class. If the project ID # matches the one in the context, we use the quota_class from # the context, otherwise, we use the provided quota_class (if # any) if quota_class: class_quotas = db.quota_class_get_all_by_name(context, quota_class) else: class_quotas = {} if len(all_usages) == 0: projects = all_quotas else: projects = all_usages for project in projects: project_quotas = all_quotas.get(project, {}) result_project_quotas = quotas.get(project, {}) for resource in resources.values(): # Omit default/quota class values if not defaults and resource.name not in project_quotas: continue result_project_quotas[resource.name] = dict( limit=project_quotas.get(resource.name, class_quotas.get( resource.name, resource.default)), ) project_usages = all_usages.get(project, {}) # Include usages if desired. This is optional because one # internal consumer of this interface wants to access the # usages directly from inside a transaction. if usages: usage = project_usages.get(resource.name, {}) result_project_quotas[resource.name].update( in_use=usage.get('in_use', 0), reserved=usage.get('reserved', 0), ) quotas.update({project: result_project_quotas}) return quotas