Coverage for manila/api/v2/availability_zones.py: 100%

30 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2026-02-18 22:19 +0000

1# Copyright (c) 2013 OpenStack Foundation 

2# Copyright (c) 2015 Mirantis inc. 

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 manila.api.openstack import wsgi 

17from manila.api.schemas import availability_zones as schema 

18from manila.api import validation 

19from manila.api.views import availability_zones as availability_zones_views 

20from manila import db 

21 

22 

23class AvailabilityZoneMixin(object): 

24 """The Availability Zone API controller common logic. 

25 

26 Mixin class that should be inherited by Availability Zone API controllers, 

27 which are used for different API URLs and microversions. 

28 """ 

29 

30 resource_name = "availability_zone" 

31 _view_builder_class = availability_zones_views.ViewBuilder 

32 

33 @wsgi.Controller.authorize("index") 

34 def _index(self, req): 

35 """Describe all known availability zones.""" 

36 views = db.availability_zone_get_all(req.environ['manila.context']) 

37 return self._view_builder.detail_list(views) 

38 

39 

40@validation.validated 

41class AvailabilityZoneControllerLegacy(AvailabilityZoneMixin, wsgi.Controller): 

42 """Deprecated Availability Zone API controller. 

43 

44 Used from microversions 2.0 to 2.6. Registered under deprecated API URL 

45 'os-availability-zone'. 

46 """ 

47 

48 @wsgi.Controller.api_version('1.0', '2.6') 

49 @validation.request_query_schema(schema.index_request_query) 

50 @validation.response_body_schema(schema.index_response_body) 

51 def index(self, req): 

52 return self._index(req) 

53 

54 

55@validation.validated 

56class AvailabilityZoneController(AvailabilityZoneMixin, wsgi.Controller): 

57 """Availability Zone API controller. 

58 

59 Used from microversion 2.7. Registered under API URL 'availability-zones'. 

60 """ 

61 

62 @wsgi.Controller.api_version('2.7') 

63 @validation.request_query_schema(schema.index_request_query) 

64 @validation.response_body_schema(schema.index_response_body) 

65 def index(self, req): 

66 return self._index(req) 

67 

68 

69def create_resource_legacy(): 

70 return wsgi.Resource(AvailabilityZoneControllerLegacy()) 

71 

72 

73def create_resource(): 

74 return wsgi.Resource(AvailabilityZoneController())