Support import modules from barbicanclient.client module

Before refactor patch, modules could be imported either from
barbicanclient.<module> or barbicanclient.client.<module>, octavia
is using both methods. We need to support that.

Change-Id: Ib5b7c2ae50d30e85685c20cfabc188f46c0c947b
Closes-bug: #1706841
This commit is contained in:
Jeremy Liu 2017-08-01 15:47:48 +08:00
parent 49505b9aec
commit 714fce2228
1 changed files with 32 additions and 0 deletions

View File

@ -13,8 +13,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import importlib
import logging
import os
import sys
import warnings
from keystoneauth1 import adapter
from keystoneauth1 import session as ks_session
@ -191,3 +194,32 @@ def env(*vars, **kwargs):
if value:
return value
return kwargs.get('default', '')
class _LazyImporter(object):
def __init__(self, module):
self._module = module
def __getattr__(self, name):
# This is only called until the import has been done.
lazy_submodules = [
'acls',
'cas',
'containers',
'orders',
'secrets',
]
if name in lazy_submodules:
warnings.warn("The %s module is moved to barbicanclient/v1 "
"directory, direct import of "
"barbicanclient.client.%s "
"will be deprecated. Please import "
"barbicanclient.v1.%s instead."
% (name, name, name))
return importlib.import_module('barbicanclient.v1.%s' % name)
# Return module attributes like __all__ etc.
return getattr(self._module, name)
sys.modules[__name__] = _LazyImporter(sys.modules[__name__])