120 lines
5.3 KiB
Python
120 lines
5.3 KiB
Python
# 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.api.rpc.callbacks import events as rpc_events
|
|
from neutron.api.rpc.callbacks import resources as resources_registry
|
|
from neutron.api.rpc.handlers import resources_rpc
|
|
|
|
from neutron_dynamic_routing.objects import bgp_associations as assoc_objects
|
|
|
|
|
|
class BgpL3AgentNotifyApi(object):
|
|
"""API for plugin to notify BGP L3Agent.
|
|
|
|
This class implements the client side of an rpc interface. The server side
|
|
is neutron_dynamic_routing.services.bgp.agent.l3.bgp_extension. For
|
|
more information about rpc interfaces, please see
|
|
https://docs.openstack.org/neutron/latest/contributor/internals/rpc_api.html.
|
|
"""
|
|
|
|
def __init__(self):
|
|
self._register_resources()
|
|
self.push_api = resources_rpc.ResourcesPushRpcApi()
|
|
|
|
def _register_resources(self):
|
|
resources_registry.register_resource_class(
|
|
assoc_objects.BgpSpeakerRouterAssociation)
|
|
resources_registry.register_resource_class(
|
|
assoc_objects.BgpSpeakerPeerAssociation)
|
|
|
|
def bgp_peer_association_created(self, context, bgp_speaker_id,
|
|
assoc_info):
|
|
"""Tell L3 agent about a BGP Peer Association.
|
|
This effectively tells the BgpL3Agent to start a peering session.
|
|
"""
|
|
peer_assoc_obj = assoc_objects.BgpSpeakerPeerAssociation(
|
|
context,
|
|
**assoc_info)
|
|
self.push_api.push(context, [peer_assoc_obj], rpc_events.CREATED)
|
|
|
|
def bgp_peer_association_deleted(self, context, bgp_speaker_id,
|
|
assoc_info):
|
|
"""Tell L3 agent about a BGP Peer disassociation.
|
|
This effectively tells the BgpL3Agent to stop a peering session.
|
|
"""
|
|
peer_assoc_obj = assoc_objects.BgpSpeakerPeerAssociation(context,
|
|
**assoc_info)
|
|
self.push_api.push(context, [peer_assoc_obj], rpc_events.DELETED)
|
|
|
|
def bgp_router_association_created(self, context, bgp_speaker_id,
|
|
assoc_info):
|
|
"""Tell L3 agent about a BGP Router Association.
|
|
This effectively tells the BgpL3Agent to start a speaker inside
|
|
router namespace.
|
|
"""
|
|
router_assoc_obj = assoc_objects.BgpSpeakerRouterAssociation(
|
|
context,
|
|
**assoc_info)
|
|
self.push_api.push(context, [router_assoc_obj], rpc_events.CREATED)
|
|
|
|
def bgp_router_association_updated(self, context, bgp_speaker_id,
|
|
assoc_info):
|
|
"""Tell L3 agent about a BGP Router Association updation."""
|
|
router_assoc_obj = assoc_objects.BgpSpeakerRouterAssociation(
|
|
context,
|
|
**assoc_info)
|
|
self.push_api.push(context, [router_assoc_obj], rpc_events.UPDATED)
|
|
|
|
def bgp_router_association_deleted(self, context, bgp_speaker_id,
|
|
assoc_info):
|
|
"""Tell L3 agent about a BGP Router disassociation.
|
|
This effectively tells the BgpL3Agent to stop the speaker inside
|
|
router namespace.
|
|
"""
|
|
router_assoc_obj = assoc_objects.BgpSpeakerRouterAssociation(
|
|
context,
|
|
**assoc_info)
|
|
self.push_api.push(context, [router_assoc_obj], rpc_events.DELETED)
|
|
|
|
def agent_updated(self, context, admin_state_up, host):
|
|
pass
|
|
|
|
def bgp_routes_advertisement(self, context, bgp_speaker_id,
|
|
routes, host):
|
|
"""Currently this is handled by L3 agent itself on router and peer
|
|
association.
|
|
This can be used in future to support FIP and other scenarios for
|
|
router attached speakers.
|
|
"""
|
|
|
|
def bgp_routes_withdrawal(self, context, bgp_speaker_id,
|
|
routes, host):
|
|
pass
|
|
|
|
def bgp_speaker_created(self, context, bgp_speaker_id, host):
|
|
"""BGP speaker is currently created whenever router is associated
|
|
to BGP speaker.
|
|
"""
|
|
|
|
def bgp_speaker_removed(self, context, bgp_speaker_id, host):
|
|
pass
|
|
|
|
def bgp_peer_disassociated(self, context, bgp_speaker_id,
|
|
bgp_peer_ip, host=None):
|
|
"""Currently router attached speakers only support peer association
|
|
objects. But this can be enhanced in future
|
|
"""
|
|
|
|
def bgp_peer_associated(self, context, bgp_speaker_id,
|
|
bgp_peer_id, host=None):
|
|
pass
|