def show(self, req, id): context = req.environ["nova.context"] try: db.sqlalchemy.api.authorize_project_context(context, id) return self._format_quota_set(id, quota.get_project_quotas(context, id)) except exception.NotAuthorized: return webob.Response(status_int=403)
def show(self, req, id): context = req.environ['nova.context'] project_id = id return { 'quota_set': self._format_quota_set(id, quota.get_project_quotas(context, id)) }
def show(self, req, id): context = req.environ['nova.context'] try: db.sqlalchemy.api.authorize_project_context(context, id) return self._format_quota_set( id, quota.get_project_quotas(context, id)) except exception.NotAuthorized: return webob.Response(status_int=403)
def show(self, req, id): context = req.environ['nova.context'] try: db.sqlalchemy.api.authorize_project_context(context, id) return self._format_quota_set(id, quota.get_project_quotas(context, id)) except exception.NotAuthorized: raise webob.exc.HTTPForbidden()
def index(self, req): """ Return all global and rate limit information. """ context = req.environ['nova.context'] abs_limits = quota.get_project_quotas(context, context.project_id) rate_limits = req.environ.get("nova.limits", []) builder = self._get_view_builder(req) return builder.build(rate_limits, abs_limits)
def index(self, req): if urlparse.parse_qs(req.environ["QUERY_STRING"]).get("defaults", False): return {"quota_set_list": [self._format_quota_set("__defaults__", quota._get_default_quotas())]} else: context = req.environ["nova.context"] user = req.environ.get("user") projects = auth_manager.AuthManager().get_projects(user=user) quota_set_list = [ self._format_quota_set(project.name, quota.get_project_quotas(context, project.name)) for project in projects ] return {"quota_set_list": quota_set_list}
def update(self, req, id, body): context = req.environ['nova.context'] project_id = id for key in body['quota_set'].keys(): if key in quota_resources: value = int(body['quota_set'][key]) try: db.quota_update(context, project_id, key, value) except exception.ProjectQuotaNotFound: db.quota_create(context, project_id, key, value) except exception.AdminRequired: raise webob.exc.HTTPForbidden() return {'quota_set': quota.get_project_quotas(context, project_id)}
def index(self, req): if urlparse.parse_qs(req.environ['QUERY_STRING']).get('defaults', False): return {'quota_set_list': [self._format_quota_set('__defaults__', quota._get_default_quotas())]} else: context = req.environ['nova.context'] user = req.environ.get('user') projects = auth_manager.AuthManager().get_projects(user=user) quota_set_list = [self._format_quota_set(project.name, quota.get_project_quotas(context, project.name)) for project in projects] return {'quota_set_list': quota_set_list}
def update(self, req, id, body): context = req.environ['nova.context'] project_id = id resources = ['metadata_items', 'injected_file_content_bytes', 'volumes', 'gigabytes', 'ram', 'floating_ips', 'instances', 'injected_files', 'cores'] for key in body['quota_set'].keys(): if key in resources: value = int(body['quota_set'][key]) try: db.quota_update(context, project_id, key, value) except exception.ProjectQuotaNotFound: db.quota_create(context, project_id, key, value) return {'quota_set': quota.get_project_quotas(context, project_id)}
def test_project_quotas_overrides_noclass(self): self._stub_class() self._stub_project(True) result = quota.get_project_quotas(self.context, 'admin') self.assertEqual(result, dict( instances=2, cores=5, ram=12 * 1024, volumes=2, gigabytes=250, floating_ips=2, metadata_items=32, injected_files=1, injected_file_content_bytes=2 * 1024, ))
def test_project_quotas_defaults_noclass(self): self._stub_class() self._stub_project() result = quota.get_project_quotas(self.context, 'admin') self.assertEqual(result, dict( instances=10, cores=20, ram=50 * 1024, volumes=10, gigabytes=1000, floating_ips=10, metadata_items=128, injected_files=5, injected_file_content_bytes=10 * 1024, ))
def test_project_quotas_defaults_withclass(self): self._stub_class() self._stub_project() self.context.quota_class = 'test_class' result = quota.get_project_quotas(self.context, 'admin') 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_project_quotas_overrides_noclass(self): self._stub_class() self._stub_project(True) result = quota.get_project_quotas(self.context, 'admin') self.assertEqual( result, dict( instances=2, cores=5, ram=12 * 1024, volumes=2, gigabytes=250, floating_ips=2, metadata_items=32, injected_files=1, injected_file_content_bytes=2 * 1024, ))
def test_project_quotas_defaults_noclass(self): self._stub_class() self._stub_project() result = quota.get_project_quotas(self.context, 'admin') self.assertEqual( result, dict( instances=10, cores=20, ram=50 * 1024, volumes=10, gigabytes=1000, floating_ips=10, metadata_items=128, injected_files=5, injected_file_content_bytes=10 * 1024, ))
def test_project_quotas_defaults_withclass(self): self._stub_class() self._stub_project() self.context.quota_class = 'test_class' result = quota.get_project_quotas(self.context, 'admin') 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_project_quotas_overrides_withclass(self): self._stub_class() self._stub_project(True) self.context.quota_class = 'test_class' result = quota.get_project_quotas(self.context, 'admin') self.assertEqual(result, dict( instances=2, cores=5, ram=12 * 1024, volumes=2, gigabytes=250, floating_ips=2, security_groups=5, security_group_rules=10, key_pairs=5, metadata_items=32, injected_files=1, injected_file_content_bytes=2 * 1024, ))
def test_project_quotas_overrides_withclass(self): self._stub_class() self._stub_project(True) self.context.quota_class = 'test_class' result = quota.get_project_quotas(self.context, 'admin') self.assertEqual( result, dict( instances=2, cores=5, ram=12 * 1024, volumes=2, gigabytes=250, floating_ips=2, security_groups=5, security_group_rules=10, key_pairs=5, metadata_items=32, injected_files=1, injected_file_content_bytes=2 * 1024, ))
def update(self, req, id, body): context = req.environ["nova.context"] project_id = id resources = [ "metadata_items", "injected_file_content_bytes", "volumes", "gigabytes", "ram", "floating_ips", "instances", "injected_files", "cores", ] for key in body["quota_set"].keys(): if key in resources: value = int(body["quota_set"][key]) try: db.quota_update(context, project_id, key, value) except exception.ProjectQuotaNotFound: db.quota_create(context, project_id, key, value) return {"quota_set": quota.get_project_quotas(context, project_id)}
def show(self, req, id): context = req.environ['nova.context'] project_id = id return {'quota_set': self._format_quota_set(id, quota.get_project_quotas(context, id))}