Utils refactoring

This commit is contained in:
Alessandro Pilotti 2013-02-03 22:37:28 +02:00
parent 61282d4adc
commit 4657ee3468
4 changed files with 9 additions and 36 deletions

View File

@ -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

View File

@ -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])()

View File

@ -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

View File

@ -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])