diff options
| author | Sean McGinnis <sean.mcginnis@gmail.com> | 2018-10-10 11:12:40 -0500 |
|---|---|---|
| committer | Sean McGinnis <sean.mcginnis@gmail.com> | 2018-10-12 14:19:51 -0500 |
| commit | 651f0c38a1f364953dc3cb3f7458385410395fd8 (patch) | |
| tree | 9f199ad98602e6035c655a8e84c2f7dadcaab2d8 /openstackclient/volume/client.py | |
| parent | e3dc30fe8c1ae6a13926bf1eae52097e8bb37aab (diff) | |
| download | python-openstackclient-651f0c38a1f364953dc3cb3f7458385410395fd8.tar.gz | |
Handle not having cinderclient.v1 available
The Cinder v1 API was deprecated several years ago and may be removed
from python-cinderclient in the near future. To handle the case where v1
is no longer present, this updates cinderclient initialization to work
without it and give an appropriate error if v1 is requested with a
version where it is no longer available.
Change-Id: I277d7b48b8ad4cce383ec3722f8117938378f615
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
Diffstat (limited to 'openstackclient/volume/client.py')
| -rw-r--r-- | openstackclient/volume/client.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/openstackclient/volume/client.py b/openstackclient/volume/client.py index c4b0dfca..e0e670a9 100644 --- a/openstackclient/volume/client.py +++ b/openstackclient/volume/client.py @@ -37,13 +37,20 @@ def make_client(instance): # Defer client imports until we actually need them from cinderclient import extension - from cinderclient.v1.contrib import list_extensions - from cinderclient.v1 import volume_snapshots - from cinderclient.v1 import volumes - - # Monkey patch for v1 cinderclient - volumes.Volume.NAME_ATTR = 'display_name' - volume_snapshots.Snapshot.NAME_ATTR = 'display_name' + from cinderclient.v3.contrib import list_extensions + from cinderclient.v3 import volume_snapshots + from cinderclient.v3 import volumes + + # Try a small import to check if cinderclient v1 is supported + try: + from cinderclient.v1 import services # noqa + except Exception: + del API_VERSIONS['1'] + + if instance._api_version[API_NAME] == '1': + # Monkey patch for v1 cinderclient + volumes.Volume.NAME_ATTR = 'display_name' + volume_snapshots.Snapshot.NAME_ATTR = 'display_name' volume_client = utils.get_client_class( API_NAME, |
