Exemplo n.º 1
0
    def get_quota(self, context, project_id, action=None):
        """Get quota for a specified tenant.

        :param context: context object.

        :param project_id: It's UUID of the project.
            Note: In v1.0 it can be defaults sometimes.
            Only specified tenant quota is retrieved from database
            using this param.

        :param action: Optional. If provided, it can be 'detail'
            action - Gets details quota for the specified tenant.
        """
        result = collections.defaultdict(dict)
        if project_id == 'defaults' or action == 'defaults':
            # Get default quota limits from conf file
            result = self.get_defaults(context, CONF.kingbird_global_limit)
        else:
            if action and action != 'detail':
                pecan.abort(404, _('Invalid request URL'))
            elif action == 'detail':
                # Get the current quota usages for a project
                result = self.rpc_client.get_total_usage_for_tenant(
                    context, project_id)
            else:
                # Get quota limits for all the resources for a project
                result = db_api.quota_get_all_by_project(context, project_id)
        return result
Exemplo n.º 2
0
 def get(self, project_id, action=None):
     quota = collections.defaultdict(dict)
     context = restcomm.extract_context_from_environ()
     result = collections.defaultdict(dict)
     try:
         if project_id == 'defaults':
             # Get default quota limits from conf file
             result = self._get_defaults(context,
                                         CONF.kingbird_global_limit)
         else:
             if action and action != 'detail':
                 pecan.abort(404, _('Invalid request URL'))
             elif action == 'detail':
                 # Get the current quota usages for a project
                 result = self.rpc_client.get_total_usage_for_tenant(
                     context, project_id)
             else:
                 # Get quota limits for all the resources for a project
                 result = db_api.quota_get_all_by_project(
                     context, project_id)
         quota['quota_set'] = result
         return quota
     # Could be raised by get total usage call
     except exceptions.InternalError:
         pecan.abort(400, _('Error while requesting usage'))
Exemplo n.º 3
0
    def test_quota_get_by_project(self):
        project_id = UUID2
        resource = "cores"

        limit = self.create_quota_limit(self.ctx, project_id=project_id, resource=resource, limit=15)
        self.assertIsNotNone(limit)

        by_project = db_api.quota_get_all_by_project(self.ctx, project_id)
        self.assertIsNotNone(by_project)
        self.assertEqual(project_id, by_project["project_id"])
Exemplo n.º 4
0
    def test_quota_get_by_project(self):
        project_id = UUID2
        resource = 'cores'

        limit = self.create_quota_limit(self.ctx,
                                        project_id=project_id,
                                        resource=resource,
                                        limit=15)
        self.assertIsNotNone(limit)

        by_project = db_api.quota_get_all_by_project(self.ctx, project_id)
        self.assertIsNotNone(by_project)
        self.assertEqual(project_id, by_project['project_id'])
Exemplo n.º 5
0
 def test_quota_get_by_non_existing_project(self):
     project_id = UUID2
     expected_quota_set = {'project_id': project_id}
     project_limit = db_api.quota_get_all_by_project(self.ctx, project_id)
     self.assertEqual(project_limit, expected_quota_set)
Exemplo n.º 6
0
 def test_quota_get_by_non_existing_project(self):
     project_id = UUID2
     expected_quota_set = {"project_id": project_id}
     project_limit = db_api.quota_get_all_by_project(self.ctx, project_id)
     self.assertEqual(project_limit, expected_quota_set)