Introduce new bgp_associations API definition

Related-Bug: #1921461
Related-Change: https://review.opendev.org/783791 (spec)

Signed-off-by: Manu B <manubk2020@gmail.com>
Change-Id: If80cf13417dca40de127fbac52ebaa8169be9422
This commit is contained in:
Manu B 2021-05-24 05:07:20 +00:00 committed by Manu B
parent 63c8443a65
commit 6df74e063d
17 changed files with 670 additions and 6 deletions

View File

@ -15,6 +15,14 @@ external network is best for being used as a gateway network.
The association builds a list of all virtual routers with gateways on provider
and self-service networks within the same address scope.
BGP associations extension
==========================
The ``bgp_associations`` extension enables addition of router, peer association
resources as sub-resources to the existing ``bgp-speakers`` resource. New
action ``get_routes`` is also added that will list both learnt as well as
advertised routes by the bgp speaker.
List BGP Speakers
=================
@ -207,7 +215,7 @@ There is no body content for the response of a successful DELETE request.
Add BGP Peer to a BGP Speaker
=============================
.. rest_method:: PUT /v2.0/bgp-speakers/<bgp-speaker-id>/add-bgp-peer
.. rest_method:: PUT /v2.0/bgp-speakers/{bgp-speaker-id}/add-bgp-peer
Bind the BGP peer to the specified BGP Speaker.
@ -243,7 +251,7 @@ Response Example
Remove BGP Peer from a BGP Speaker
==================================
.. rest_method:: PUT /v2.0/bgp-speakers/<bgp-speaker-id>/remove-bgp-peer
.. rest_method:: PUT /v2.0/bgp-speakers/{bgp-speaker-id}/remove-bgp-peer
Unbind the BGP peer from a BGP Speaker.
@ -271,7 +279,7 @@ There is no body content for the response of a successful DELETE request.
Add Network to a BGP Speaker
============================
.. rest_method:: PUT /v2.0/bgp-speakers/<bgp-speaker-id>/add_gateway_network
.. rest_method:: PUT /v2.0/bgp-speakers/{bgp-speaker-id}/add_gateway_network
Add a network to the specified BGP speaker.
@ -308,16 +316,360 @@ Response Example
Delete Network from a BGP Speaker
=================================
.. rest_method:: PUT /v2.0/bgp-speakers/<bgp-speaker-id>/remove_gateway_network
.. rest_method:: PUT /v2.0/bgp-speakers/{bgp-speaker-id}/remove_gateway_network
Remove a network from the specified BGP speaker.
Normal response codes: 200
List Router associations for a given BGP speaker
================================================
.. rest_method:: GET /v2.0/bgp-speakers/{bgp-speaker-id}/router_associations
List all the associated routers for a given BGP speaker
Normal response codes: 200
Error response codes: 400, 401, 403
Request
-------
.. rest_parameters:: parameters.yaml
- bgp-speaker-id: bgp_speaker_id-path
Response Parameters
-------------------
.. rest_parameters:: parameters.yaml
- router_associations: bgp_speaker_router_associations-body
- id: bgp_speaker_router_association_id-body
- router_id: bgp_speaker-router_id-body
- project_id: project_id
- advertise_extra_routes: bgp_speaker_advertise_extra_routes-body
- status: bgp_speaker_association_status
Response Example
----------------
.. literalinclude:: samples/bgp/bgp_speaker_list_all_router_associations-response.json
:language: javascript
Show details for a BGP speaker Router Association
=================================================
.. rest_method:: GET /v2.0/bgp-speakers/{bgp-speaker-id}/router_associations/{router-association-id}
Normal response codes: 200
Error response codes: 401, 404
Request
-------
.. rest_parameters:: parameters.yaml
- bgp-speaker-id: bgp_speaker_id-path
- router-association-id: bgp_speaker_router_association_id-path
Response Parameters
-------------------
.. rest_parameters:: parameters.yaml
- id: bgp_speaker_router_association_id-body
- router_id: bgp_speaker-router_id-body
- project_id: project_id
- advertise_extra_routes: bgp_speaker_advertise_extra_routes-body
- status: bgp_speaker_association_status
Response Example
.. literalinclude:: samples/bgp/bgp_speaker_show_router_association-response.json
:language: javascript
Create BGP Speaker Router Association
=====================================
.. rest_method:: POST /v2.0/bgp-speakers/{bgp-speaker-id}/router_associations
Add a router to the specified BGP speaker.
Normal response codes: 200
Error response codes: 401, 403, 404, 409
Request
-------
.. rest_parameters:: parameters.yaml
- bgp-speaker-id: bgp_speaker_id-path
- router_id: bgp_speaker-router_id-body
- advertise_extra_routes: bgp_speaker_advertise_extra_routes-body
Request Example
---------------
.. literalinclude:: samples/bgp/bgp_speaker_create_router_association-request.json
:language: javascript
Response Parameters
-------------------
.. rest_parameters:: parameters.yaml
- id: bgp_speaker_router_association_id-body
- router_id: bgp_speaker-router_id-body
- project_id: project_id
- advertise_extra_routes: bgp_speaker_advertise_extra_routes-body
- status: bgp_speaker_association_status
Response Example
----------------
.. literalinclude:: samples/bgp/bgp_speaker_create_router_association-response.json
:language: javascript
Update BGP Speaker Router Association
=====================================
.. rest_method:: PUT /v2.0/bgp-speakers/{bgp-speaker-id}/router_associations/{router-association-uuid}
Update router associated to the specified BGP speaker.
Normal response codes: 200
Error response codes: 400, 401, 404, 412
Request
-------
.. rest_parameters:: parameters.yaml
- bgp-speaker-id: bgp_speaker_id-path
- router-association-uuid: bgp_speaker_router_association_id-path
- advertise_extra_routes: bgp_speaker_advertise_extra_routes-body
Request Example
---------------
.. literalinclude:: samples/bgp/bgp_speaker_update_router_association-request.json
:language: javascript
Response Parameters
-------------------
.. rest_parameters:: parameters.yaml
- id: bgp_speaker_router_association_id-body
- router_id: bgp_speaker-router_id-body
- project_id: project_id
- advertise_extra_routes: bgp_speaker_advertise_extra_routes-body
- status: bgp_speaker_association_status
Response Example
----------------
.. literalinclude:: samples/bgp/bgp_speaker_update_router_association-response.json
:language: javascript
Delete BGP Speaker Router Association
=====================================
.. rest_method:: DELETE /v2.0/bgp-speakers/{bgp-speaker-id}/router_associations/{router-association-uuid}
Remove a router from the specified BGP speaker.
Normal response codes: 200
Error response codes: 400, 401, 404, 412
Request
-------
.. rest_parameters:: parameters.yaml
- bgp-speaker-id: bgp_speaker_id-path
- router-association-uuid: bgp_speaker_router_association_id-path
Response
--------
There is no body content for the response of a successful DELETE request.
List Peer associations for a given BGP speaker
==============================================
.. rest_method:: GET /v2.0/bgp-speakers/{bgp-speaker-id}/peer_associations
List all the peer associations for a given BGP speaker.
Normal response codes: 200
Error response codes: 400, 401, 403
Request
-------
.. rest_parameters:: parameters.yaml
- bgp-speaker-id: bgp_speaker_id-path
Response Parameters
-------------------
.. rest_parameters:: parameters.yaml
- peer_associations: bgp_speaker_peer_associations-body
- id: bgp_speaker_peer_association_id-body
- project_id: project_id
- bgp_peer_id: bgp_speaker_peer_id-body
- status: bgp_speaker_association_status
Response Example
----------------
.. literalinclude:: samples/bgp/bgp_speaker_list_all_peer_associations-response.json
:language: javascript
Show details for a BGP speaker Peer Association
===============================================
.. rest_method:: GET /v2.0/bgp-speakers/{bgp-speaker-id}/peer_associations/{peer-association-id}
Normal response codes: 200
Error response codes: 401, 404
Request
-------
.. rest_parameters:: parameters.yaml
- bgp-speaker-id: bgp_speaker_id-path
- peer-association-id: bgp_speaker_peer_association_id-path
Response Parameters
-------------------
.. rest_parameters:: parameters.yaml
- id: bgp_speaker_peer_association_id-body
- project_id: project_id
- bgp_peer_id: bgp_speaker_peer_id-body
- status: bgp_speaker_association_status
Response Example
----------------
.. literalinclude:: samples/bgp/bgp_speaker_show_peer_association-response.json
:language: javascript
Create BGP speaker Peer Association
===================================
.. rest_method:: POST /v2.0/bgp-speakers/{bgp-speaker-id}/peer_associations
Add a peer association to the specified BGP speaker. This operation is
currently planned to be supported only for router-associated BGP speakers and
will not be supported for network-associated BGP speakers.
Normal response codes: 200
Error response codes: 401, 403, 404, 409
Request
-------
.. rest_parameters:: parameters.yaml
- bgp-speaker-id: bgp_speaker_id-path
- bgp_peer_id: bgp_speaker_peer_id-body
Request Example
---------------
.. literalinclude:: samples/bgp/bgp_speaker_create_peer_association-request.json
:language: javascript
Response Parameters
-------------------
.. rest_parameters:: parameters.yaml
- id: bgp_speaker_peer_association_id-body
- project_id: project_id
- bgp_peer_id: bgp_speaker_peer_id-body
- status: bgp_speaker_association_status
Response Example
----------------
.. literalinclude:: samples/bgp/bgp_speaker_create_peer_association-response.json
:language: javascript
Delete BGP speaker Peer Association
===================================
.. rest_method:: DELETE /v2.0/bgp-speakers/{bgp-speaker-id}/peer_associations/{peer-association-uuid}
Remove a peer association from the specified BGP speaker. This operation is
currently planned to be supported only for router-associated BGP speakers and
will not be supported for network-associated BGP speakers.
Normal response codes: 200
Error response codes: 400, 401, 404, 412
Request
-------
.. rest_parameters:: parameters.yaml
- bgp-speaker-id: bgp_speaker_id-path
- peer-association-uuid: bgp_speaker_peer_association_id-path
Response
--------
There is no body content for the response of a successful DELETE request.
List learnt and advertised routes advertised by a BGP Speaker
=============================================================
.. rest_method:: GET /v2.0/bgp-speakers/{bgp-speaker-id}/get_routes
List all routes which includes learnt routes and routes advertised by the
specified BGP Speaker.
Normal response codes: 200
Error response codes: 401, 404
Response Parameters
-------------------
.. rest_parameters:: parameters.yaml
- routes: bgp_speaker_routes-body
- cidr: bgp_speaker_cidr-body
- nexthop: bgp_speaker_nexthop-body
- route_type: bgp_speaker_route_type-body
Response Example
----------------
.. literalinclude:: samples/bgp/bgp_speaker_list_all_routes-response.json
:language: javascript
List routes advertised by a BGP Speaker
=======================================
.. rest_method:: GET /v2.0/bgp-speakers/<bgp-speaker-id>/get_advertised_routes
.. rest_method:: GET /v2.0/bgp-speakers/{bgp-speaker-id}/get_advertised_routes
List all routes advertised by the specified BGP Speaker.
@ -341,7 +693,7 @@ Response Example
List Dynamic Routing Agents hosting a specific BGP Speaker
==========================================================
.. rest_method:: GET /v2.0/bgp-speakers/<bgp-speaker-id>/bgp-dragents
.. rest_method:: GET /v2.0/bgp-speakers/{bgp-speaker-id}/bgp-dragents
List all BGP dynamic agents which are hosting the specified BGP Speaker.

