Merge "Refactor the base monitoring driver"
This commit is contained in:
commit
061144c6c8
|
@ -224,18 +224,9 @@
|
|||
# Driver used to get a status updates of compute nodes (string value)
|
||||
#driver = freezer_dr.monitors.drivers.default.driver.StandardDriver
|
||||
|
||||
# username to be used to initialize the monitoring driver (string value)
|
||||
#username = <None>
|
||||
|
||||
# Password to be used for initializing monitoring driver (string value)
|
||||
#password = <None>
|
||||
|
||||
# Monitoring system API endpoint (string value)
|
||||
#endpoint = <None>
|
||||
|
||||
# List of kwargs if you want to pass it to initialize the monitoring driver.
|
||||
# should be provided in key:value format (dict value)
|
||||
#kwargs =
|
||||
# configuration section name. This should contain your monitoring specific
|
||||
# configuration options. (string value)
|
||||
#backend_name = <None>
|
||||
|
||||
|
||||
[notifiers]
|
||||
|
|
|
@ -30,17 +30,9 @@ _MONITORS = [
|
|||
default='freezer_dr.monitors.drivers.default.driver.'
|
||||
'StandardDriver',
|
||||
help='Driver used to get a status updates of compute nodes'),
|
||||
cfg.StrOpt('username',
|
||||
help='username to be used to initialize the monitoring driver'),
|
||||
cfg.StrOpt('password',
|
||||
help='Password to be used for initializing monitoring driver'),
|
||||
cfg.StrOpt('endpoint',
|
||||
help='Monitoring system API endpoint'),
|
||||
cfg.DictOpt('kwargs',
|
||||
default={},
|
||||
help='List of kwargs if you want to pass it to initialize'
|
||||
' the monitoring driver. should be provided in key:value '
|
||||
'format')
|
||||
cfg.StrOpt('backend_name',
|
||||
help="configuration section name. This should contain your "
|
||||
"monitoring specific configuration options.")
|
||||
]
|
||||
|
||||
_COMMON = [
|
||||
|
|
|
@ -15,6 +15,10 @@
|
|||
import abc
|
||||
import six
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class MonitorBaseDriver(object):
|
||||
|
@ -22,22 +26,19 @@ class MonitorBaseDriver(object):
|
|||
Abstract class that all monitoring plugins should implement to have a
|
||||
unified interface and as many plugins as we want...
|
||||
"""
|
||||
_OPTS = []
|
||||
|
||||
def __init__(self, username, password, endpoint, **kwargs):
|
||||
def __init__(self, backend_name):
|
||||
"""
|
||||
Initializing the driver. Any monitoring system requires the following
|
||||
parameters to call it's api. All these parameters can be passed from the
|
||||
configuration file in /etc/freezer/dr.conf
|
||||
:param username: Username
|
||||
:param password: Password
|
||||
:param endpoint: API URL
|
||||
:param kwargs: any additional parameters can be passed using this config
|
||||
option.
|
||||
:param backend_name: Name of section in the configuration file that
|
||||
contains your driver initialization details; like username, password,
|
||||
endpoint and so on. Variables in this section depends on your driver
|
||||
"""
|
||||
self.username = username
|
||||
self.password = password
|
||||
self.endpoint = endpoint
|
||||
self.kwargs = kwargs
|
||||
CONF.register_opts(self._OPTS, group=backend_name)
|
||||
self.conf = CONF.get(backend_name)
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_data(self):
|
||||
|
|
|
@ -23,12 +23,10 @@ class MonitorManager(object):
|
|||
|
||||
def __init__(self):
|
||||
monitor = CONF.get('monitoring')
|
||||
backend_name = monitor['backend_name']
|
||||
self.driver = importutils.import_object(
|
||||
monitor.get('driver'),
|
||||
monitor.get('username'),
|
||||
monitor.get('password'),
|
||||
monitor.get('endpoint'),
|
||||
**monitor.get('kwargs')
|
||||
monitor.driver,
|
||||
backend_name=backend_name
|
||||
)
|
||||
driver_info = self.driver.get_info()
|
||||
LOG.info('Initializing driver %s with version %s found in %s' %
|
||||
|
|
|
@ -26,17 +26,35 @@ LOG = log.getLogger(__name__)
|
|||
|
||||
|
||||
class StandardDriver(MonitorBaseDriver):
|
||||
_OPTS = [
|
||||
cfg.StrOpt('username',
|
||||
help='username to be used to initialize the default '
|
||||
'monitoring driver'),
|
||||
cfg.StrOpt('password',
|
||||
help='Password to be used for initializing the default '
|
||||
'monitoring driver'),
|
||||
cfg.StrOpt('endpoint',
|
||||
help='Monitoring system API endpoint'),
|
||||
cfg.DictOpt('kwargs',
|
||||
default={},
|
||||
help='List of kwargs if you want to pass it to initialize'
|
||||
' the monitoring driver. should be provided in'
|
||||
' key:value format'),
|
||||
]
|
||||
|
||||
def __init__(self, username, password, endpoint, **kwargs):
|
||||
super(StandardDriver, self).__init__(username, password, endpoint, **kwargs)
|
||||
def __init__(self, backend_name):
|
||||
super(StandardDriver, self).__init__(backend_name=backend_name)
|
||||
self.endpoint = self.conf.endpoint
|
||||
client = OSClient(
|
||||
authurl=endpoint,
|
||||
username=username,
|
||||
password=password,
|
||||
**kwargs
|
||||
authurl=self.conf.endpoint,
|
||||
username=self.conf.username,
|
||||
password=self.conf.password,
|
||||
**self.conf.kwargs
|
||||
)
|
||||
LOG.info("OSClient:: username: %s, password: %s, endpoint: %s, kwargs:"
|
||||
" %s" % (username, '****', endpoint, kwargs))
|
||||
" %s" % (self.conf.username, '****', self.conf.endpoint,
|
||||
self.conf.kwargs)
|
||||
)
|
||||
self.client = client
|
||||
|
||||
def get_data(self):
|
||||
|
|
Loading…
Reference in New Issue