Coverage for manila/api/versions.py: 100%

39 statements  

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

1# Copyright 2010 OpenStack LLC. 

2# Copyright 2015 Clinton Knight 

3# All Rights Reserved. 

4# 

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

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

7# a copy of the License at 

8# 

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

10# 

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

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

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

14# License for the specific language governing permissions and limitations 

15# under the License. 

16 

17import copy 

18 

19from oslo_config import cfg 

20 

21from manila.api import extensions 

22from manila.api import openstack 

23from manila.api.openstack import api_version_request 

24from manila.api.openstack import wsgi 

25from manila.api.views import versions as views_versions 

26 

27CONF = cfg.CONF 

28 

29_LINKS = [{ 

30 'rel': 'describedby', 

31 'type': 'text/html', 

32 'href': 'http://docs.openstack.org/', 

33}] 

34 

35_MEDIA_TYPES = [{ 

36 'base': 'application/json', 

37 'type': 'application/vnd.openstack.share+json;version=1', 

38}] 

39 

40_KNOWN_VERSIONS = { 

41 'v1.0': { 

42 'id': 'v1.0', 

43 'status': 'DEPRECATED', 

44 'version': '', 

45 'min_version': '', 

46 'updated': '2015-08-27T11:33:21Z', 

47 'links': _LINKS, 

48 'media-types': _MEDIA_TYPES, 

49 }, 

50 'v2.0': { 

51 'id': 'v2.0', 

52 'status': 'CURRENT', 

53 'version': api_version_request._MAX_API_VERSION, 

54 'min_version': api_version_request._MIN_API_VERSION, 

55 'updated': '2015-08-27T11:33:21Z', 

56 'links': _LINKS, 

57 'media-types': _MEDIA_TYPES, 

58 }, 

59} 

60 

61 

62class VersionsRouter(openstack.APIRouter): 

63 """Route versions requests.""" 

64 

65 ExtensionManager = extensions.ExtensionManager 

66 

67 def _setup_routes(self, mapper): 

68 self.resources['versions'] = create_resource() 

69 mapper.connect('versions', '/', 

70 controller=self.resources['versions'], 

71 action='all') 

72 mapper.redirect('', '/') 

73 

74 

75class VersionsController(wsgi.Controller): 

76 

77 def __init__(self): 

78 super(VersionsController, self).__init__(None) 

79 

80 @wsgi.Controller.api_version('1.0', '1.0') 

81 def index(self, req): 

82 """Return versions supported prior to the microversions epoch.""" 

83 builder = views_versions.get_view_builder(req) 

84 known_versions = copy.deepcopy(_KNOWN_VERSIONS) 

85 known_versions.pop('v2.0') 

86 return builder.build_versions(known_versions) 

87 

88 @wsgi.Controller.api_version('2.0') # noqa 

89 def index(self, req): # pylint: disable=function-redefined # noqa F811 

90 """Return versions supported after the start of microversions.""" 

91 builder = views_versions.get_view_builder(req) 

92 known_versions = copy.deepcopy(_KNOWN_VERSIONS) 

93 known_versions.pop('v1.0') 

94 return builder.build_versions(known_versions) 

95 

96 # NOTE (cknight): Calling the versions API without 

97 # /v1 or /v2 in the URL will lead to this unversioned 

98 # method, which should always return info about all 

99 # available versions. 

100 @wsgi.response(300) 

101 def all(self, req): 

102 """Return all known versions.""" 

103 builder = views_versions.get_view_builder(req) 

104 known_versions = copy.deepcopy(_KNOWN_VERSIONS) 

105 return builder.build_versions(known_versions) 

106 

107 

108def create_resource(): 

109 return wsgi.Resource(VersionsController())