Beispiel #1
0
    def get_one(self, project_id, resource):
        """Retrieve Quota information for the given project_id.

        :param id: project id.
        :param resource: resource name.
        """
        context = pecan.request.context
        policy.enforce(context, 'quota:get', action='quota:get')

        if not context.is_admin and project_id != context.project_id:
            raise exception.NotAuthorized()

        quota = objects.Quota.get_quota_by_project_id_resource(
            context, project_id, resource)
        return Quota.convert(quota)
Beispiel #2
0
    def get_one(self, project_id, resource):
        """Retrieve Quota information for the given project_id.

        :param id: project id.
        :param resource: resource name.
        """
        context = pecan.request.context
        policy.enforce(context, 'quota:get', action='quota:get')

        if not context.is_admin and project_id != context.project_id:
            raise exception.NotAuthorized()

        try:
            quota = objects.Quota.get_quota_by_project_id_resource(
                context, project_id, resource)
            quota = Quota.convert(quota)
        except exception.QuotaNotFound:
            # If explicit quota was not set for the project, use default limit
            quota = Quota(project_id=project_id,
                          hard_limit=CONF.quotas.max_clusters_per_project)
        return quota
Beispiel #3
0
    def get_all(self, project_id=None, type="cluster"):
        """Retrieve magnum stats.

        """
        context = pecan.request.context
        policy.enforce(context, 'stats:get_all', action='stats:get_all')
        allowed_stats = ["cluster"]

        if type.lower() not in allowed_stats:
            msg = _("Invalid stats type. Allowed values are '%s'")
            allowed_str = ','.join(allowed_stats)
            raise exception.InvalidParameterValue(err=msg % allowed_str)

        # 1.If the requester is not an admin and trying to request stats for
        # different tenant, then reject the request
        # 2.If the requester is not an admin and project_id was not provided,
        # then return self stats
        if not context.is_admin:
            project_id = project_id if project_id else context.project_id
            if project_id != context.project_id:
                raise exception.NotAuthorized()

        stats = objects.Stats.get_cluster_stats(context, project_id)
        return Stats.convert(stats)
Beispiel #4
0
 def test_NotAuthorized(self):
     self.assertRaises(exception.NotAuthorized,
                       lambda: self.raise_(exception.NotAuthorized()))