summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Liu <liujiong@gohighsec.com>2017-08-01 15:47:48 +0800
committerJeremy Liu <liujiong@gohighsec.com>2017-08-01 15:47:48 +0800
commit714fce222816ad3348d4ba4c3baaa721308158e2 (patch)
treeb5d1ba46e5d3b29b07afa9bf97db174b312652fa
parent49505b9aec05ec42e0a809ec51935c2324d5f3a6 (diff)
downloadpython-barbicanclient-714fce222816ad3348d4ba4c3baaa721308158e2.tar.gz
Support import modules from barbicanclient.client module4.5.2
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
-rw-r--r--barbicanclient/client.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/barbicanclient/client.py b/barbicanclient/client.py
index c715315..4e1d058 100644
--- a/barbicanclient/client.py
+++ b/barbicanclient/client.py
@@ -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__])