Example #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
Example #2
0
File: quota.py Project: bhuvan/nova
    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)
Example #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
Example #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
Example #5
0
File: quota.py Project: xtoddx/nova
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
Example #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
Example #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
Example #8
0
File: quota.py Project: nimbis/nova
    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
Example #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
Example #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)
Example #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