Esempio n. 1
0
    def update(self, req, id, body):
        context = req.environ['cinder.context']
        authorize(context)
        quota_class = id
        if not self.is_valid_body(body, 'quota_class_set'):
            msg = (_("Missing required element quota_class_set"
                     " in request body."))
            raise webob.exc.HTTPBadRequest(explanation=msg)

        for key in body['quota_class_set'].keys():
            if key in QUOTAS:
                try:
                    value = int(body['quota_class_set'][key])
                except ValueError:
                    msg = _("Quota class limit must be specified as an"
                            " integer value.")
                    raise webob.exc.HTTPBadRequest(explanation=msg)
                if value < -1:
                    msg = _("Quota class limit must be -1 or greater.")
                    raise webob.exc.HTTPBadRequest(explanation=msg)
                try:
                    db.quota_class_update(context, quota_class, key, value)
                except exception.QuotaClassNotFound:
                    db.quota_class_create(context, quota_class, key, value)
                except exception.AdminRequired:
                    raise webob.exc.HTTPForbidden()
        return {'quota_class_set': QUOTAS.get_class_quotas(context,
                                                           quota_class)}
Esempio n. 2
0
    def update(self, req, id, body):
        context = req.environ['cinder.context']
        authorize(context)
        self.validate_string_length(id,
                                    'quota_class_name',
                                    min_length=1,
                                    max_length=255)

        quota_class = id
        if not self.is_valid_body(body, 'quota_class_set'):
            msg = (_("Missing required element quota_class_set"
                     " in request body."))
            raise webob.exc.HTTPBadRequest(explanation=msg)

        for key, value in body['quota_class_set'].items():
            if key in QUOTAS:
                try:
                    value = utils.validate_integer(value,
                                                   key,
                                                   min_value=-1,
                                                   max_value=db.MAX_INT)
                    db.quota_class_update(context, quota_class, key, value)
                except exception.QuotaClassNotFound:
                    db.quota_class_create(context, quota_class, key, value)
                except exception.AdminRequired:
                    raise webob.exc.HTTPForbidden()
        return {
            'quota_class_set': QUOTAS.get_class_quotas(context, quota_class)
        }
Esempio n. 3
0
    def update(self, req, id, body):
        context = req.environ['cinder.context']
        authorize(context)
        quota_class = id
        if not self.is_valid_body(body, 'quota_class_set'):
            msg = (_("Missing required element quota_class_set"
                     " in request body."))
            raise webob.exc.HTTPBadRequest(explanation=msg)

        for key in body['quota_class_set'].keys():
            if key in QUOTAS:
                try:
                    value = int(body['quota_class_set'][key])
                except ValueError:
                    msg = _("Quota class limit must be specified as an"
                            " integer value.")
                    raise webob.exc.HTTPBadRequest(explanation=msg)
                if value < -1:
                    msg = _("Quota class limit must be -1 or greater.")
                    raise webob.exc.HTTPBadRequest(explanation=msg)
                try:
                    db.quota_class_update(context, quota_class, key, value)
                except exception.QuotaClassNotFound:
                    db.quota_class_create(context, quota_class, key, value)
                except exception.AdminRequired:
                    raise webob.exc.HTTPForbidden()
        return {
            'quota_class_set': QUOTAS.get_class_quotas(context, quota_class)
        }
Esempio n. 4
0
    def update(self, req, id, body):
        context = req.environ['cinder.context']
        authorize(context)
        self.validate_string_length(id, 'quota_class_name',
                                    min_length=1, max_length=255)

        quota_class = id
        if not self.is_valid_body(body, 'quota_class_set'):
            msg = (_("Missing required element quota_class_set"
                     " in request body."))
            raise webob.exc.HTTPBadRequest(explanation=msg)

        for key, value in body['quota_class_set'].items():
            if key in QUOTAS or key in GROUP_QUOTAS:
                try:
                    value = utils.validate_integer(value, key, min_value=-1,
                                                   max_value=db.MAX_INT)
                    db.quota_class_update(context, quota_class, key, value)
                except exception.QuotaClassNotFound:
                    db.quota_class_create(context, quota_class, key, value)
                except exception.AdminRequired:
                    raise webob.exc.HTTPForbidden()

        quota_set = QUOTAS.get_class_quotas(context, quota_class)
        group_quota_set = GROUP_QUOTAS.get_class_quotas(context, quota_class)
        quota_set.update(group_quota_set)

        return {'quota_class_set': quota_set}
    def update(self, req, id, body):
        context = req.environ['cinder.context']
        context.authorize(policy.MANAGE_POLICY)
        self.validate_string_length(id,
                                    'quota_class_name',
                                    min_length=1,
                                    max_length=255)

        quota_class = id
        self.assert_valid_body(body, 'quota_class_set')

        for key, value in body['quota_class_set'].items():
            if key in QUOTAS or key in GROUP_QUOTAS:
                try:
                    value = utils.validate_integer(value,
                                                   key,
                                                   min_value=-1,
                                                   max_value=db.MAX_INT)
                    db.quota_class_update(context, quota_class, key, value)
                except exception.QuotaClassNotFound:
                    db.quota_class_create(context, quota_class, key, value)
                except exception.AdminRequired:
                    raise webob.exc.HTTPForbidden()

        quota_set = QUOTAS.get_class_quotas(context, quota_class)
        group_quota_set = GROUP_QUOTAS.get_class_quotas(context, quota_class)
        quota_set.update(group_quota_set)

        return {'quota_class_set': quota_set}
