def update(self, req, id, body): context = req.environ['nova.context'] authorize(context) quota_class = id if not self.is_valid_body(body, 'quota_class_set'): msg = _("quota_class_set not specified") raise webob.exc.HTTPBadRequest(explanation=msg) quota_class_set = body['quota_class_set'] for key in quota_class_set.keys(): if key in QUOTAS: try: value = utils.validate_integer( body['quota_class_set'][key], key) except exception.InvalidInput as e: raise webob.exc.HTTPBadRequest( explanation=e.format_message()) 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) }
def update(self, req, id, body): context = req.environ['nova.context'] authorize(context) quota_class = id if not self.is_valid_body(body, 'quota_class_set'): msg = _("quota_class_set not specified") raise webob.exc.HTTPBadRequest(explanation=msg) quota_class_set = body['quota_class_set'] for key in quota_class_set.keys(): if key in QUOTAS: try: value = int(quota_class_set[key]) db.quota_class_update(context, quota_class, key, value) except (ValueError, TypeError): msg = _("Quota class '%(value)s' for %(key)s should be " "integer.") % { 'value': value, 'key': key } raise webob.exc.HTTPBadRequest(explanation=msg) 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) }
def update(self, req, id, body): context = req.environ['nova.context'] authorize(context) quota_class = id if not self.is_valid_body(body, 'quota_class_set'): raise webob.exc.HTTPBadRequest("The request body invalid") quota_class_set = body['quota_class_set'] for key in quota_class_set.keys(): if key in QUOTAS: try: value = int(quota_class_set[key]) except ValueError: msg = _("The value %s(val) of %(key)s isn't an " "integer") % {'val': body['quota_class_set'][key], 'key': key} 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 self._format_quota_set( quota_class, QUOTAS.get_class_quotas(context, quota_class))
def update(self, req, id, body): context = req.environ['nova.context'] authorize(context) quota_class = id if not self.is_valid_body(body, 'quota_class_set'): msg = _("quota_class_set not specified") raise webob.exc.HTTPBadRequest(explanation=msg) quota_class_set = body['quota_class_set'] for key in quota_class_set.keys(): if key in QUOTAS: try: value = utils.validate_integer( body['quota_class_set'][key], key) except exception.InvalidInput as e: raise webob.exc.HTTPBadRequest( explanation=e.format_message()) 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)}
def update(self, req, id, body): context = req.environ['nova.context'] authorize(context) quota_class = id bad_keys = [] if not self.is_valid_body(body, 'quota_class_set'): msg = _("quota_class_set not specified") raise webob.exc.HTTPBadRequest(explanation=msg) quota_class_set = body['quota_class_set'] for key in quota_class_set.keys(): if key not in self.supported_quotas: bad_keys.append(key) continue try: utils.validate_integer(body['quota_class_set'][key], key) except exception.InvalidInput as e: raise webob.exc.HTTPBadRequest(explanation=e.format_message()) if bad_keys: msg = _("Bad key(s) %s in quota_set") % ",".join(bad_keys) raise webob.exc.HTTPBadRequest(explanation=msg) for key in quota_class_set.keys(): value = utils.validate_integer(body['quota_class_set'][key], 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() values = QUOTAS.get_class_quotas(context, quota_class) return self._format_quota_set(None, values)
def update(self, req, id, body): context = req.environ['nova.context'] authorize(context) quota_class = id bad_keys = [] if not self.is_valid_body(body, 'quota_class_set'): msg = _("quota_class_set not specified") raise webob.exc.HTTPBadRequest(explanation=msg) quota_class_set = body['quota_class_set'] for key in quota_class_set.keys(): if key not in self.supported_quotas: bad_keys.append(key) continue try: body['quota_class_set'][key] = utils.validate_integer( body['quota_class_set'][key], key, max_value=db.MAX_INT) except exception.InvalidInput as e: raise webob.exc.HTTPBadRequest( explanation=e.format_message()) if bad_keys: msg = _("Bad key(s) %s in quota_set") % ",".join(bad_keys) raise webob.exc.HTTPBadRequest(explanation=msg) for key, value in 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() values = QUOTAS.get_class_quotas(context, quota_class) return self._format_quota_set(None, values)
def update(self, req, id, body): context = req.environ['nova.context'] authorize(context) quota_class = id if not self.is_valid_body(body, 'quota_class_set'): raise webob.exc.HTTPBadRequest("The request body invalid") quota_class_set = body['quota_class_set'] for key in quota_class_set.keys(): if key in QUOTAS and key not in FILTERED_QUOTAS: try: value = int(quota_class_set[key]) except ValueError: msg = _("The value %(val)s of %(key)s isn't an " "integer") % { 'val': body['quota_class_set'][key], 'key': key } 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 self._format_quota_set( quota_class, QUOTAS.get_class_quotas(context, quota_class))
def test_quota_class_unlimited(self): self.flags(quota_floating_ips=10) items = quota.allowed_floating_ips(self.context, 10) self.assertEqual(items, 10) self.context.quota_class = 'foo' db.quota_class_create(self.context, 'foo', 'floating_ips', -1) items = quota.allowed_floating_ips(self.context, 100) self.assertEqual(items, 100)
def update(self, req, id, body): context = req.environ['nova.context'] authorize(context, action='update', target={'quota_class': id}) quota_class = id for key, value in six.iteritems(body['quota_class_set']): try: db.quota_class_update(context, quota_class, key, value) except exception.QuotaClassNotFound: db.quota_class_create(context, quota_class, key, value) values = QUOTAS.get_class_quotas(context, quota_class) return self._format_quota_set(None, values)
def update(self, req, id, body): context = req.environ['nova.context'] authorize(context) try: utils.check_string_length(id, 'quota_class_name', min_length=1, max_length=255) except exception.InvalidInput as e: raise webob.exc.HTTPBadRequest(explanation=e.format_message()) quota_class = id bad_keys = [] if not self.is_valid_body(body, 'quota_class_set'): msg = _("quota_class_set not specified") raise webob.exc.HTTPBadRequest(explanation=msg) quota_class_set = body['quota_class_set'] for key in quota_class_set.keys(): if key not in self.supported_quotas: bad_keys.append(key) continue try: body['quota_class_set'][key] = utils.validate_integer( body['quota_class_set'][key], key, max_value=db.MAX_INT) except exception.InvalidInput as e: raise webob.exc.HTTPBadRequest(explanation=e.format_message()) if bad_keys: msg = _("Bad key(s) %s in quota_set") % ",".join(bad_keys) raise webob.exc.HTTPBadRequest(explanation=msg) try: # NOTE(alex_xu): back-compatible with db layer hard-code admin # permission checks. This has to be left only for API v2.0 because # this version has to be stable even if it means that only admins # can call this method while the policy could be changed. nova.context.require_admin_context(context) except exception.AdminRequired: raise webob.exc.HTTPForbidden() for key, value in 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) values = QUOTAS.get_class_quotas(context, quota_class) return self._format_quota_set(None, values)
def update(self, req, id, body): context = req.environ['nova.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)}
def update(self, req, id, body): context = req.environ['nova.context'] authorize(context) quota_class = id for key, value in body['quota_class_set'].iteritems(): 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() values = QUOTAS.get_class_quotas(context, quota_class) return self._format_quota_set(None, values)
def update(self, req, id, body): context = req.environ["nova.context"] authorize(context) try: utils.check_string_length(id, "quota_class_name", min_length=1, max_length=255) except exception.InvalidInput as e: raise webob.exc.HTTPBadRequest(explanation=e.format_message()) quota_class = id bad_keys = [] if not self.is_valid_body(body, "quota_class_set"): msg = _("quota_class_set not specified") raise webob.exc.HTTPBadRequest(explanation=msg) quota_class_set = body["quota_class_set"] for key in quota_class_set.keys(): if key not in self.supported_quotas: bad_keys.append(key) continue try: body["quota_class_set"][key] = utils.validate_integer( body["quota_class_set"][key], key, max_value=db.MAX_INT ) except exception.InvalidInput as e: raise webob.exc.HTTPBadRequest(explanation=e.format_message()) if bad_keys: msg = _("Bad key(s) %s in quota_set") % ",".join(bad_keys) raise webob.exc.HTTPBadRequest(explanation=msg) try: # NOTE(alex_xu): back-compatible with db layer hard-code admin # permission checks. This has to be left only for API v2.0 because # this version has to be stable even if it means that only admins # can call this method while the policy could be changed. nova.context.require_admin_context(context) except exception.AdminRequired: raise webob.exc.HTTPForbidden() for key, value in 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) values = QUOTAS.get_class_quotas(context, quota_class) return self._format_quota_set(None, values)
def update(self, req, id, body): context = req.environ['nova.context'] context.can(qcs_policies.POLICY_ROOT % 'update', {'quota_class': id}) try: utils.check_string_length(id, 'quota_class_name', min_length=1, max_length=255) except exception.InvalidInput as e: raise webob.exc.HTTPBadRequest( explanation=e.format_message()) quota_class = id for key, value in six.iteritems(body['quota_class_set']): try: db.quota_class_update(context, quota_class, key, value) except exception.QuotaClassNotFound: db.quota_class_create(context, quota_class, key, value) values = QUOTAS.get_class_quotas(context, quota_class) return self._format_quota_set(None, values)
def update(self, req, id, body): context = req.environ['nova.context'] authorize(context) quota_class = id if not self.is_valid_body(body, 'quota_class_set'): msg = _("quota_class_set not specified") raise webob.exc.HTTPBadRequest(explanation=msg) quota_class_set = body['quota_class_set'] for key in quota_class_set.keys(): if key in QUOTAS: try: value = int(quota_class_set[key]) db.quota_class_update(context, quota_class, key, value) except (ValueError, TypeError): msg = _("Quota class '%(value)s' for %(key)s should be " "integer.") % {'value': value, 'key': key} raise webob.exc.HTTPBadRequest(explanation=msg) 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)}