Exemplo n.º 1
0
    def delete(self, project_id, resource):
        """Delete Quota for a given project_id and resource.

        :param project_id: project id.
        :param resource: resource name.
        """

        context = pecan.request.context
        policy.enforce(context, 'quota:delete', action='quota:delete')
        quota_dict = {"project_id": project_id, "resource": resource}
        quota = objects.Quota(context, **quota_dict)
        quota.delete()
Exemplo n.º 2
0
def get_test_quota(context, **kw):
    """Return a Quota object with appropriate attributes.

    NOTE: The object leaves the attributes marked as changed, such
    that a create() could be used to commit it to the DB.
    """
    db_quota = db_utils.get_test_quota(**kw)
    # Let DB generate ID if it isn't specified explicitly
    if 'id' not in kw:
        del db_quota['id']
    quota = objects.Quota(context)
    for key in db_quota:
        setattr(quota, key, db_quota[key])
    return quota
Exemplo n.º 3
0
    def post(self, quota):
        """Create Quota.

        :param quota: a json document to create this Quota.
        """

        context = pecan.request.context
        policy.enforce(context, 'quota:create', action='quota:create')

        quota_dict = quota.as_dict()
        if 'project_id' not in quota_dict or not quota_dict['project_id']:
            msg = _('Must provide a valid project ID.')
            raise exception.InvalidParameterValue(message=msg)

        new_quota = objects.Quota(context, **quota_dict)
        new_quota.create()
        return Quota.convert(new_quota)