Instead of each individual driver setting up the RPC server (and setting the _rpc_backend attribute on the TrunkPlugin) we now check in the TrunkPlugin if any driver requires the RPC backend to be started. Additionally, we only start it when this is requested by Neutron via start_rpc_listeners(). This is required when running neutron-server and neutron-rpc-server separately to run RPC only in neutron-rpc-server. As we still need the notifiers of ServerSideRpcBackend to be created/started, we separate TrunkSkeleton (which is the RPC server implementation) and ServerSideRpcBackend (which is essentially only a notifier). In case RPC is required by a driver, we always start the notifier, but the RPC server only when requested via start_rpc_listeners(). Change-Id: I2c6362b3320e534a6e65bd7701b5ac2feca42a49 Closes-Bug: #2015275 Closes-Bug: #2062009
68 lines
2.6 KiB
Python
68 lines
2.6 KiB
Python
# Copyright 2016 Hewlett Packard Enterprise Development LP
|
|
#
|
|
# 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_lib.callbacks import events
|
|
from neutron_lib.callbacks import registry
|
|
from neutron_lib.callbacks import resources
|
|
from oslo_log import log as logging
|
|
|
|
from neutron.services.trunk.rpc import server
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
@registry.has_registry_receivers
|
|
class ServerSideRpcBackend(object):
|
|
"""The Neutron Server RPC backend."""
|
|
|
|
def __init__(self):
|
|
"""Initialize an RPC backend for the Neutron Server."""
|
|
self._stub = server.TrunkStub()
|
|
|
|
LOG.debug("RPC notifier initialized for trunk plugin")
|
|
|
|
for event_type in (events.AFTER_CREATE, events.AFTER_DELETE):
|
|
registry.subscribe(self.process_event,
|
|
resources.TRUNK, event_type)
|
|
registry.subscribe(self.process_event,
|
|
resources.SUBPORTS, event_type)
|
|
|
|
# Set up listeners to trunk events: they dispatch RPC messages
|
|
# to agents as needed. These are designed to work with any
|
|
# agent-based driver that may integrate with the trunk service
|
|
# plugin, e.g. linux bridge or ovs.
|
|
|
|
def process_event(self, resource, event, trunk_plugin, payload):
|
|
"""Emit RPC notifications to registered subscribers."""
|
|
context = payload.context
|
|
LOG.debug("RPC notification needed for trunk %s", payload.resource_id)
|
|
|
|
if resource == resources.TRUNK:
|
|
payload = payload.latest_state
|
|
method = {
|
|
events.AFTER_CREATE: self._stub.trunk_created,
|
|
events.AFTER_DELETE: self._stub.trunk_deleted,
|
|
}
|
|
elif resource == resources.SUBPORTS:
|
|
payload = payload.metadata['subports']
|
|
method = {
|
|
events.AFTER_CREATE: self._stub.subports_added,
|
|
events.AFTER_DELETE: self._stub.subports_deleted,
|
|
}
|
|
else:
|
|
LOG.error('Wrong resource %s', resource)
|
|
|
|
LOG.debug("Emitting event %s for resource %s", event, resource)
|
|
method[event](context, payload)
|