@@ -41,8 +41,18 @@ def make_client(instance):
4141 version = _compute_api_version
4242 else :
4343 version = instance ._api_version [API_NAME ]
44+ from novaclient import api_versions
45+ # convert to APIVersion object
46+ version = api_versions .get_api_version (version )
47+
48+ if version .is_latest ():
49+ import novaclient
50+ # NOTE(RuiChen): executing version discovery make sense, but that need
51+ # an initialized REST client, it's not available now,
52+ # fallback to use the max version of novaclient side.
53+ version = novaclient .API_MAX_VERSION
4454
45- LOG .debug ('Instantiating compute client for V %s' , version )
55+ LOG .debug ('Instantiating compute client for %s' , version )
4656
4757 # Set client http_log_debug to True if verbosity level is high enough
4858 http_log_debug = utils .get_effective_log_level () <= logging .DEBUG
@@ -91,30 +101,27 @@ def check_api_version(check_version):
91101 """
92102
93103 # Defer client imports until we actually need them
94- try :
95- from novaclient import api_versions
96- except ImportError :
97- # Retain previous behaviour
98- return False
99-
100104 import novaclient
105+ from novaclient import api_versions
101106
102107 global _compute_api_version
103108
104- # Copy some logic from novaclient 2.27 .0 for basic version detection
109+ # Copy some logic from novaclient 3.3 .0 for basic version detection
105110 # NOTE(dtroyer): This is only enough to resume operations using API
106111 # version 2.0 or any valid version supplied by the user.
107112 _compute_api_version = api_versions .get_api_version (check_version )
108113
109- if _compute_api_version > api_versions .APIVersion ("2.0" ):
110- if not _compute_api_version .matches (
111- novaclient .API_MIN_VERSION ,
112- novaclient .API_MAX_VERSION ,
113- ):
114- raise exceptions .CommandError (
115- "versions supported by client: %s - %s" % (
116- novaclient .API_MIN_VERSION .get_string (),
117- novaclient .API_MAX_VERSION .get_string (),
118- ),
119- )
114+ # Bypass X.latest format microversion
115+ if not _compute_api_version .is_latest ():
116+ if _compute_api_version > api_versions .APIVersion ("2.0" ):
117+ if not _compute_api_version .matches (
118+ novaclient .API_MIN_VERSION ,
119+ novaclient .API_MAX_VERSION ,
120+ ):
121+ raise exceptions .CommandError (
122+ "versions supported by client: %s - %s" % (
123+ novaclient .API_MIN_VERSION .get_string (),
124+ novaclient .API_MAX_VERSION .get_string (),
125+ ),
126+ )
120127 return True
0 commit comments