diff options
| author | Russell Bryant <rbryant@redhat.com> | 2012-07-02 11:33:09 -0400 |
|---|---|---|
| committer | Russell Bryant <rbryant@redhat.com> | 2012-07-02 11:33:09 -0400 |
| commit | 2633156659bd767b5b206fba9fbf68d2dcb62c51 (patch) | |
| tree | 082320e0c1373dac035fe0794b6ca07e378510b5 /nova/openstack | |
| parent | c1306968603c206a6cb227dfe1225dc230c51031 (diff) | |
| download | nova-2633156659bd767b5b206fba9fbf68d2dcb62c51.tar.gz nova-2633156659bd767b5b206fba9fbf68d2dcb62c51.tar.xz nova-2633156659bd767b5b206fba9fbf68d2dcb62c51.zip | |
Sync latest importutils from openstack-common.
This patch pulls in the latest version of importutils from
openstack-common. It includes a formatting change and one new function:
import_object_ns().
Change-Id: Ifc1533fe1e33a447e4c501d759a6c838133d1063
Diffstat (limited to 'nova/openstack')
| -rw-r--r-- | nova/openstack/common/importutils.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/nova/openstack/common/importutils.py b/nova/openstack/common/importutils.py index 7654af5b9..67d94ad5f 100644 --- a/nova/openstack/common/importutils.py +++ b/nova/openstack/common/importutils.py @@ -30,7 +30,7 @@ def import_class(import_str): return getattr(sys.modules[mod_str], class_str) except (ImportError, ValueError, AttributeError), exc: raise ImportError('Class %s cannot be found (%s)' % - (class_str, str(exc))) + (class_str, str(exc))) def import_object(import_str, *args, **kwargs): @@ -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) |
