Exemple #1
0
 def get_all_by_project(cls, context, project_id):
     api_db_quotas_dict = cls._get_all_from_db_by_project(context,
                                                          project_id)
     main_db_quotas_dict = db.quota_get_all_by_project(context, project_id)
     for k, v in api_db_quotas_dict.items():
         main_db_quotas_dict[k] = v
     return main_db_quotas_dict
Exemple #2
0
    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.
        """

        project_quotas = db.quota_get_all_by_project(context, project_id)

        project_usages = None
        if usages:
            project_usages = db.quota_usage_get_all_by_project(context,
                                                               project_id)

        return self._process_quotas(context, resources,
                                    project_id, project_quotas,
                                    quota_class=quota_class,
                                    defaults=defaults,
                                    usages=project_usages)
Exemple #3
0
def get_project_quotas(context, project_id):
    rval = _get_default_quotas()
    quota = db.quota_get_all_by_project(context, project_id)
    for key in rval.keys():
        if key in quota:
            rval[key] = quota[key]
    return rval
Exemple #4
0
 def get_all_by_project(cls, context, project_id):
     api_db_quotas_dict = cls._get_all_from_db_by_project(
         context, project_id)
     main_db_quotas_dict = db.quota_get_all_by_project(context, project_id)
     for k, v in api_db_quotas_dict.items():
         main_db_quotas_dict[k] = v
     return main_db_quotas_dict
Exemple #5
0
def get_project_quotas(context, project_id):
    rval = _get_default_quotas()
    quota = db.quota_get_all_by_project(context, project_id)
    for key in rval.keys():
        if key in quota:
            rval[key] = quota[key]
    return rval
Exemple #6
0
def get_project_quotas(context, project_id):
    defaults = _get_default_quotas()
    if context.quota_class:
        get_class_quotas(context, context.quota_class, defaults)
    quota = db.quota_get_all_by_project(context, project_id)
    for key in defaults.keys():
        if key in quota:
            defaults[key] = quota[key]
    return defaults
Exemple #7
0
def get_project_quotas(context, project_id):
    defaults = _get_default_quotas()
    if context.quota_class:
        get_class_quotas(context, context.quota_class, defaults)
    quota = db.quota_get_all_by_project(context, project_id)
    for key in defaults.keys():
        if key in quota:
            defaults[key] = quota[key]
    return defaults
Exemple #8
0
    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
Exemple #9
0
def get_quota(context, project_id):
    rval = {'instances': FLAGS.quota_instances,
            'cores': FLAGS.quota_cores,
            'volumes': FLAGS.quota_volumes,
            'gigabytes': FLAGS.quota_gigabytes,
            'floating_ips': FLAGS.quota_floating_ips,
            'metadata_items': FLAGS.quota_metadata_items}

    quota = db.quota_get_all_by_project(context, project_id)
    for key in rval.keys():
        if key in quota:
            rval[key] = quota[key]
    return rval
Exemple #10
0
    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.
        """

        project_quotas = db.quota_get_all_by_project(context, project_id)

        project_usages = None
        if usages:
            project_usages = db.quota_usage_get_all_by_project(
                context, project_id)

        return self._process_quotas(context,
                                    resources,
                                    project_id,
                                    project_quotas,
                                    quota_class=quota_class,
                                    defaults=defaults,
                                    usages=project_usages)
Exemple #11
0
    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