Files
astara/astara/health.py
Mark McClain 59e25b504d Make Astara Newton compatible
This change makes Astara compatible with Newton. This change adds support
for Neutron agent reporting and service providers to work with new L3
drivers.  Included in this change is a temporary filed called newton_fix.py.
This file will be removed in follow-up change after changes are migrated to
astara-neutron.

Change-Id: I5843e84e36af2e46de5b8420ca5749033c26ee69
2016-10-04 10:49:09 -04:00

88 lines
2.0 KiB
Python

# Copyright 2014 DreamHost, LLC
#
# Author: DreamHost, LLC
#
# 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.
"""Periodic health check code.
"""
import threading
import time
from oslo_config import cfg
from astara import event
from astara.api import neutron
from oslo_log import log as logging
LOG = logging.getLogger(__name__)
CONF = cfg.CONF
HEALTH_INSPECTOR_OPTS = [
cfg.IntOpt('health_check_period',
default=60,
help='seconds between health checks'),
]
CONF.register_opts(HEALTH_INSPECTOR_OPTS)
def _health_inspector(scheduler):
"""Runs in the thread.
"""
period = CONF.health_check_period
while True:
time.sleep(period)
LOG.debug('waking up')
r = event.Resource(
id='*',
tenant_id='*',
driver='*',
)
e = event.Event(
resource=r,
crud=event.POLL,
body={},
)
scheduler.handle_message('*', e)
def start_inspector(period, scheduler):
"""Start a health check thread.
"""
t = threading.Thread(
target=_health_inspector,
args=(scheduler,),
name='HealthInspector',
)
t.setDaemon(True)
t.start()
return t
def start_reporter():
"""Start a agent report thread.
"""
reporter = neutron.NeutronAgentReporter()
t = threading.Thread(
target=reporter.report_forever,
args=(),
name='AgentReporter',
)
t.setDaemon(True)
t.start()
return t