View File

@ -19,6 +19,18 @@ bgp_speaker_id-path:
in: path
required: true
type: string
bgp_speaker_peer_association_id-path:
description: |
The ID of the BGP Speaker Peer association.
in: path
required: true
type: string
bgp_speaker_router_association_id-path:
description: |
The ID of the BGP Speaker Router association.
in: path
required: true
type: string
bgpvpn-id-path:
description: |
The ID of the BGP VPN.
@ -1779,6 +1791,20 @@ bgp_speaker-networks-body:
in: body
required: true
type: string
bgp_speaker-router_id-body:
description: |
The ID of a Neutron router to be associated with the BGP speaker.
in: body
required: true
type: string
bgp_speaker_advertise_extra_routes-body:
description: |
Boolean flag which determines whether Neutron extra routes on the Neutron
router will be redistributed to bgp-peers by the bgpspeaker. Default is
true.
in: body
required: false
type: boolean
bgp_speaker_advertise_fip_host_routes-body:
description: |
Whether to enable or disable the advertisement of floating ip host
@ -1799,6 +1825,13 @@ bgp_speaker_advertised_routes-body:
in: body
required: true
type: array
bgp_speaker_association_status:
description: |
Status of realization of a peer or a router association on the underlying
Openstack infrastructure. It can be either ``DOWN`` or ``ACTIVE``.
in: body
required: true
type: string
bgp_speaker_cidr-body:
description: |
The cidr of the route advertised by the BGP Speaker.
@ -1823,12 +1856,50 @@ bgp_speaker_nexthop-body:
in: body
required: true
type: string
bgp_speaker_peer_association_id-body:
description: |
The ID of Peer association associated to BGP speaker.
in: body
required: true
type: string
bgp_speaker_peer_associations-body:
description: |
A list of ``peer_association`` objects associated to a BGP speaker.
in: body
required: true
type: array
bgp_speaker_peer_id-body:
description: |
The id of the peer.
in: body
required: true
type: string
bgp_speaker_route_type-body:
description: |
The type of route that describes where the route is originated. Valid
values are ``local``, ``peer``.
in: body
required: true
type: string
bgp_speaker_router_association_id-body:
description: |
The ID of Router association associated to BGP speaker.
in: body
required: true
type: string
bgp_speaker_router_associations-body:
description: |
A list of ``router_association`` objects associated to a BGP speaker.
in: body
required: true
type: array
bgp_speaker_routes-body:
description: |
A list of routes (cidr-nexthop-route_type values) advertised and learnt by
the BGP Speaker.
in: body
required: true
type: array
bgp_speakers:
description: |
A list of ``bgp_speaker`` objects. Each ``bgp_speaker`` object acts as a

