summaryrefslogtreecommitdiffstats
path: root/nova/utils.py
diff options
context:
space:
mode:
authorRussell Bryant <rbryant@redhat.com>2012-04-27 14:14:18 -0400
committerRussell Bryant <rbryant@redhat.com>2012-04-28 23:33:15 -0400
commit7593a6948c43c907893bfba5fff65a6b5acf5c2d (patch)
tree24872d7fb65dfb87b197c5a28077e0464e2d2542 /nova/utils.py
parent76bb37e049818cbde4ca890566d01e85439ce517 (diff)
Use openstack.common.importutils.
Use import_class(), import_object(), and import_module() from openstack-common's importutils module. The equivalent functions have been removed from nova.utils. A few modules had import order cleaned up in passing, as well. My initial motivation for this was to remove some more usage of nova bits from nova.rpc as another step towards being able to move nova.rpc import openstack-common. Since I was pulling importutils into nova, I went ahead and converted the whole thing. Change-Id: I7c7786cf0001bcd06db52b9a99ff4284a3f6c6fa
Diffstat (limited to 'nova/utils.py')
-rw-r--r--nova/utils.py28
1 files changed, 4 insertions, 24 deletions
diff --git a/nova/utils.py b/nova/utils.py
index 309863bd5..71e734e8b 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -57,6 +57,7 @@ from nova import exception
from nova import flags
from nova import log as logging
from nova.openstack.common import cfg
+from nova.openstack.common import importutils
LOG = logging.getLogger(__name__)
@@ -69,27 +70,6 @@ FLAGS.register_opt(
help='Whether to disable inter-process locks'))
-def import_class(import_str):
- """Returns a class from a string including module and class."""
- mod_str, _sep, class_str = import_str.rpartition('.')
- try:
- __import__(mod_str)
- return getattr(sys.modules[mod_str], class_str)
- except (ImportError, ValueError, AttributeError), exc:
- LOG.debug(_('Inner Exception: %s'), exc)
- raise exception.ClassNotFound(class_name=class_str, exception=exc)
-
-
-def import_object(import_str):
- """Returns an object including a module or module and class."""
- try:
- __import__(import_str)
- return sys.modules[import_str]
- except ImportError:
- cls = import_class(import_str)
- return cls()
-
-
def find_config(config_path):
"""Find a configuration file using the given hint.
@@ -1229,20 +1209,20 @@ def monkey_patch():
for module_and_decorator in FLAGS.monkey_patch_modules:
module, decorator_name = module_and_decorator.split(':')
# import decorator function
- decorator = import_class(decorator_name)
+ decorator = importutils.import_class(decorator_name)
__import__(module)
# Retrieve module information using pyclbr
module_data = pyclbr.readmodule_ex(module)
for key in module_data.keys():
# set the decorator for the class methods
if isinstance(module_data[key], pyclbr.Class):
- clz = import_class("%s.%s" % (module, key))
+ clz = importutils.import_class("%s.%s" % (module, key))
for method, func in inspect.getmembers(clz, inspect.ismethod):
setattr(clz, method,
decorator("%s.%s.%s" % (module, key, method), func))
# set the decorator for the function
if isinstance(module_data[key], pyclbr.Function):
- func = import_class("%s.%s" % (module, key))
+ func = importutils.import_class("%s.%s" % (module, key))
setattr(sys.modules[module], key,
decorator("%s.%s" % (module, key), func))