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
This commit is contained in:
LiuNanke 2016-11-08 14:03:25 +08:00 committed by Kirill Zaitsev
parent 2eae10c17e
commit 6776dd66ac
3 changed files with 7 additions and 11 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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='<subcommand>')
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)