View File

@ -0,0 +1,6 @@
{
"peer_association":
{
"peer_id": "b930d7f6-ceb7-40a0-8b81-a425dd994ccf"
}
}

View File

@ -0,0 +1,9 @@
{
"peer_association":
{
"project_id": "d84c70a21fed4aeba121a1a429ba0d14",
"id": "a3ebaec0-0570-43ac-82f6-60d2b03168d3",
"peer_id": "b930d7f6-ceb7-40a0-8b81-a425dd994ccf",
"status": "DOWN"
}
}

View File

@ -0,0 +1,7 @@
{
"router_association":
{
"router_id": "c930d7f6-ceb7-40a0-8b81-a425dd994ccf",
"advertise_extra_routes": false
}
}

View File

@ -0,0 +1,11 @@
{
"router_association":
{
"project_id": "d84c70a21fed4aeba121a1a429ba0d14",
"id": "c3ebaec0-0570-43ac-82f6-60d2b03168d3",
"router_id": "c930d7f6-ceb7-40a0-8b81-a425dd994ccf",
"advertise_extra_routes": false,
"status": "DOWN"
}
}

View File

@ -0,0 +1,16 @@
{
"peer_associations": [
{
"project_id": "d84c70a21fed4aeba121a1a429ba0d14",
"id": "a3ebaec0-0570-43ac-82f6-60d2b03168d3",
"peer_id": "b930d7f6-ceb7-40a0-8b81-a425dd994ccf",
"status": "ACTIVE"
},
{
"project_id": "d84c70a21fed4aeba121a1a429ba0d14",
"id": "b3ebaec0-0570-43ac-82f6-60d2b03178f2",
"peer_id": "a640d7f6-ceb7-40a0-8b81-a425dd994dde",
"status": "ACTIVE"
}
]
}

