Add implement of loading hostmonitor driver

This pathc adds implementation of loading hostmonitor driver
using stevedore.

Change-Id: I29666484b35cb5f295b0ab183e9bb3cbbcc28d21
Implements: bp pythonize-host-and-process-monitor
This commit is contained in:
Kengo Takahara 2016-12-26 19:07:59 +09:00 committed by takahara.kengo
parent 6a6cc0a892
commit 191724d60d
7 changed files with 133 additions and 1 deletions

View File

@ -15,6 +15,7 @@ from oslo_config import cfg
from masakarimonitors.conf import api
from masakarimonitors.conf import base
from masakarimonitors.conf import host
from masakarimonitors.conf import instance
from masakarimonitors.conf import process
from masakarimonitors.conf import service
@ -23,6 +24,7 @@ CONF = cfg.CONF
api.register_opts(CONF)
base.register_opts(CONF)
host.register_opts(CONF)
instance.register_opts(CONF)
process.register_opts(CONF)
service.register_opts(CONF)

View File

@ -0,0 +1,30 @@
# Copyright(c) 2016 Nippon Telegraph and Telephone Corporation
#
# 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 oslo_config import cfg
monitor_host_opts = [
cfg.StrOpt('monitoring_driver',
default='default',
help='Driver that hostmonitor uses for monitoring hosts.'),
]
def register_opts(conf):
conf.register_opts(monitor_host_opts, group='host')
def list_opts():
return {
'host': monitor_host_opts
}

View File

@ -12,11 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
from stevedore import driver
from oslo_log import log as oslo_logging
import masakarimonitors.conf
from masakarimonitors.i18n import _LE
from masakarimonitors import manager
LOG = oslo_logging.getLogger(__name__)
CONF = masakarimonitors.conf.CONF
class HostmonitorManager(manager.Manager):
@ -25,8 +31,38 @@ class HostmonitorManager(manager.Manager):
def __init__(self, *args, **kwargs):
super(HostmonitorManager, self).__init__(
service_name="hostmonitor", *args, **kwargs)
self.driver = None
def init_host(self):
"""Initialization for hostmonitor."""
try:
# Determine dynamic load driver from configuration.
driver_name = CONF.host.monitoring_driver
# Load the driver to global.
self.driver = driver.DriverManager(
namespace='hostmonitor.driver',
name=driver_name,
invoke_on_load=True,
invoke_args=(),
)
except Exception as e:
LOG.exception(
_LE("Exception caught during initializing hostmonitor: %s"),
e)
os._exit(1)
def stop(self):
self.driver.driver.stop()
def main(self):
"""Main method."""
pass
try:
# Call the host monitoring driver.
self.driver.driver.monitor_hosts()
except Exception as e:
LOG.exception(_LE("Exception caught: %s"), e)
return

View File

@ -0,0 +1,32 @@
# Copyright(c) 2016 Nippon Telegraph and Telephone Corporation
#
# 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.
import abc
import six
@six.add_metaclass(abc.ABCMeta)
class DriverBase(object):
"""Driver Base class.
This class is base of monitoring hosts.
"""
def __init__(self):
pass
@abc.abstractmethod
def monitor_hosts(self):
"""Must override monitor_hosts method."""
pass

View File

@ -0,0 +1,28 @@
# Copyright(c) 2016 Nippon Telegraph and Telephone Corporation
#
# 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.
import masakarimonitors.hostmonitor.host_handler.driver as driver
class HandleHost(driver.DriverBase):
"""Handle hosts.
This class handles the host status.
"""
def __init__(self):
super(HandleHost, self).__init__()
def monitor_hosts(self):
pass

View File

@ -46,6 +46,10 @@ console_scripts =
masakari-processmonitor = masakarimonitors.cmd.processmonitor:main
masakari-hostmonitor = masakarimonitors.cmd.hostmonitor:main
hostmonitor.driver =
simple = masakarimonitors.hostmonitor.host_handler.handle_host:HandleHost
default = masakarimonitors.hostmonitor.host_handler.handle_host:HandleHost
[build_sphinx]
source-dir = doc/source
build-dir = doc/build