Coverage for nova/api/openstack/compute/limits.py: 100%

46 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-04-24 11:16 +0000

1# Copyright 2011 OpenStack Foundation 

2# All Rights Reserved. 

3# 

4# Licensed under the Apache License, Version 2.0 (the "License"); you may 

5# not use this file except in compliance with the License. You may obtain 

6# a copy of the License at 

7# 

8# http://www.apache.org/licenses/LICENSE-2.0 

9# 

10# Unless required by applicable law or agreed to in writing, software 

11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 

12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 

13# License for the specific language governing permissions and limitations 

14# under the License. 

15 

16from nova.api.openstack.api_version_request \ 

17 import MAX_IMAGE_META_PROXY_API_VERSION 

18from nova.api.openstack.api_version_request \ 

19 import MAX_PROXY_API_SUPPORT_VERSION 

20from nova.api.openstack.api_version_request \ 

21 import MIN_WITHOUT_IMAGE_META_PROXY_API_VERSION 

22from nova.api.openstack.api_version_request \ 

23 import MIN_WITHOUT_PROXY_API_SUPPORT_VERSION 

24from nova.api.openstack.compute.schemas import limits 

25from nova.api.openstack.compute.views import limits as limits_views 

26from nova.api.openstack import wsgi 

27from nova.api import validation 

28from nova.policies import limits as limits_policies 

29from nova import quota 

30 

31 

32QUOTAS = quota.QUOTAS 

33 

34# This is a list of limits which needs to filter out from the API response. 

35# This is due to the deprecation of network related proxy APIs, the related 

36# limit should be removed from the API also. 

37FILTERED_LIMITS_2_36 = ['floating_ips', 'security_groups', 

38 'security_group_rules'] 

39 

40FILTERED_LIMITS_2_57 = list(FILTERED_LIMITS_2_36) 

41FILTERED_LIMITS_2_57.extend(['injected_files', 'injected_file_content_bytes']) 

42 

43 

44class LimitsController(wsgi.Controller): 

45 """Controller for accessing limits in the OpenStack API.""" 

46 

47 @wsgi.Controller.api_version("2.1", MAX_PROXY_API_SUPPORT_VERSION) 

48 @wsgi.expected_errors(()) 

49 @validation.query_schema(limits.limits_query_schema) 

50 def index(self, req): 

51 return self._index(req) 

52 

53 @wsgi.Controller.api_version(MIN_WITHOUT_PROXY_API_SUPPORT_VERSION, # noqa 

54 MAX_IMAGE_META_PROXY_API_VERSION) 

55 @wsgi.expected_errors(()) 

56 @validation.query_schema(limits.limits_query_schema) 

57 def index(self, req): # noqa 

58 return self._index(req, FILTERED_LIMITS_2_36) 

59 

60 @wsgi.Controller.api_version( # noqa 

61 MIN_WITHOUT_IMAGE_META_PROXY_API_VERSION, '2.56') 

62 @wsgi.expected_errors(()) 

63 @validation.query_schema(limits.limits_query_schema) 

64 def index(self, req): # noqa 

65 return self._index(req, FILTERED_LIMITS_2_36, max_image_meta=False) 

66 

67 @wsgi.Controller.api_version('2.57') # noqa 

68 @wsgi.expected_errors(()) 

69 @validation.query_schema(limits.limits_query_schema_275, '2.75') 

70 @validation.query_schema(limits.limits_query_schema, '2.57', '2.74') 

71 def index(self, req): # noqa 

72 return self._index(req, FILTERED_LIMITS_2_57, max_image_meta=False) 

73 

74 def _index(self, req, filtered_limits=None, max_image_meta=True): 

75 """Return all global limit information.""" 

76 context = req.environ['nova.context'] 

77 context.can(limits_policies.BASE_POLICY_NAME, target={}) 

78 project_id = context.project_id 

79 if 'tenant_id' in req.GET: 

80 project_id = req.GET.get('tenant_id') 

81 context.can(limits_policies.OTHER_PROJECT_LIMIT_POLICY_NAME) 

82 

83 quotas = QUOTAS.get_project_quotas(context, project_id, 

84 usages=True) 

85 builder = limits_views.ViewBuilder() 

86 return builder.build(req, quotas, filtered_limits=filtered_limits, 

87 max_image_meta=max_image_meta)