View File

@ -0,0 +1,18 @@
{
"router_associations": [
{
"project_id": "d84c70a21fed4aeba121a1a429ba0d14",
"id": "c3ebaec0-0570-43ac-82f6-60d2b03168d3",
"router_id": "c930d7f6-ceb7-40a0-8b81-a425dd994ccf",
"advertise_extra_routes": true,
"status": "ACTIVE"
},
{
"project_id": "d84c70a21fed4aeba121a1a429ba0d14",
"id": "a4ebaec0-0570-43ac-82f6-60d2b0316844",
"router_id": "ac30d7f6-ceb7-40a0-8b81-b425dd994ddf",
"advertise_extra_routes": true,
"status": "ACTIVE"
}
]
}

View File

@ -0,0 +1,14 @@
{
"routes":[
{
"cidr":"192.168.10.0/24",
"nexthop":"10.0.0.1",
"route_type": "local"
},
{
"cidr":"192.168.11.0/24",
"nexthop":"10.0.0.5",
"route_type": "peer"
}
]
}

View File

@ -0,0 +1,9 @@
{
"peer_association":
{
"project_id": "d84c70a21fed4aeba121a1a429ba0d14",
"id": "a3ebaec0-0570-43ac-82f6-60d2b03168d3",
"peer_id": "b930d7f6-ceb7-40a0-8b81-a425dd994ccf",
"status": "ACTIVE"
}
}

