Nautobot Relationships

The native data model in Nautobot will suffice for the majority of use cases. However, some deployments have additional requirements between objects based on the design of their networks. Nautobot now provides the capability to define new relationships to support a more customized network data model.

For example, a VLAN may need to be defined on a per-device basis, rather than the native model of a VLAN per site. This would allow a user to define and model VLANs for a network device that are locally significant.

This series of posts will outline the new user-defined relationship feature in Nautobot and explore some use cases where this feature can be applied to help model a network design.

Relationships Primer

One of the columns in a database table will store a primary key, which will uniquely identify each object. This field is used in the object-relational mapping (ORM) when defining relationships between objects. This simply allows objects to build associations with each other.

A common example used to explain this concept uses books. A publisher has a relationship with a book as it can publish a book. Each book will have a publisher.

db-assoc

Additional constraints can be introduced to be more specific in the relationship definition. The next sections outline the different types of relationships that can exist between objects.

One-to-Many

one-to-many type introduces a constraint in that a book can have only one publisher, denoted with the 1 on line beside the publisher. A publisher can have many books, denoted with N for number on the many side.

rel-one-to-many

Many-to-Many

many-to-many relationship has no constraints. A customer can buy many books and a book can be bought by many customers.

rel-many-to-many

One-to-One

one-to-one relationship has a unique constraint on both sides of the relationship. For example, an order can have only one payment and a payment can be made on one order.

rel-one-to-one

Nautobot Model

Nautobot is designed as a Source of Truth application aimed at modeling modern networks. Its core data models allow users to define the intended state of a network. This is achieved by providing a native data model, with its inherent relationships between the objects.

As an example, a subset of the Nautobot core data model illustrates the relationships between some of the objects in the nautobot.ipam and nautobot.circuit applications. The database tables are represented as boxes including their fields. The lines between the tables denote an association or relationship between the tables. The diagram shows how an IPAddress can have a VRF, a Prefix can have a VRF and a VLAN, and finally a Circuit can have a Provider. At a database level, we can see that these relationships are represented as foreign keys between the database tables.

graph_model_incl_fields

INFO: This diagram was rendered using the graph models feature in the django_extensions package.

The core data model is quite established, based on years of iterative open-source development that began with the NetBox project. However, it’s very difficult to provide a standard framework that can meet the requirements of all networks. There will always be components of the network that will be different. One of the key objectives of Nautobot is to provide maximum data model flexibility. This is where the new Relationships feature can be applied. It allows users to define their own relationships between the objects in the system.

Use Case 1: IPAddress – Circuit

The first use case will focus on modeling an IPv4-based circuit, such as an enterprise router connection to an Internet Service Provider WAN. Each circuit can have two IP addresses, one at each end of the circuit. This type of relationship is not defined in the native data model. To enable it, a new relationship (highlighted in red) can be created between an IPAddress and a Circuit.

graph_model_no_fields_new_rel

New Relationship: IPAddress – Circuit

To create a new relationship, navigate to Extensibility -> Relationships on the Nautobot web user interface. The use case in question supports one circuit having two IPs. Any model that can have more than one object in the association is defined as a many in the relationship. Enter a custom name to identify the new relationship and set the relationship type as One to Many.

The Source type is circuit | circuit as this is the one side of the relationship and it is defined as the source. The Source Label will be used to display the other end of the relationship, on the source page. For this use case the Source Label is IP Address. The Destination fields are the reverse of the Source fields. Both source and destination filters can be left blank.

circuit-ipaddress-relationship

Update Circuit

Once a relationship has been created, it will be visible when configuring one of the model objects. A new Relationship panel will be available to select an existing object of the defined source/destination type.

In the example, circuit A123456789 has two IP addresses associated with it. Multiple IPs can be can be selected since IPAddress is on the many side of the new relationship.

edit_circuit_ip_relationship

Update IP Address

For the IP addresses, one circuit can be selected in each IP address object. The selection drop-down list will only allow one object to be configured, as Circuit is on the one side of the relationship.

edit_ipaddress_circuit_relationship

Defining a new relationship allows network design use cases to be managed through the web user interface by creating new associations between existing objects. This reduces the need to manage additional layers of data by adding custom fields to objects and maintaining the custom field data synchronization through scripts or playbooks. Relationships can also be defined using the REST API.

An alternative solution for this use case might involve creating a one-to-one relationship between an IP Address and Circuit. In this case, a circuit would be associated with one IP Address. Creating two of these associations would model the circuit end-to-end.

Use Case 2: VLAN – VLAN Group

Another, perhaps more advanced, use case would be to create a relationship between models that already have a native relationship. For example, a VLAN group and VLAN have an inherent One to Many relationship, whereby a VLAN Group can have many VLANs but a VLAN can only be a member of only one VLAN group. Some networks may have a need to have VLANs in multiple VLAN groups. VLANs could be members of a management group for a site, while also being part of a group that requires access to cloud-based Operational Support Systems (OSS). This use case could be managed with custom tags or custom fields, but relationships provide a way to overlay a new association between the models and link existing objects together.

The diagram below illustrates how the new relationship (highlighted in red) would be modeled, alongside the existing relationship.

graph_model_no_fields_vlans

New Relationship: VLAN – VLAN Group

Many to Many relationship is required to support this use case. Following on from the guidelines in the previous use case, with the addition of a filter to restrict the relationship to VLANs with the role of leaf, filtering is defined using JSON data format to identify the model fields and their values.

In the example, the new relationship will be applied only on VLANs that have a role of leaf. Roles can be applied to VLANs to assist with network design modeling e.g., define leaf-switch VLANs.

vlan_edit_multiple_groups_relationship

For demonstration purposes, a short list of VLANs shows some Leaf and Core roles to illustrate the filtering capability.

vlan_list_relationship

Update VLAN

Editing a VLAN allows multiple VLAN groups to be associated with a single VLAN through the newly defined relationship. A key point to note is that the new relationship is managed through the Relationships panel and not through the native Group field, which is left blank.

edit_vlan_relationship

Update VLAN Group

For VLAN group(s) configured in the relationship, apply the new VLANs. Due to the filtering applied on the VLAN side of the relationship, only VLANs with a role of Leaf can be selected.

vlan_group_edit_filter_vlan_relationship

Management of the new VLANs is through the Relationships panel on the VLAN Group page. For this advanced use case, the native VLAN view (right-hand side) on the VLAN group page is not populated.

vlan_group_manage_vlan

Selecting the VLANs hyperlink displays all of the VLANs through the relationship-association table.

vlan_group_relationship_assoc

Conclusion

Defining new relationships is a very powerful feature in Nautobot. It supports flexible data modeling to assist with specific use cases of network design representation in a Source of Truth application.

This guide focused on how to define the relationships in the web user interface. In a future post, we’ll look at using REST and GraphQL based APIs to interact with the new relationships in Nautobot.

-Paddy

Resources



ntc img
ntc img

Contact Us to Learn More

Share details about yourself & someone from our team will reach out to you ASAP!

Author