def show(self, req, id): context = req.environ['nova.context'] authorize(context) try: db.sqlalchemy.api.authorize_quota_class_context(context, id) return self._format_quota_set(id, quota.get_class_quotas(context, id)) except exception.NotAuthorized: raise webob.exc.HTTPForbidden()
def test_class_quotas(self): self._stub_class() result = quota.get_class_quotas(self.context, 'test_class') self.assertEqual(result, dict( instances=5, cores=10, ram=25 * 1024, volumes=5, gigabytes=500, floating_ips=5, metadata_items=64, injected_files=2, injected_file_content_bytes=5 * 1024, ))
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 quota.quota_resources: 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': quota.get_class_quotas(context, quota_class)}
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 quota.quota_resources: 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': quota.get_class_quotas(context, quota_class) }
def test_class_quotas(self): self._stub_class() result = quota.get_class_quotas(self.context, 'test_class') self.assertEqual( result, dict( instances=5, cores=10, ram=25 * 1024, volumes=5, gigabytes=500, floating_ips=5, metadata_items=64, injected_files=2, injected_file_content_bytes=5 * 1024, ))
def test_class_quotas_noclass(self): self._stub_class() result = quota.get_class_quotas(self.context, 'noclass') self.assertEqual(result, dict( instances=10, cores=20, ram=50 * 1024, volumes=10, gigabytes=1000, floating_ips=10, security_groups=10, security_group_rules=20, key_pairs=10, metadata_items=128, injected_files=5, injected_file_content_bytes=10 * 1024, ))
def test_class_quotas_noclass(self): self._stub_class() result = quota.get_class_quotas(self.context, 'noclass') self.assertEqual( result, dict( instances=10, cores=20, ram=50 * 1024, volumes=10, gigabytes=1000, floating_ips=10, security_groups=10, security_group_rules=20, key_pairs=10, metadata_items=128, injected_files=5, injected_file_content_bytes=10 * 1024, ))