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

39 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-04-17 15:08 +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 import api_version_request 

17from nova.api.openstack.compute.schemas import versions as schema 

18from nova.api.openstack.compute.views import versions as views_versions 

19from nova.api.openstack import wsgi 

20from nova.api import validation 

21 

22 

23LINKS = { 

24 'v2.0': { 

25 'html': 'http://docs.openstack.org/' 

26 }, 

27 'v2.1': { 

28 'html': 'http://docs.openstack.org/' 

29 }, 

30} 

31 

32 

33VERSIONS = { 

34 "v2.0": { 

35 "id": "v2.0", 

36 "status": "SUPPORTED", 

37 "version": "", 

38 "min_version": "", 

39 "updated": "2011-01-21T11:33:21Z", 

40 "links": [ 

41 { 

42 "rel": "describedby", 

43 "type": "text/html", 

44 "href": LINKS['v2.0']['html'], 

45 }, 

46 ], 

47 "media-types": [ 

48 { 

49 "base": "application/json", 

50 "type": "application/vnd.openstack.compute+json;version=2", 

51 } 

52 ], 

53 }, 

54 "v2.1": { 

55 "id": "v2.1", 

56 "status": "CURRENT", 

57 "version": api_version_request._MAX_API_VERSION, 

58 "min_version": api_version_request._MIN_API_VERSION, 

59 "updated": "2013-07-23T11:33:21Z", 

60 "links": [ 

61 { 

62 "rel": "describedby", 

63 "type": "text/html", 

64 "href": LINKS['v2.1']['html'], 

65 }, 

66 ], 

67 "media-types": [ 

68 { 

69 "base": "application/json", 

70 "type": "application/vnd.openstack.compute+json;version=2.1", 

71 } 

72 ], 

73 } 

74} 

75 

76 

77class Versions(wsgi.Resource): 

78 

79 # The root version API isn't under the microversion control. 

80 support_api_request_version = False 

81 

82 def __init__(self): 

83 super(Versions, self).__init__(None) 

84 

85 @validation.query_schema(schema.show_query) 

86 @validation.response_body_schema(schema.index_response) 

87 def index(self, req, body=None): 

88 """Return all versions.""" 

89 builder = views_versions.get_view_builder(req) 

90 return builder.build_versions(VERSIONS) 

91 

92 @wsgi.response(300) 

93 @validation.query_schema(schema.multi_query) 

94 @validation.response_body_schema(schema.multi_response) 

95 def multi(self, req, body=None): 

96 """Return multiple choices.""" 

97 builder = views_versions.get_view_builder(req) 

98 return builder.build_choices(VERSIONS, req) 

99 

100 def get_action_args(self, request_environment): 

101 """Parse dictionary created by routes library.""" 

102 args = {} 

103 if request_environment['PATH_INFO'] == '/': 

104 args['action'] = 'index' 

105 else: 

106 args['action'] = 'multi' 

107 

108 return args 

109 

110 

111class VersionsV2(wsgi.Resource): 

112 

113 def __init__(self): 

114 super(VersionsV2, self).__init__(None) 

115 

116 # NOTE(stephenfin): Despite being called index, this is actually called as 

117 # a show action 

118 @validation.query_schema(schema.show_query) 

119 @validation.response_body_schema(schema.show_response) 

120 def index(self, req, body=None): 

121 builder = views_versions.get_view_builder(req) 

122 ver = 'v2.0' if req.is_legacy_v2() else 'v2.1' 

123 return builder.build_version(VERSIONS[ver]) 

124 

125 def get_action_args(self, request_environment): 

126 """Parse dictionary created by routes library.""" 

127 return {'action': 'index'}