From 5d92fc0d0a7c606fdcf7a3565801ae361389d9ab Mon Sep 17 00:00:00 2001
From: Dean Troyer <dtroyer@gmail.com>
Date: Mon, 2 Mar 2015 13:49:40 -0600
Subject: [PATCH] Handle novaclient >2.20.0

As of 2.21.0 novaclient moved all of the v1_1 classes to v2 with a
deprecation warning.  The version-non-specific interfaces provided in
novaclient.client are insufficient to support a few specific commands in
OSC so we need to conditionally import directly from the correct classes.

Closes-Bug: #1418024
Change-Id: I864b1908737803069dc1419c9cbca391b985c932
---
 openstackclient/compute/client.py            | 17 ++++++++---------
 openstackclient/compute/v2/security_group.py |  7 ++++++-
 openstackclient/compute/v2/server.py         |  6 +++++-
 3 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/openstackclient/compute/client.py b/openstackclient/compute/client.py
index 166747d59f..7ca08a4f23 100644
--- a/openstackclient/compute/client.py
+++ b/openstackclient/compute/client.py
@@ -15,8 +15,13 @@
 
 import logging
 
+from novaclient import client as nova_client
 from novaclient import extension
-from novaclient.v1_1.contrib import list_extensions
+
+try:
+    from novaclient.v2.contrib import list_extensions
+except ImportError:
+    from novaclient.v1_1.contrib import list_extensions
 
 from openstackclient.common import utils
 
@@ -25,19 +30,13 @@ LOG = logging.getLogger(__name__)
 DEFAULT_COMPUTE_API_VERSION = '2'
 API_VERSION_OPTION = 'os_compute_api_version'
 API_NAME = 'compute'
-API_VERSIONS = {
-    '1.1': 'novaclient.v1_1.client.Client',
-    '1': 'novaclient.v1_1.client.Client',
-    '2': 'novaclient.v1_1.client.Client',
-}
 
 
 def make_client(instance):
     """Returns a compute service client."""
-    compute_client = utils.get_client_class(
-        API_NAME,
+    compute_client = nova_client.get_client_class(
         instance._api_version[API_NAME],
-        API_VERSIONS)
+    )
     LOG.debug('Instantiating compute client: %s', compute_client)
 
     # Set client http_log_debug to True if verbosity level is high enough
diff --git a/openstackclient/compute/v2/security_group.py b/openstackclient/compute/v2/security_group.py
index f7ffb1d115..13a2103fae 100644
--- a/openstackclient/compute/v2/security_group.py
+++ b/openstackclient/compute/v2/security_group.py
@@ -24,7 +24,12 @@ from cliff import lister
 from cliff import show
 
 from keystoneclient import exceptions as ksc_exc
-from novaclient.v1_1 import security_group_rules
+
+try:
+    from novaclient.v2 import security_group_rules
+except ImportError:
+    from novaclient.v1_1 import security_group_rules
+
 from openstackclient.common import parseractions
 from openstackclient.common import utils
 
diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py
index f0a59d348b..3d28cc151b 100644
--- a/openstackclient/compute/v2/server.py
+++ b/openstackclient/compute/v2/server.py
@@ -26,7 +26,11 @@ import sys
 from cliff import command
 from cliff import lister
 from cliff import show
-from novaclient.v1_1 import servers
+
+try:
+    from novaclient.v2 import servers
+except ImportError:
+    from novaclient.v1_1 import servers
 
 from openstackclient.common import exceptions
 from openstackclient.common import parseractions