0bf1965057
Listens to oslo_messaging for database updates from octavia. When neutron-lbaas is being used with octavia this queing system will be used to so that health check and status updates from octavia are sent to neutron-lbaas so that neutron updates its database in sync with octavia. See CR https://review.openstack.org/218735 for details on the octavia side. This event handler can actually be used for other drivers as long, but for now its only used for octavia. Co-Authored-By: Brandon Logan <brandon.logan@rackspace.com> Change-Id: I4694d9830d37c6432ff64497396be120dda31501
113 lines
3.8 KiB
Python
113 lines
3.8 KiB
Python
# Copyright 2016 Rackspace
|
|
#
|
|
# 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 neutron_lbaas._i18n import _LI
|
|
from oslo_config import cfg
|
|
from oslo_log import log as logging
|
|
import oslo_messaging as messaging
|
|
from oslo_service import service
|
|
|
|
|
|
oslo_messaging_opts = [
|
|
cfg.StrOpt('event_stream_topic',
|
|
default='neutron_lbaas_event',
|
|
help=_('topic name for receiving events from a queue'))
|
|
]
|
|
|
|
cfg.CONF.register_opts(oslo_messaging_opts, group='oslo_messaging')
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
class InfoContainer(object):
|
|
@staticmethod
|
|
def from_dict(dict_obj):
|
|
return InfoContainer(dict_obj['info_type'],
|
|
dict_obj['info_id'],
|
|
dict_obj['info_payload'])
|
|
|
|
def __init__(self, info_type, info_id, info_payload):
|
|
self.info_type = info_type
|
|
self.info_id = info_id
|
|
self.info_payload = info_payload
|
|
|
|
def to_dict(self):
|
|
return {'info_type': self.info_type,
|
|
'info_id': self.info_id,
|
|
'info_payload': self.info_payload}
|
|
|
|
def __eq__(self, other):
|
|
if not isinstance(other, InfoContainer):
|
|
return False
|
|
if self.info_type != other.info_type:
|
|
return False
|
|
if self.info_id != other.info_id:
|
|
return False
|
|
if self.info_payload != other.info_payload:
|
|
return False
|
|
return True
|
|
|
|
def __ne__(self, other):
|
|
return not self == other
|
|
|
|
|
|
class ConsumerEndPoint(object):
|
|
target = messaging.Target(namespace="control", version='1.0')
|
|
|
|
def __init__(self, driver):
|
|
self.driver = driver
|
|
|
|
def update_info(self, ctx, container):
|
|
LOG.debug("Received event from stream %s", container)
|
|
container_inst = InfoContainer.from_dict(container)
|
|
self.driver.handle_streamed_event(container_inst)
|
|
|
|
|
|
class OctaviaConsumer(service.Service):
|
|
def __init__(self, driver, **kwargs):
|
|
super(OctaviaConsumer, self).__init__(**kwargs)
|
|
topic = cfg.CONF.oslo_messaging.event_stream_topic
|
|
server = cfg.CONF.host
|
|
self.driver = driver
|
|
self.transport = messaging.get_transport(cfg.CONF)
|
|
self.target = messaging.Target(topic=topic, server=server,
|
|
exchange="common", fanout=False)
|
|
self.endpoints = [ConsumerEndPoint(self.driver)]
|
|
self.server = None
|
|
|
|
def start(self):
|
|
super(OctaviaConsumer, self).start()
|
|
LOG.info(_LI("Starting octavia consumer..."))
|
|
self.server = messaging.get_rpc_server(self.transport, self.target,
|
|
self.endpoints,
|
|
executor='eventlet')
|
|
self.server.start()
|
|
|
|
def stop(self, graceful=False):
|
|
if self.server:
|
|
LOG.info(_LI('Stopping consumer...'))
|
|
self.server.stop()
|
|
if graceful:
|
|
LOG.info(
|
|
_LI('Consumer successfully stopped. Waiting for final '
|
|
'messages to be processed...'))
|
|
self.server.wait()
|
|
super(OctaviaConsumer, self).stop(graceful=graceful)
|
|
|
|
def reset(self):
|
|
if self.server:
|
|
self.server.reset()
|
|
super(OctaviaConsumer, self).reset()
|