Merge "Enabled config parameters to plugins"

This commit is contained in:
Jenkins
2016-05-30 09:40:30 +00:00
committed by Gerrit Code Review
22 changed files with 453 additions and 129 deletions

View File

@@ -41,20 +41,22 @@ import six
from watcher._i18n import _
from watcher.common import clients
from watcher.common.loader import loadable
from watcher.decision_engine.solution import default
from watcher.decision_engine.strategy.common import level
@six.add_metaclass(abc.ABCMeta)
class BaseStrategy(object):
class BaseStrategy(loadable.Loadable):
"""A base class for all the strategies
A Strategy is an algorithm implementation which is able to find a
Solution for a given Goal.
"""
def __init__(self, osc=None):
def __init__(self, config, osc=None):
""":param osc: an OpenStackClients instance"""
super(BaseStrategy, self).__init__(config)
self._name = self.get_name()
self._display_name = self.get_display_name()
# default strategy level
@@ -104,6 +106,15 @@ class BaseStrategy(object):
# other services
raise NotImplementedError()
@classmethod
def get_config_opts(cls):
"""Defines the configuration options to be associated to this loadable
:return: A list of configuration options relative to this Loadable
:rtype: list of :class:`oslo_config.cfg.Opt` instances
"""
return []
@abc.abstractmethod
def execute(self, original_model):
"""Execute a strategy

View File

@@ -71,16 +71,14 @@ class BasicConsolidation(base.ServerConsolidationBaseStrategy):
MIGRATION = "migrate"
CHANGE_NOVA_SERVICE_STATE = "change_nova_service_state"
def __init__(self, osc=None):
def __init__(self, config=None, osc=None):
"""Basic offline Consolidation using live migration
:param name: The name of the strategy (Default: "basic")
:param description: The description of the strategy
(Default: "Basic offline consolidation")
:param osc: An :py:class:`~watcher.common.clients.OpenStackClients`
instance
:param config: A mapping containing the configuration of this strategy
:type config: dict
:param osc: :py:class:`~.OpenStackClients` instance
"""
super(BasicConsolidation, self).__init__(osc)
super(BasicConsolidation, self).__init__(config, osc)
# set default value for the number of released nodes
self.number_of_released_nodes = 0

View File

@@ -48,8 +48,14 @@ class DummyStrategy(base.DummyBaseStrategy):
NOP = "nop"
SLEEP = "sleep"
def __init__(self, osc=None):
super(DummyStrategy, self).__init__(osc)
def __init__(self, config=None, osc=None):
"""Dummy Strategy implemented for demo and testing purposes
:param config: A mapping containing the configuration of this strategy
:type config: dict
:param osc: :py:class:`~.OpenStackClients` instance
"""
super(DummyStrategy, self).__init__(config, osc)
def execute(self, original_model):
LOG.debug("Executing Dummy strategy")

View File

@@ -78,14 +78,15 @@ class OutletTempControl(base.ThermalOptimizationBaseStrategy):
MIGRATION = "migrate"
def __init__(self, osc=None):
def __init__(self, config=None, osc=None):
"""Outlet temperature control using live migration
:param name: the name of the strategy
:param description: a description of the strategy
:param osc: an OpenStackClients object
:param config: A mapping containing the configuration of this strategy
:type config: dict
:param osc: an OpenStackClients object, defaults to None
:type osc: :py:class:`~.OpenStackClients` instance, optional
"""
super(OutletTempControl, self).__init__(osc)
super(OutletTempControl, self).__init__(config, osc)
# the migration plan will be triggered when the outlet temperature
# reaches threshold
# TODO(zhenzanz): Threshold should be configurable for each audit

View File

@@ -84,8 +84,8 @@ class VMWorkloadConsolidation(base.ServerConsolidationBaseStrategy):
https://github.com/openstack/watcher-specs/blob/master/specs/mitaka/implemented/zhaw-load-consolidation.rst
""" # noqa
def __init__(self, osc=None):
super(VMWorkloadConsolidation, self).__init__(osc)
def __init__(self, config=None, osc=None):
super(VMWorkloadConsolidation, self).__init__(config, osc)
self._ceilometer = None
self.number_of_migrations = 0
self.number_of_released_hypervisors = 0