From aedb9768d72079cfe6538f38b517adb4d81beb73 Mon Sep 17 00:00:00 2001 From: Andrey Kurilin Date: Wed, 4 Feb 2015 15:10:57 +0200 Subject: [PATCH] Remove versioning import of novaclient 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 | 15 ++++++++++++--- neutron/plugins/cisco/l3/service_vm_lib.py | 6 ++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/neutron/notifiers/nova.py b/neutron/notifiers/nova.py index 455653d6372..bf0c3c28d92 100644 --- a/neutron/notifiers/nova.py +++ b/neutron/notifiers/nova.py @@ -14,10 +14,10 @@ # 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, diff --git a/neutron/plugins/cisco/l3/service_vm_lib.py b/neutron/plugins/cisco/l3/service_vm_lib.py index 6103db6d5ce..d8bb3389ef0 100644 --- a/neutron/plugins/cisco/l3/service_vm_lib.py +++ b/neutron/plugins/cisco/l3/service_vm_lib.py @@ -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