|
14 | 14 | import functools |
15 | 15 | import logging |
16 | 16 | import os |
17 | | -import pkgutil |
18 | 17 | import re |
19 | 18 | import traceback |
20 | 19 | import warnings |
@@ -195,35 +194,59 @@ def __repr__(self): |
195 | 194 |
|
196 | 195 |
|
197 | 196 | def get_available_major_versions(): |
198 | | - # NOTE(andreykurilin): available clients version should not be |
199 | | - # hardcoded, so let's discover them. |
200 | | - matcher = re.compile(r"v[0-9]*$") |
201 | | - submodules = pkgutil.iter_modules([os.path.dirname(__file__)]) |
202 | | - available_versions = [name[1:] for loader, name, ispkg in submodules |
203 | | - if matcher.search(name)] |
204 | | - |
205 | | - return available_versions |
| 197 | + return ['2'] |
206 | 198 |
|
207 | 199 |
|
208 | 200 | def check_major_version(api_version): |
209 | 201 | """Checks major part of ``APIVersion`` obj is supported. |
210 | 202 |
|
211 | 203 | :raises novaclient.exceptions.UnsupportedVersion: if major part is not |
212 | | - supported |
| 204 | + supported |
213 | 205 | """ |
214 | | - available_versions = get_available_major_versions() |
215 | | - if (not api_version.is_null() and |
216 | | - str(api_version.ver_major) not in available_versions): |
217 | | - if len(available_versions) == 1: |
218 | | - msg = _("Invalid client version '%(version)s'. " |
219 | | - "Major part should be '%(major)s'") % { |
220 | | - "version": api_version.get_string(), |
221 | | - "major": available_versions[0]} |
222 | | - else: |
223 | | - msg = _("Invalid client version '%(version)s'. " |
224 | | - "Major part must be one of: '%(major)s'") % { |
225 | | - "version": api_version.get_string(), |
226 | | - "major": ", ".join(available_versions)} |
| 206 | + if api_version.is_null(): |
| 207 | + return |
| 208 | + |
| 209 | + if api_version.ver_major == 2: |
| 210 | + return |
| 211 | + |
| 212 | + msg = _( |
| 213 | + "Invalid client version '%(version)s'. Major part should be '2'" |
| 214 | + ) % {"version": api_version.get_string()} |
| 215 | + raise exceptions.UnsupportedVersion(msg) |
| 216 | + |
| 217 | + |
| 218 | +def check_version(api_version): |
| 219 | + """Checks if version of ``APIVersion`` is supported. |
| 220 | +
|
| 221 | + Provided as an alternative to :func:`check_major_version` to avoid changing |
| 222 | + the behavior of that function. |
| 223 | +
|
| 224 | + :raises novaclient.exceptions.UnsupportedVersion: if major part is not |
| 225 | + supported |
| 226 | + """ |
| 227 | + if api_version.is_null(): |
| 228 | + return |
| 229 | + |
| 230 | + # we can't use API_MIN_VERSION since we do support 2.0 (which is 2.1 but |
| 231 | + # less strict) |
| 232 | + if api_version < APIVersion('2.0'): |
| 233 | + msg = _( |
| 234 | + "Invalid client version '%(version)s'. " |
| 235 | + "Min version supported is '%(min_version)s'" |
| 236 | + ) % { |
| 237 | + "version": api_version.get_string(), |
| 238 | + "min_version": novaclient.API_MIN_VERSION, |
| 239 | + } |
| 240 | + raise exceptions.UnsupportedVersion(msg) |
| 241 | + |
| 242 | + if api_version > novaclient.API_MAX_VERSION: |
| 243 | + msg = _( |
| 244 | + "Invalid client version '%(version)s'. " |
| 245 | + "Max version supported is '%(max_version)s'" |
| 246 | + ) % { |
| 247 | + "version": api_version.get_string(), |
| 248 | + "max_version": novaclient.API_MAX_VERSION, |
| 249 | + } |
227 | 250 | raise exceptions.UnsupportedVersion(msg) |
228 | 251 |
|
229 | 252 |
|
|
0 commit comments