コード例 #1
0
    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)
        }
コード例 #2
0
    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)
        }
コード例 #3
0
ファイル: quota_classes.py プロジェクト: Jonbeek/nova
 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))
コード例 #4
0
ファイル: quota_classes.py プロジェクト: CLisa/nova
    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)}
コード例 #5
0
ファイル: quota_classes.py プロジェクト: zlzlnet/nova
    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)
コード例 #6
0
ファイル: quota_classes.py プロジェクト: tudorvio/nova
    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)
コード例 #7
0
ファイル: quota_classes.py プロジェクト: BigFire/nova-1
 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))
コード例 #8
0
ファイル: test_quota.py プロジェクト: andrewbogott/nova
 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)
コード例 #9
0
 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)
コード例 #10
0
    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)
コード例 #11
0
ファイル: quota_classes.py プロジェクト: henrylv206/nova
    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)
コード例 #12
0
    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)
コード例 #13
0
ファイル: quota_classes.py プロジェクト: StackOps/nova
 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)}
コード例 #14
0
ファイル: quota_classes.py プロジェクト: paulmathews/nova
 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)}
コード例 #15
0
    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)
コード例 #16
0
ファイル: quota_classes.py プロジェクト: jorgevgut/nova
    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)
コード例 #17
0
ファイル: quota_classes.py プロジェクト: eepalms/CloudMonatt
    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)
コード例 #18
0
ファイル: quota_classes.py プロジェクト: AZBob/nova
    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)}