Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSRB review #55

Merged
merged 5 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Nautobot BGP Models Plugin

A plugin for [Nautobot](https://github.com/nautobot/nautobot) to extend the core models with BGP specific models. All types of BGP peerings can be model and managed, whether or not the device is present in Nautobot.
A plugin for [Nautobot](https://github.com/nautobot/nautobot) extending the core models with BGP-specific models.

New models enable modeling and management of BGP peerings, whether or not the peer device is present in Nautobot.

> The initial development of this plugin was sponsored by Riot Games, Inc.

Expand Down
13 changes: 12 additions & 1 deletion development/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@ version: "3.4"
services:
nautobot:
command: "nautobot-server runserver 0.0.0.0:8080"
ports:
- "8080:8080"
volumes:
- "./nautobot_config.py:/opt/nautobot/nautobot_config.py"
- "../:/source"
docs:
entrypoint: "mkdocs serve -v -a 0.0.0.0:8080"
ports:
- "8080:8080"
- "8001:8080"
volumes:
- "../docs:/source/docs:ro"
- "../mkdocs.yml:/source/mkdocs.yml:ro"
image: "nautobot-bgp-models/nautobot:${NAUTOBOT_VER}-py${PYTHON_VER}"
healthcheck:
disable: true
tty: true
worker:
volumes:
- "./nautobot_config.py:/opt/nautobot/nautobot_config.py"
Expand Down
4 changes: 3 additions & 1 deletion docs/cisco_use_case.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Example use of BGP Models plugin - Cisco BGP Configuration

This document provides an example of generating a Cisco device's desired BGP configuration based on data stored in Nautobot using this plugin. A GraphQL query is used to retrieve the relevant data, which is then rendered through a Jinja2 template to produce the desired configuration.

## Querying for the data
In order to retrieve a BGP data, following GraphQL can be issued to a Nautobot.

In order to retrieve a BGP data, following GraphQL query can be issued to a Nautobot.
mzbroch marked this conversation as resolved.
Show resolved Hide resolved

```python
import pynautobot
Expand Down
11 changes: 11 additions & 0 deletions docs/example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Examples

To make the start with the plugin easier, we provide two example use cases for common OS platforms: Cisco and Juniper.

## Cisco Configuration Modeling and Rendering

Navigate to [Cisco Example Use Case](cisco_use_case.md) for detailed instructions how to consume BGP Models plugin on Cisco devices.
mzbroch marked this conversation as resolved.
Show resolved Hide resolved

## Juniper Configuration Modeling and Rendering

Navigate to [Juniper Example Use Case](juniper_use_case.md) for detailed instructions how to consume BGP Models plugin on Juniper devices.
mzbroch marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 3 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Nautobot BGP Models Plugin

A plugin for [Nautobot](https://github.com/nautobot/nautobot) to extend the core models with BGP specific models. All types of BGP peerings can be model and managed, whether or not the device is present in Nautobot.
A plugin for [Nautobot](https://github.com/nautobot/nautobot) extending the core models with BGP-specific models.

New models enable modeling and management of BGP peerings, whether or not the peer device is present in Nautobot.

> The initial development of this plugin was sponsored by Riot Games, Inc.

Expand Down
4 changes: 3 additions & 1 deletion docs/juniper_use_case.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Example use of BGP Models plugin - Juniper BGP Configuration

This document provides an example of generating a Juniper device's desired BGP configuration based on data stored in Nautobot using this plugin. A GraphQL query is used to retrieve the relevant data, which is then rendered through a Jinja2 template to produce the desired configuration.

## Querying for the data
In order to retrieve a BGP data, following GraphQL can be issued to a Nautobot.

In order to retrieve a BGP data, following GraphQL query can be issued to Nautobot.
mzbroch marked this conversation as resolved.
Show resolved Hide resolved

```python
import pynautobot
Expand Down
150 changes: 79 additions & 71 deletions docs/models.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Data Models

This plugin adds the following new data models into Nautobot:

- Autonomous System
- Routing Instance
- Peer Endpoint
- Peer Group
- Peer Group Template
- Address Family
This plugin adds the following data models to Nautobot:

- AutonomousSystem
- BGPRoutingInstance
- PeerEndpoint
- PeerGroup
- PeerGroupTemplate
- AddressFamily
- Peering
- Peering Role
- PeeringRole

A key motivation behind this design is the idea that the Source of Truth should take a network-wide view of the BGP configuration, rather than a device-per-device view. This most directly applies to the data models for autonomous systems (ASNs), BGP peerings and network-wide templates (Peer Groups).
A key motivation behind this design is the idea that the Source of Truth should take a network-wide view of the BGP configuration, rather than a per-device view. This especially applies to the data models for autonomous systems (ASNs), BGP peerings, and network-wide templates (Peer Groups).
mzbroch marked this conversation as resolved.
Show resolved Hide resolved

All the data models introduced by the BGP plugin support the following Nautobot features:
The data models introduced by the BGP plugin support the following Nautobot features:

- Rest API
- GraphQL
Expand All @@ -24,32 +24,48 @@ All the data models introduced by the BGP plugin support the following Nautobot
- Custom data validation logic
- Webhooks

> The data model defined by this plugin takes inspirations from the Openconfig BGP data model (https://yangcatalog.org/api/services/tree/[email protected]) and the RFC 9234 (https://datatracker.ietf.org/doc/rfc9234/)
> The data models defined in this plugin were inspired by the Openconfig BGP data model (https://yangcatalog.org/api/services/tree/[email protected]) and the RFC 9234 (https://datatracker.ietf.org/doc/rfc9234/)

## AutonomousSystem
### AutonomousSystem

This model represents a network-wide description of a BGP autonomous system (AS). It has fields including the actual AS number (ASN), a description field, foreign key (FK) to a Nautobot `Provider` object, and a FK to a Nautobot `Status` object.

## BGPRoutingInstance
### BGPRoutingInstance

This model represents a device specific BGP process. It has a mandatory FK to a Nautobot `Device`, mandatory FK to a `AutonomousSystem` and following fields:

- Router ID (optional, FK to Nautobot `IPAddress`,
- Router ID (optional, FK to Nautobot `IPAddress`)
- Description (optional, string)
- Extra Attributes (optional, JSON)

## PeerEndpoint
### Extra Attributes

This model represents the configuration of a single device with respect to a single BGP peering. It does not store configuration that must match symmetrically between peer devices (such as a common authentication key).
Additional BGP object's attributes can be defined in "Extra Attributes" field. Extra attributes is a JSON type field meant to store data defined by user.
mzbroch marked this conversation as resolved.
Show resolved Hide resolved

Note that in the case of an external peering (device in the locally managed network peering to a remote endpoint belonging to an AS not managed within this network), while there generally will not be a Device record representing the remote endpoint, there will need to be a `PeerEndpoint` record representing it, at a minimum storing the IP address and ASN of the remote endpoint.
Extra attributes follow the inheritance pattern, thus allowing for merging of the inherited extra attributes.
mzbroch marked this conversation as resolved.
Show resolved Hide resolved

`PeerEndpoint` model has a mandatory FK to a BGP Routing Instance (`BGPRoutingInstance`) record, an optional foreign-key relationship to a `PeerGroup`, and additional keys including:
Example of the extra attributes:

```json
{"ttl-security": 1, "timers": [6, 20] }
```

Extra Attributes are available for following models:

- `PeerEndpoint`
- `PeerGroup`
- `PeerGroupTemplate`
- `BGPRoutingInstance`

### PeeringRole

This model operates similarly to Nautobot’s `Status` and `Tag` models, in that instances of this model describe various valid values for the `Role` field used by `PeerGroup` and `Peering` records. Similar to those models, this model has fields including a unique name, unique slug, and a HTML color value.
mzbroch marked this conversation as resolved.
Show resolved Hide resolved

### PeerGroupTemplate

This model represents network-wide configuration for `PeerGroups`. `PeerGroupTemplate` aims to represent a global configuration, and it has a mandatory `Name` field, and following fields:
mzbroch marked this conversation as resolved.
Show resolved Hide resolved

- ASN (optional, FK to `AutonomousSystem`)
- Peer (optional, FK to `PeerEndpoint`)
- Source IP (optional, FK to Nautobot `IPAddress`, mutually-exclusive with Source Interface)
- Source Interface (optional, FK to Nautobot `Interface`, mutually-exclusive with Source IP)
- Role (optional, FK to `PeeringRole`)
- Description (string)
- Enabled (bool)
Expand All @@ -58,21 +74,9 @@ Note that in the case of an external peering (device in the locally managed netw
- Secret (optional, FK to Nautobot `Secret`)
- Extra Attributes (optional, JSON)

### PeerEndpoint Local-IP

To ease the data presentation and consumption, `PeerEndpoint` provides also a property named `local_ip`.
The value of this property will be presented in plugin's Grapical User Interface (GUI), and can be used to render configuration templates.

As Source-IP and Source-Interface could be defined at multiple inheritance levels, each Peer Endpoint will have a `local_ip` determined based on the following order:

1. `PeerEndpoint`'s `source_ip` attribute (if exists)
2. `Peer Group`'s `source_ip` attribute (if exists)
3. `PeerEndpoint`'s `source_interface` attribute (if exists)
4. `PeerGroup`'s `source_interface` attribute (if exists)

## PeerGroup
### PeerGroup

This model represents common configuration for a group of functionally related BGP peers. `PeerGroup` aims to represent device-specific configuration, and it has a mandatory `Name` field, optional FK to a network-wide `PeerGroupTemplate`, and additional fields including:
This model represents common configuration for a group of functionally related BGP peers. Peer Group aims to represent device-specific configuration shared across multiple peerings, and it has a mandatory `Name` field, optional FK to a network-wide `PeerGroupTemplate`, and additional fields including:
mzbroch marked this conversation as resolved.
Show resolved Hide resolved

- ASN (optional, FK to `AutonomousSystem`)
- Source IP (optional, FK to Nautobot `IPAddress`, mutually-exclusive with Source Interface)
Expand All @@ -85,11 +89,20 @@ This model represents common configuration for a group of functionally related B
- Secret (optional, FK to Nautobot `Secret`)
- Extra Attributes (optional, JSON)

## PeerGroupTemplate
### PeerEndpoint

This model represents network-wide configuration for `PeerGroups`. `PeerGroupTemplate` aims to represent a global configuration, and it has a mandatory `Name` field, and following fields:
PeerEndpoint records are created when Peering instance is created.

This model represents the configuration of a single device with respect to a single BGP peering.

Note that in the case of an external peering (connection with an ISP or Transit Provider), there is no need to create and model provider's `Device` object. However, as a minimum `PeerEndpoint` (representing provider's side of `Peering`) created during `Peering` object creation, will have to store IP Address and ASN.

`PeerEndpoint` model has a mandatory FK to a BGP Routing Instance (`BGPRoutingInstance`) record, an optional foreign-key relationship to a `PeerGroup`, and additional keys including:
mzbroch marked this conversation as resolved.
Show resolved Hide resolved

- ASN (optional, FK to `AutonomousSystem`)
- Peer (optional, FK to `PeerEndpoint`)
- Source IP (optional, FK to Nautobot `IPAddress`, mutually-exclusive with Source Interface)
- Source Interface (optional, FK to Nautobot `Interface`, mutually-exclusive with Source IP)
- Role (optional, FK to `PeeringRole`)
- Description (string)
- Enabled (bool)
Expand All @@ -98,72 +111,67 @@ This model represents network-wide configuration for `PeerGroups`. `PeerGroupTem
- Secret (optional, FK to Nautobot `Secret`)
- Extra Attributes (optional, JSON)

## Extra Attributes
The device-specific `PeerEndpoint` custom modeling will be implemented in the future with `PeerEndpointContext` and `PeerGroupContext` models.

Additional BGP object's attributes can be modelled by "Extra Attributes". Extra_attributes is a JSON type fields allowing to store data modelled by user.
Extra attributes follow the inheritance pattern, thus allowing for merging the inherited extra attributes.
#### PeerEndpoint Local-IP

Examples of the extra attributes might include:
To ease the data presentation and consumption, `PeerEndpoint` provides also a property named `local_ip`.
mzbroch marked this conversation as resolved.
Show resolved Hide resolved

```json
{"ttl-security": 1, "timers": [6, 20] }
```
The value of this property will be presented in plugin's Grapical User Interface (GUI), and can be used to render configuration templates.
mzbroch marked this conversation as resolved.
Show resolved Hide resolved

Extra Attributes are available for following models:
As Source-IP and Source-Interface could be defined at multiple inheritance levels, each Peer Endpoint will have a `local_ip` determined based on the following order:

- `PeerEndpoint`
- `PeerGroup`
- `PeerGroupTemplate`
- `BGPRoutingInstance`
1. `PeerEndpoint`'s `source_ip` attribute (if exists)
2. `PeerGroup`'s `source_ip` attribute (if exists)
3. `PeerEndpoint`'s `source_interface` attribute (if exists)
4. `PeerGroup`'s `source_interface` attribute (if exists)

## AddressFamily
### AddressFamily

This model represents configuration of a BGP address-family (AFI-SAFI). AddressFamily aims to represent a device specific Address Family instance.
It has a locally unique AFI (address-family identifier) field, optional VRF field (FK to Nautobot `VRF`) and following fields:

It has a locally unique AFI (address family identifier) field, optional VRF field (FK to Nautobot `VRF`) and following fields:

- Import Policy (optional, string)
- Export Policy (optional, string)

(*) The network-wide modelling of AddressFamilies will be implemented in the future with `AddressFamilyTemplate` model similar to the `PeerGroupTemplate`.
The device-specific `PeerEndpoint` custom modeling will be implemented in the future with `PeerEndpointContext` and `PeerGroupContext` models.
(*) The network-wide modeling of AddressFamilies will be implemented in the future with `AddressFamilyTemplate` model similar to the `PeerGroupTemplate`.

## Peering
### Peering

This model represents the shared configuration of a single BGP peer relationship between two endpoints. It has FKs to two `PeerEndpoint` records (representing the two devices involved in the peering), and additional fields including:

- Status (FK to Nautobot `Status`)

> The nature of a session as BGP “internal” or “external” is useful in the construction of queries and filters, but does not need to be stored as an actual database attribute (as it is implied by whether the ASNs of the two BGPPeerEndpoints involved are identical or different). It is implemented as a derived property of the `Peering` model.

## PeeringRole
> The nature of a session as BGP "internal" or "external" is useful in the construction of queries and filters, but does not need to be stored as an actual database attribute (as it is implied by whether the ASNs of the two BGPPeerEndpoints involved are identical or different). It is implemented as a derived property of the `Peering` model.
mzbroch marked this conversation as resolved.
Show resolved Hide resolved

This model operates similarly to Nautobot’s `Status` and `Tag` models, in that instances of this model describe various valid values for the `role` field on `PeerGroupTemplate`, `PeerGroup` and/or `PeerEndpoint`. This model has fields including a unique name, unique slug, and a HTML color value.
### Inheritance between models

## Inheritance between models

Some models have a built-in inheritance similar to what BGP supports with PeerGroup. The inheritance can take multi-level lookup between BGP objects, in this case the first found object with the assigned attribute will be considered as an inheritance source.
Some models can inherit attribute values, similar to what BGP supports with Peer Group. The inheritance is built hierarchically. The final attribute value will be taken from the first object in the hierarchy, moving from the top, which has given the attribute value defined.

Example **PeerEndpoint** inheritance details:

- A `PeerEndpoint` inherits `AutonomousSystem` and `extra_attributes` fields from:
- `PeerGroup`
- `PeerGroupTemplate`
- `BGPRoutingInstance`
- `PeerGroup`
- `PeerGroupTemplate`
- `BGPRoutingInstance`


- A `PeerEndpoint` inherits `description`, `enabled`, `export_policy`, `import_policy` fields from:
- `PeerGroup`
- `PeerGroupTemplate`
- `PeerGroup`
- `PeerGroupTemplate`


- A `PeerEndpoint` inherits `source_ip`, `source_interface` fields from:
- `PeerGroup`
- `PeerGroup`

As an example, a `PeerEndpoint` associated with a `PeerGroup` will automatically inherit above attributes of the `PeerGroup` that haven't been defined at the `PeerEndpoint` level. If an attribute is defined on both, the value defined on the `PeerEndpoint` will be used.
As an example, a `PeerEndpoint` associated with a `PeerGroup` will automatically inherit above attributes of the `PeerGroup` that haven't been defined at the `PeerEndpoint` level. If an attribute is defined at both levels, the value defined in the `PeerEndpoint` will be used.
mzbroch marked this conversation as resolved.
Show resolved Hide resolved

The inherited values will be automatically displayed in the UI and can be retrieve from the REST API with the additional `?include_inherited=true` parameter.
The inherited values will be automatically displayed in the UI and can be retrieved from the REST API by adding `?include_inherited=true` parameter.

(*) **BGP models Custom Fields and GraphQL currently does not offer support for BGP Field Inheritance.** GraphQL issue is tracked under https://github.com/nautobot/nautobot-plugin-bgp-models/issues/43

Following is the complete documentation of the field inheritance pattern. Models are listed from top priority to the least priority, the first model with an assigned attribute value will be used as an inheritance source.
Following is the complete documentation of the field inheritance hierarchy. Models are ordered with the topmost having the highest priority. The first model with an assigned attribute value will be used as an inheritance source.

**PeerEndpoint**:

Expand Down
26 changes: 26 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
dev_addr: "127.0.0.1:8001"
edit_uri: "edit/main/nautobot-plugin-bgp-models/docs"
site_name: "Nautobot BGP Models Plugin Documentation"
site_url: "https://nautobot-plugin-bgp-models.readthedocs.io/"
site_dir: "nautobot_bgp_models/static/nautobot_bgp_models/docs"
repo_url: "https://github.com/nautobot/nautobot-plugin-bgp-models"
theme:
name: "readthedocs"
navigation_depth: 4
hljs_languages:
- "django"
- "yaml"
extra_css:
- "extra.css"
markdown_extensions:
- "admonition"
- toc:
permalink: true
plugins:
- "include-markdown"
nav:
- Introduction: "index.md"
- Examples: "example.md"
- Development Environment: "development.md"
- Models: "models.md"
mzbroch marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 10 additions & 0 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,14 @@ def unittest_coverage(context):
run_command(context, command)


@task
def check_docs(context):
"""Build and test docs."""
command = "mkdocs build --no-directory-urls --strict"

run_command(context, command)


@task
def yamllint(context):
"""Run yamllint to validate formating adheres to NTC defined YAML standards.
Expand Down Expand Up @@ -379,6 +387,8 @@ def tests(context, failfast=False):
pydocstyle(context)
print("Running pylint...")
pylint(context)
print("Running mkdocs...")
check_docs(context)
print("Running unit tests...")
unittest(context, failfast=failfast)
print("All tests have passed!")
Expand Down