Exemple #1
0
    def update(self, req, body, tenant_id, id):
        LOG.info("req : '%s'\n\n" % req)
        LOG.info("Updating quota limits for tenant '%s'" % id)
        if not body:
            raise exception.BadRequest(_("Invalid request body."))

        quotas = {}
        quota = None
        registered_resources = quota_engine.resources
        for resource, limit in body['quotas'].items():
            if limit is None:
                continue
            if resource == "xmlns":
                continue
            if resource not in registered_resources:
                raise exception.QuotaResourceUnknown(unknown=resource)
            try:
                quota = Quota.find_by(tenant_id=id, resource=resource)
                quota.hard_limit = limit
                quota.save()
            except exception.ModelNotFoundError:
                quota = Quota.create(tenant_id=id,
                                     resource=resource,
                                     hard_limit=limit)

            quotas[resource] = quota

        return wsgi.Result(views.QuotaView(quotas).data(), 200)
Exemple #2
0
    def show(self, req, tenant_id, id):
        """Return all quotas for this tenant."""
        LOG.info(
            _("Indexing quota info for tenant '%(id)s'\n"
              "req : '%(req)s'\n\n") % {
                  "id": id,
                  "req": req
              })

        quotas = quota_engine.get_all_quotas_by_tenant(id)
        return wsgi.Result(views.QuotaView(quotas).data(), 200)