diff --git a/cloudbaseinit/metadata/factory.py b/cloudbaseinit/metadata/factory.py index 3f39d0de..96b3e1b9 100644 --- a/cloudbaseinit/metadata/factory.py +++ b/cloudbaseinit/metadata/factory.py @@ -16,7 +16,7 @@ from cloudbaseinit.openstack.common import cfg from cloudbaseinit.openstack.common import log as logging -from cloudbaseinit.utils import * +from cloudbaseinit.utils import classloader opts = [ cfg.ListOpt('metadata_services', default=[ @@ -38,9 +38,9 @@ LOG = logging.getLogger(__name__) class MetadataServiceFactory(object): def get_metadata_service(self): # Return the first service that loads correctly - utils = Utils() + cl = classloader.ClassLoader() for class_path in CONF.metadata_services: - service = utils.load_class(class_path)() + service = cl.load_class(class_path)() try: if service.load(): return service diff --git a/cloudbaseinit/osutils/factory.py b/cloudbaseinit/osutils/factory.py index d97a3e44..a5c84149 100644 --- a/cloudbaseinit/osutils/factory.py +++ b/cloudbaseinit/osutils/factory.py @@ -16,7 +16,7 @@ import os -from cloudbaseinit.utils import * +from cloudbaseinit.utils import classloader class OSUtilsFactory(object): def get_os_utils(self): @@ -25,5 +25,5 @@ class OSUtilsFactory(object): 'posix' : 'cloudbaseinit.osutils.posix.PosixUtils' } - utils = Utils() - return utils.load_class(osutils_class_paths[os.name])() + cl = classloader.ClassLoader() + return cl.load_class(osutils_class_paths[os.name])() diff --git a/cloudbaseinit/plugins/factory.py b/cloudbaseinit/plugins/factory.py index 27b35651..a588acf6 100644 --- a/cloudbaseinit/plugins/factory.py +++ b/cloudbaseinit/plugins/factory.py @@ -15,7 +15,7 @@ # under the License. from cloudbaseinit.openstack.common import cfg -from cloudbaseinit.utils import * +from cloudbaseinit.utils import classloader opts = [ cfg.ListOpt('plugins', default=[ @@ -37,7 +37,7 @@ CONF.register_opts(opts) class PluginFactory(object): def load_plugins(self): plugins = [] - utils = Utils() + cl = classloader.ClassLoader() for class_path in CONF.plugins: - plugins.append(utils.load_class(class_path)()) + plugins.append(cl.load_class(class_path)()) return plugins diff --git a/cloudbaseinit/utils.py b/cloudbaseinit/utils.py deleted file mode 100644 index f8fcd2db..00000000 --- a/cloudbaseinit/utils.py +++ /dev/null @@ -1,27 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2012 Cloudbase Solutions Srl -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from cloudbaseinit.openstack.common import log as logging - -LOG = logging.getLogger(__name__) - - -class Utils(object): - def load_class(self, class_path): - LOG.debug('Loading class \'%s\'' % class_path) - parts = class_path.rsplit('.', 1) - module = __import__(parts[0], fromlist=parts[1]) - return getattr(module, parts[1])