View File

@ -0,0 +1,10 @@
{
"router_association":
{
"project_id": "d84c70a21fed4aeba121a1a429ba0d14",
"id": "c3ebaec0-0570-43ac-82f6-60d2b03168d3",
"router_id": "c930d7f6-ceb7-40a0-8b81-a425dd994ccf",
"advertise_extra_routes": true,
"status": "ACTIVE"
}
}

View File

@ -0,0 +1,6 @@
{
"router_association":
{
"advertise_extra_routes": true
}
}

View File

@ -0,0 +1,11 @@
{
"router_association":
{
"project_id": "d84c70a21fed4aeba121a1a429ba0d14",
"id": "c3ebaec0-0570-43ac-82f6-60d2b03168d3",
"router_id": "c930d7f6-ceb7-40a0-8b81-a425dd994ccf",
"advertise_extra_routes": true,
"status": "ACTIVE"
}
}

View File

@ -21,6 +21,7 @@ from neutron_lib.api.definitions import availability_zone
from neutron_lib.api.definitions import availability_zone_filter
from neutron_lib.api.definitions import bgp
from neutron_lib.api.definitions import bgp_4byte_asn
from neutron_lib.api.definitions import bgp_associations
from neutron_lib.api.definitions import bgp_dragentscheduler
from neutron_lib.api.definitions import bgpvpn
from neutron_lib.api.definitions import bgpvpn_routes_control
@ -146,6 +147,7 @@ _ALL_API_DEFINITIONS = {
availability_zone_filter,
bgp,
bgp_4byte_asn,
bgp_associations,
bgp_dragentscheduler,
bgpvpn,
bgpvpn_routes_control,

View File

@ -0,0 +1,86 @@
# 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.api import converters as n_conv
from neutron_lib.api.definitions import bgp
from neutron_lib.db import constants as db_const
ALIAS = 'bgp-associations'
DESCRIPTION = "Allow adding router, peer association objects to BGP extension"
IS_SHIM_EXTENSION = False
IS_STANDARD_ATTR_EXTENSION = False
NAME = 'BGP Associations'
UPDATED_TIMESTAMP = "2021-07-01T11:00:00-00:00"
BGP_ASSOC_EXT_ALIAS = 'bgp-associations'
ROUTER_ASSOCIATIONS = 'router_associations'
ROUTER_ASSOCIATION = 'router_association'
PEER_ASSOCIATIONS = 'peer_associations'
PEER_ASSOCIATION = 'peer_association'
RESOURCE_ATTRIBUTE_MAP = {
bgp.BGP_SPEAKERS: {}
}
SUB_RESOURCE_ATTRIBUTE_MAP = {
ROUTER_ASSOCIATIONS: {
'parent': {'collection_name': bgp.BGP_SPEAKERS,
'member_name': bgp.BGP_SPEAKER_BODY_KEY_NAME},
'parameters': {
'id': {'allow_post': False, 'allow_put': False,
'validate': {'type:uuid': None},
'is_visible': True,
'primary_key': True},
'project_id': {'allow_post': True, 'allow_put': False,
'validate': {
'type:string': db_const.PROJECT_ID_FIELD_SIZE},
'required_by_policy': True,
'is_visible': True},
'router_id': {'allow_post': True, 'allow_put': False,
'validate': {'type:uuid': None},
'is_visible': True},
'advertise_extra_routes': {
'allow_post': True,
'allow_put': True,
'convert_to': n_conv.convert_to_boolean,
'validate': {'type:boolean': None},
'is_visible': True, 'default': True,
'required_by_policy': False},
}
},
PEER_ASSOCIATIONS: {
'parent': {'collection_name': bgp.BGP_SPEAKERS,
'member_name': bgp.BGP_SPEAKER_BODY_KEY_NAME},
'parameters': {
'id': {'allow_post': False, 'allow_put': False,
'validate': {'type:uuid': None},
'is_visible': True,
'primary_key': True},
'project_id': {'allow_post': True, 'allow_put': False,
'validate': {
'type:string': db_const.PROJECT_ID_FIELD_SIZE},
'required_by_policy': True,
'is_visible': True},
'peer_id': {'allow_post': True, 'allow_put': False,
'validate': {'type:uuid': None},
'is_visible': True}
}
}
}
REQUIRED_EXTENSIONS = [bgp.ALIAS]
OPTIONAL_EXTENSIONS = []
ACTION_MAP = bgp.ACTION_MAP
ACTION_MAP[bgp.BGP_SPEAKER_RESOURCE_NAME].update({
'get_routes': 'GET',
})
ACTION_STATUS = {}

View File

@ -0,0 +1,24 @@
# 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.api.definitions import bgp
from neutron_lib.api.definitions import bgp_associations
from neutron_lib.tests.unit.api.definitions import base
class BgpAssociationsTestCase(base.DefinitionBaseTestCase):
extension_module = bgp_associations
extension_resources = (bgp.BGP_SPEAKERS,)
extension_subresources = (bgp_associations.ROUTER_ASSOCIATIONS,
bgp_associations.PEER_ASSOCIATIONS)
extension_attributes = ('router_id', 'advertise_extra_routes', 'peer_id')

View File

@ -0,0 +1,12 @@
---
features:
- New extension ``bgp_associations`` is included to allow addition of
router, peer association resources as sub-resources to the existing
``bgp-speakers`` resource.
- Added action ``get_routes`` to the existing bgp extension to list both
learnt as well as advertised routes by the bgp speaker.
(``Note`` that this API extension was merged as experimental to enable
parallel development of multiple backends. At the moment this API does
not have a reference implementation and should not be considered final.
A later release note will mark when the reference implementation gets
merged and the feauture is ready to be consumed.