use importutils in monitors.py to avoid cyclic imports
* Remove import statements from the method level. * Use importutils to import COE monitor classes. Change-Id: Ie343def2c97f96d6a269ee6030a83b4eaf879c1a Closes-Bug: #1513722
This commit is contained in:
parent
61c9017335
commit
9a2872dea0
|
@ -17,6 +17,7 @@ import abc
|
|||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
from oslo_utils import importutils
|
||||
import six
|
||||
|
||||
from magnum import objects
|
||||
|
@ -33,6 +34,11 @@ CONF.import_opt('default_timeout',
|
|||
'magnum.conductor.handlers.docker_conductor',
|
||||
group='docker')
|
||||
|
||||
COE_CLASS_PATH = {
|
||||
bay_type.SWARM: 'magnum.conductor.swarm_monitor.SwarmMonitor',
|
||||
bay_type.KUBERNETES: 'magnum.conductor.k8s_monitor.K8sMonitor'
|
||||
}
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class MonitorBase(object):
|
||||
|
@ -63,12 +69,9 @@ class MonitorBase(object):
|
|||
|
||||
def create_monitor(context, bay):
|
||||
baymodel = objects.BayModel.get_by_uuid(context, bay.baymodel_id)
|
||||
if baymodel.coe == bay_type.SWARM:
|
||||
from magnum.conductor.swarm_monitor import SwarmMonitor
|
||||
return SwarmMonitor(context, bay)
|
||||
elif baymodel.coe == bay_type.KUBERNETES:
|
||||
from magnum.conductor.k8s_monitor import K8sMonitor
|
||||
return K8sMonitor(context, bay)
|
||||
if baymodel.coe in COE_CLASS_PATH:
|
||||
coe_cls = importutils.import_class(COE_CLASS_PATH[baymodel.coe])
|
||||
return coe_cls(context, bay)
|
||||
|
||||
# TODO(hongbin): add support for other bay types
|
||||
LOG.debug("Cannot create monitor with bay type '%s'" % baymodel.coe)
|
||||
|
|
Loading…
Reference in New Issue