From 6776dd66aca5055d72e0d3283dd4190c8f9555d5 Mon Sep 17 00:00:00 2001 From: LiuNanke Date: Tue, 8 Nov 2016 14:03:25 +0800 Subject: [PATCH] Make method import_versioned_module work Oslo.utils 3.17 provides similar function, just use it. For more information: [1] http://docs.openstack.org/developer/oslo.utils/history.html Change-Id: I77b0517422569f9ef559b2cf7c7d954713c74de5 Closes-Bug: #1627313 --- muranoclient/client.py | 5 +++-- muranoclient/common/utils.py | 9 +-------- muranoclient/shell.py | 4 +++- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/muranoclient/client.py b/muranoclient/client.py index d38702e5..485ed898 100644 --- a/muranoclient/client.py +++ b/muranoclient/client.py @@ -11,10 +11,11 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -from muranoclient.common import utils +from oslo_utils import importutils def Client(version, *args, **kwargs): - module = utils.import_versioned_module(version, 'client') + module = importutils.import_versioned_module('muranoclient', + version, 'client') client_class = getattr(module, 'Client') return client_class(*args, **kwargs) diff --git a/muranoclient/common/utils.py b/muranoclient/common/utils.py index 739fa034..34abde6c 100644 --- a/muranoclient/common/utils.py +++ b/muranoclient/common/utils.py @@ -33,7 +33,7 @@ import zipfile from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import encodeutils -from oslo_utils import importutils + import prettytable import requests import six @@ -165,13 +165,6 @@ def env(*vars, **kwargs): return kwargs.get('default', '') -def import_versioned_module(version, submodule=None): - module = 'muranoclient.v%s' % version - if submodule: - module = '.'.join((module, submodule)) - return importutils.import_module(module) - - def exit(msg=''): if msg: print(encodeutils.safe_encode(msg), file=sys.stderr) diff --git a/muranoclient/shell.py b/muranoclient/shell.py index 5ae030f3..720f74b8 100644 --- a/muranoclient/shell.py +++ b/muranoclient/shell.py @@ -31,6 +31,7 @@ from oslo_log import handlers from oslo_log import log as logging from oslo_log import versionutils from oslo_utils import encodeutils +from oslo_utils import importutils import six import six.moves.urllib.parse as urlparse @@ -194,7 +195,8 @@ class MuranoShell(object): self.subcommands = {} subparsers = parser.add_subparsers(metavar='') - submodule = utils.import_versioned_module(version, 'shell') + submodule = importutils.import_versioned_module('muranoclient', + version, 'shell') self._find_actions(subparsers, submodule) self._find_actions(subparsers, self)