1#    Licensed under the Apache License, Version 2.0 (the "License"); you may
2#    not use this file except in compliance with the License. You may obtain
3#    a copy of the License at
4#
5#         http://www.apache.org/licenses/LICENSE-2.0
6#
7#    Unless required by applicable law or agreed to in writing, software
8#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10#    License for the specific language governing permissions and limitations
11#    under the License.
12
13"""API Microversion definitions.
14
15All new microversions should have a constant added here to be used throughout
16the code instead of the specific version number. Until patches land, it's
17common to end up with merge conflicts with other microversion changes. Merge
18conflicts will be easier to handle via the microversion constants defined here
19as the version number will only need to be changed in a single location.
20
21Actual version numbers should be used:
22
23  * In this file
24  * In cinder/api/openstack/rest_api_version_history.rst
25  * In cinder/api/openstack/api_version_request.py
26  * In release notes describing the new functionality
27  * In updates to api-ref
28
29Nearly all microversion changes should include changes to all of those
30locations. Make sure to add relevant documentation, and make sure that
31documentation includes the final version number used.
32"""
33
34from cinder.api.openstack import api_version_request as api_version
35from cinder import exception
36
37
38# Add new constants here for each new microversion.
39
40BASE_VERSION = '3.0'
41
42UPLOAD_IMAGE_PARAMS = '3.1'
43
44VOLUME_LIST_BOOTABLE = '3.2'
45
46MESSAGES = '3.3'
47
48VOLUME_LIST_GLANCE_METADATA = '3.4'
49
50MESSAGES_PAGINATION = '3.5'
51
52CG_UPDATE_BLANK_PROPERTIES = '3.6'
53
54CLUSTER_SUPPORT = '3.7'
55
56MANAGE_EXISTING_LIST = '3.8'
57
58BACKUP_UPDATE = '3.9'
59
60VOLUME_LIST_GROUP = '3.10'
61
62GROUP_TYPE = '3.11'
63
64VOLUME_SUMMARY = '3.12'
65
66GROUP_VOLUME = '3.13'
67
68GROUP_SNAPSHOTS = '3.14'
69
70ETAGS = '3.15'
71
72VOLUME_MIGRATE_CLUSTER = '3.16'
73
74MANAGE_EXISTING_CLUSTER = '3.17'
75
76BACKUP_PROJECT = '3.18'
77
78GROUP_SNAPSHOT_RESET_STATUS = '3.19'
79
80GROUP_VOLUME_RESET_STATUS = '3.20'
81
82VOLUME_DETAIL_PROVIDER_ID = '3.21'
83
84SNAPSHOT_LIST_METADATA_FILTER = '3.22'
85
86VOLUME_DELETE_FORCE = '3.23'
87
88WORKERS_CLEANUP = '3.24'
89
90GROUP_VOLUME_LIST = '3.25'
91
92REPLICATION_CLUSTER = '3.26'
93
94NEW_ATTACH = '3.27'
95
96POOL_FILTER = '3.28'
97
98GROUP_SNAPSHOT_PAGINATION = '3.29'
99
100SNAPSHOT_SORT = '3.30'
101
102RESOURCE_FILTER = '3.31'
103
104LOG_LEVEL = '3.32'
105
106RESOURCE_FILTER_CONFIG = '3.33'
107
108LIKE_FILTER = '3.34'
109
110POOL_TYPE_FILTER = '3.35'
111
112VOLUME_SUMMARY_METADATA = '3.36'
113
114BACKUP_SORT_NAME = '3.37'
115
116GROUP_REPLICATION = '3.38'
117
118LIMITS_ADMIN_FILTER = '3.39'
119
120VOLUME_REVERT = '3.40'
121
122SNAPSHOT_LIST_USER_ID = '3.41'
123
124VOLUME_EXTEND_INUSE = '3.42'
125
126BACKUP_METADATA = '3.43'
127
128NEW_ATTACH_COMPLETION = '3.44'
129
130SUPPORT_COUNT_INFO = '3.45'
131
132SUPPORT_NOVA_IMAGE = '3.46'
133
134VOLUME_CREATE_FROM_BACKUP = '3.47'
135
136VOLUME_SHARED_TARGETS_AND_SERVICE_FIELDS = '3.48'
137
138BACKEND_STATE_REPORT = '3.49'
139
140MULTIATTACH_VOLUMES = '3.50'
141
142
143def get_mv_header(version):
144    """Gets a formatted HTTP microversion header.
145
146    :param version: The microversion needed.
147    :return: A tuple containing the microversion header with the
148             requested version value.
149    """
150    return {'OpenStack-API-Version':
151            'volume %s' % version}
152
153
154def get_api_version(version):
155    """Gets a ``APIVersionRequest`` instance.
156
157    :param version: The microversion needed.
158    :return: The ``APIVersionRequest`` instance.
159    """
160    return api_version.APIVersionRequest(version)
161
162
163def get_prior_version(version):
164    """Gets the microversion before the given version.
165
166    Mostly useful for testing boundaries. This gets the microversion defined
167    just prior to the given version.
168
169    :param version: The version of interest.
170    :return: The version just prior to the given version.
171    """
172    parts = version.split('.')
173
174    if len(parts) != 2 or parts[0] != '3':
175        raise exception.InvalidInput(reason='Version %s is not a valid '
176                                     'microversion format.' % version)
177
178    minor = int(parts[1]) - 1
179
180    if minor < 0:
181        # What's your problem? Are you trying to be difficult?
182        minor = 0
183
184    return '%s.%s' % (parts[0], minor)
185