Merge "use importutils in monitors.py to avoid cyclic imports"
This commit is contained in:
commit
6bf2bcad88
|
@ -17,6 +17,7 @@ import abc
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
from oslo_utils import importutils
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from magnum import objects
|
from magnum import objects
|
||||||
|
@ -33,6 +34,11 @@ CONF.import_opt('default_timeout',
|
||||||
'magnum.conductor.handlers.docker_conductor',
|
'magnum.conductor.handlers.docker_conductor',
|
||||||
group='docker')
|
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)
|
@six.add_metaclass(abc.ABCMeta)
|
||||||
class MonitorBase(object):
|
class MonitorBase(object):
|
||||||
|
@ -63,12 +69,9 @@ class MonitorBase(object):
|
||||||
|
|
||||||
def create_monitor(context, bay):
|
def create_monitor(context, bay):
|
||||||
baymodel = objects.BayModel.get_by_uuid(context, bay.baymodel_id)
|
baymodel = objects.BayModel.get_by_uuid(context, bay.baymodel_id)
|
||||||
if baymodel.coe == bay_type.SWARM:
|
if baymodel.coe in COE_CLASS_PATH:
|
||||||
from magnum.conductor.swarm_monitor import SwarmMonitor
|
coe_cls = importutils.import_class(COE_CLASS_PATH[baymodel.coe])
|
||||||
return SwarmMonitor(context, bay)
|
return coe_cls(context, bay)
|
||||||
elif baymodel.coe == bay_type.KUBERNETES:
|
|
||||||
from magnum.conductor.k8s_monitor import K8sMonitor
|
|
||||||
return K8sMonitor(context, bay)
|
|
||||||
|
|
||||||
# TODO(hongbin): add support for other bay types
|
# TODO(hongbin): add support for other bay types
|
||||||
LOG.debug("Cannot create monitor with bay type '%s'" % baymodel.coe)
|
LOG.debug("Cannot create monitor with bay type '%s'" % baymodel.coe)
|
||||||
|
|
Loading…
Reference in New Issue