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

Add common TypedDicts used for M2M #565

Merged
merged 4 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions changes/310.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added common TypedDicts for Contrib SSoT.
10 changes: 10 additions & 0 deletions docs/user/modeling.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ class IPAddressDict(TypedDict):
prefix_length: int
```

!!! note
Common `TypedDict` objects are included with `nautobot_ssot.contrib.typeddicts` including:

`ContentTypeDict`, `TagDict`, `LocationDict`, `DeviceDict`, `InterfaceDict`, `PrefixDict`, `VLANDict`, `IPAddressDict`, `VirtualMachineDict`

```
# Example
from nautobot_ssot.contrib.typeddicts import LocationDict
```

Having defined this, we can now define our diffsync model:

```python
Expand Down
74 changes: 74 additions & 0 deletions nautobot_ssot/contrib/typeddicts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""Common TypedDict definitions used in Many-to-Many relationships."""

from typing import TypedDict


class ContentTypeDict(TypedDict):
"""TypedDict for Django Content Types."""

app_label: str
model: str


class TagDict(TypedDict):
"""TypedDict for Nautobot Tags."""

name: str


class LocationDict(TypedDict):
"""TypedDict for DCIM Locations."""

name: str
parent__name: str


class DeviceDict(TypedDict):
"""TypedDict for DCIM Devices."""

name: str
location__name: str
tenant__name: str
rack__name: str
rack__rack_group__name: str
position: int
face: str
virtual_chassis__name: str
vc_position: int


class InterfaceDict(TypedDict):
"""TypedDict for DCIM INterfaces."""

name: str
device__name: str


class PrefixDict(TypedDict):
"""TypedDict for IPAM Prefixes."""

network: str
prefix_length: int
namespace__name: str


class VLANDict(TypedDict):
"""TypedDict for IPAM VLANs."""

vid: int
vlan_group__name: str


class IPAddressDict(TypedDict):
"""TypedDict for IPAM IP Address."""

host: str
prefix_length: int


class VirtualMachineDict(TypedDict):
"""TypedDict for IPAM ."""

name: str
cluster__name: str
tenant__name: str
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,9 @@ def load_circuit(self, bs_circuit, branch_vars):
def load_circuit_termination(self, bs_circuit_termination, branch_vars):
"""Load CircuitTermination objects from Bootstrap into DiffSync models."""
if self.job.debug:
self.job.logger.debug(f"Loading Bootstrap CircuitTermination {bs_circuit_termination} into DiffSync models.")
self.job.logger.debug(
f"Loading Bootstrap CircuitTermination {bs_circuit_termination} into DiffSync models."
)
_parts = bs_circuit_termination["name"].split("__")
_circuit_id = _parts[0]
_provider = _parts[1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,9 @@ def load_location_type(self):
"""Method to load LocationType objects from Nautobot into NautobotLocationType DiffSync models."""
for nb_location_type in LocationType.objects.all():
if self.job.debug:
self.job.logger.debug(f"Loading Nautobot LocationType: {nb_location_type}, with ID {nb_location_type.id}")
self.job.logger.debug(
f"Loading Nautobot LocationType: {nb_location_type}, with ID {nb_location_type.id}"
)
try:
self.get(self.location_type, nb_location_type.name)
except ObjectNotFound:
Expand Down