Esempio n. 6
0
    def update(self, req, id, body):
        context = req.environ['cinder.context']
        context.authorize(policy.MANAGE_POLICY)
        self.validate_string_length(id, 'quota_class_name',
                                    min_length=1, max_length=255)

        quota_class = id
        self.assert_valid_body(body, 'quota_class_set')

        for key, value in body['quota_class_set'].items():
            if key in QUOTAS or key in GROUP_QUOTAS:
                try:
                    value = utils.validate_integer(value, key, min_value=-1,
                                                   max_value=db.MAX_INT)
                    db.quota_class_update(context, quota_class, key, value)
                except exception.QuotaClassNotFound:
                    db.quota_class_create(context, quota_class, key, value)
                except exception.AdminRequired:
                    raise webob.exc.HTTPForbidden()

        quota_set = QUOTAS.get_class_quotas(context, quota_class)
        group_quota_set = GROUP_QUOTAS.get_class_quotas(context, quota_class)
        quota_set.update(group_quota_set)

        return {'quota_class_set': quota_set}
Esempio n. 7
0
 def update(self, req, id, body):
     context = req.environ['cinder.context']
     authorize(context)
     quota_class = id
     for key in body['quota_class_set'].keys():
         if key in QUOTAS:
             value = int(body['quota_class_set'][key])
             try:
                 db.quota_class_update(context, quota_class, key, value)
             except exception.QuotaClassNotFound:
                 db.quota_class_create(context, quota_class, key, value)
             except exception.AdminRequired:
                 raise webob.exc.HTTPForbidden()
     return {'quota_class_set': QUOTAS.get_class_quotas(context,
                                                        quota_class)}
Esempio n. 8
0
    def update(self, req, id, body):
        context = req.environ['cinder.context']
        context.authorize(policy.UPDATE_POLICY)
        self.validate_string_length(id,
                                    'quota_class_name',
                                    min_length=1,
                                    max_length=255)

        quota_class = id

        for key, value in body['quota_class_set'].items():
            try:
                db.quota_class_update(context, quota_class, key, value)
            except exception.QuotaClassNotFound:
                db.quota_class_create(context, quota_class, key, value)
            except exception.AdminRequired:
                raise webob.exc.HTTPForbidden()

        quota_set = QUOTAS.get_class_quotas(context, quota_class)
        group_quota_set = GROUP_QUOTAS.get_class_quotas(context, quota_class)
        quota_set.update(group_quota_set)

        return {'quota_class_set': quota_set}
Esempio n. 9
0
 def test_quota_class_update(self):
     db.quota_class_update(self.ctxt, 'test_qc', 'test_resource', 43)
     updated = db.quota_class_get(self.ctxt, 'test_qc', 'test_resource')
     self.assertEqual(43, updated['hard_limit'])
Esempio n. 10
0
 def test_quota_class_update(self):
     db.quota_class_update(self.ctxt, 'test_qc', 'test_resource', 43)
     updated = db.quota_class_get(self.ctxt, 'test_qc', 'test_resource')
     self.assertEqual(43, updated['hard_limit'])
Esempio n. 11
0
 def test_quota_class_update(self):
     db.quota_class_update(self.ctxt, "test_qc", "test_resource", 43)
     updated = db.quota_class_get(self.ctxt, "test_qc", "test_resource")
     self.assertEqual(43, updated["hard_limit"])