]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Remove versioning import of novaclient
authorAndrey Kurilin <akurilin@mirantis.com>
Wed, 4 Feb 2015 13:10:57 +0000 (15:10 +0200)
committerAndrey Kurilin <akurilin@mirantis.com>
Fri, 20 Feb 2015 07:46:40 +0000 (09:46 +0200)
novaclient has specific function novaclient.client.Client for obtaining
client object. This fuction should be used instead of direct import.
Also, contrib path dependends on version, so we should get it based on
versioned client.

Change-Id: If9c55446c4d10a58e9723f5c333082bcacb431b8
Closes-Bug: #1418017

neutron/notifiers/nova.py
neutron/plugins/cisco/l3/service_vm_lib.py

index 455653d6372cb11ac2a6d442d6f6617f61c04986..bf0c3c28d92fd08566a5cdea0cd0391b7aed8284 100644 (file)
 #    under the License.
 
 import eventlet
+from novaclient import client as nova_client
 from novaclient import exceptions as nova_exceptions
-import novaclient.v1_1.client as nclient
-from novaclient.v1_1.contrib import server_external_events
 from oslo_config import cfg
+from oslo_utils import importutils
 from sqlalchemy.orm import attributes as sql_attr
 
 from neutron.common import constants
@@ -35,6 +35,7 @@ VIF_PLUGGED = 'network-vif-plugged'
 NEUTRON_NOVA_EVENT_STATUS_MAP = {constants.PORT_STATUS_ACTIVE: 'completed',
                                  constants.PORT_STATUS_ERROR: 'failed',
                                  constants.PORT_STATUS_DOWN: 'completed'}
+NOVA_API_VERSION = "2"
 
 
 class Notifier(object):
@@ -48,7 +49,15 @@ class Notifier(object):
         else:
             bypass_url = None
 
-        self.nclient = nclient.Client(
+        # NOTE(andreykurilin): novaclient.v1_1 was renamed to v2 and there is
+        # no way to import the contrib module directly without referencing v2,
+        # which would only work for novaclient >= 2.21.0.
+        novaclient_cls = nova_client.get_client_class(NOVA_API_VERSION)
+        server_external_events = importutils.import_module(
+            novaclient_cls.__module__.replace(
+                ".client", ".contrib.server_external_events"))
+
+        self.nclient = novaclient_cls(
             username=cfg.CONF.nova_admin_username,
             api_key=cfg.CONF.nova_admin_password,
             project_id=cfg.CONF.nova_admin_tenant_name,
index 6103db6d5cef12c643fa61c2da9981c1f2203e90..d8bb3389ef0e2085d442de3e1bff627caba14a7c 100644 (file)
@@ -12,9 +12,9 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+from novaclient import client
 from novaclient import exceptions as nova_exc
 from novaclient import utils as n_utils
-from novaclient.v1_1 import client
 from oslo_config import cfg
 
 from neutron.i18n import _LE
@@ -23,6 +23,7 @@ from neutron.openstack.common import log as logging
 from neutron.plugins.cisco.common import cisco_constants as c_constants
 
 LOG = logging.getLogger(__name__)
+NOVA_API_VERSION = "2"
 
 
 SERVICE_VM_LIB_OPTS = [
@@ -41,7 +42,8 @@ class ServiceVMManager(object):
 
     def __init__(self, user=None, passwd=None, l3_admin_tenant=None,
                  auth_url=''):
-        self._nclient = client.Client(user, passwd, l3_admin_tenant, auth_url,
+        self._nclient = client.Client(NOVA_API_VERSION, user, passwd,
+                                      l3_admin_tenant, auth_url,
                                       service_type="compute")
 
     @property