summaryrefslogtreecommitdiffstats
path: root/openstack/common/importutils.py
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-06-18 21:48:23 +0000
committerGerrit Code Review <review@openstack.org>2012-06-18 21:48:23 +0000
commit2204ca4d4bc94efcfb4d402e3c89e1c20b312021 (patch)
tree9902bf43e247d0a9f7484c425cb2cda9047b360e /openstack/common/importutils.py
parentf5ca941543847e62426cf1166a68053d711d4e32 (diff)
parent1fb23610eb47e4b6d181901fff59b4b30ac2aaad (diff)
downloadoslo-2204ca4d4bc94efcfb4d402e3c89e1c20b312021.tar.gz
oslo-2204ca4d4bc94efcfb4d402e3c89e1c20b312021.tar.xz
oslo-2204ca4d4bc94efcfb4d402e3c89e1c20b312021.zip
Merge "add import_object_ns function"
Diffstat (limited to 'openstack/common/importutils.py')
-rw-r--r--openstack/common/importutils.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/openstack/common/importutils.py b/openstack/common/importutils.py
index b507d22..67d94ad 100644
--- a/openstack/common/importutils.py
+++ b/openstack/common/importutils.py
@@ -38,6 +38,19 @@ def import_object(import_str, *args, **kwargs):
return import_class(import_str)(*args, **kwargs)
+def import_object_ns(name_space, import_str, *args, **kwargs):
+ """
+ Import a class and return an instance of it, first by trying
+ to find the class in a default namespace, then failing back to
+ a full path if not found in the default namespace.
+ """
+ import_value = "%s.%s" % (name_space, import_str)
+ try:
+ return import_class(import_value)(*args, **kwargs)
+ except ImportError:
+ return import_class(import_str)(*args, **kwargs)
+
+
def import_module(import_str):
"""Import a module."""
__import__(import_str)