Skip to content

Commit

Permalink
revamps SSoT cookie for contrib pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Kircheneer committed Dec 10, 2024
1 parent e9b4d0c commit 127f1d9
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 145 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Diffsync components for {{ cookiecutter.app_name }}."""
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""{{ cookiecutter.verbose_name }} Adapter for {{ cookiecutter.system_of_record }} SSoT app."""
"""Diffsync adapters for {{ cookiecutter.app_name }}."""

from diffsync import Adapter

from {{ cookiecutter.app_name }}.diffsync.models.{{ cookiecutter.system_of_record_slug }} import {{ cookiecutter.system_of_record_camel }}Device
from {{ cookiecutter.app_name }}.diffsync.models import DiffsyncDevice


class {{ cookiecutter.system_of_record_camel }}Adapter(Adapter):
class {{ cookiecutter.system_of_record_camel }}RemoteAdapter(Adapter):
"""DiffSync adapter for {{ cookiecutter.system_of_record }}."""

device = {{ cookiecutter.system_of_record_camel }}Device
device = DiffsyncDevice

top_level = ["device"]

Expand All @@ -28,3 +28,11 @@ def __init__(self, *args, job=None, sync=None, client=None, **kwargs):
def load(self):
"""Load data from {{ cookiecutter.system_of_record }} into DiffSync models."""
raise NotImplementedError


class {{ cookiecutter.system_of_record_camel }}NautobotAdapter(NautobotAdapter):
"""DiffSync adapter for Nautobot."""

device = NautobotDevice

top_level = ["device"]

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Diffsync models for {{ cookiecutter.app_name }}."""
from typing import Optional, Annotated

from nautobot.dcim.models import Device
from nautobot_ssot.contrib import CustomFieldAnnotation, NautobotModel


class DiffsyncDevice(NautobotModel):
"""DiffSync model for {{ cookiecutter.system_of_record }} devices."""

_model = Device
_modelname = "device"
_identifiers = ("name",)
_attributes = (
"status__name",
"role__name",
"device_type__name",
"location__name",
"example_custom_field"
)

name: str
status__name: Optional[str] = None
role__name: Optional[str] = None
device_type__name: Optional[str] = None
location__name: Optional[str] = None
ip_address: Optional[str] = None
example_custom_field: Annotated[str, CustomFieldAnnotation(key="my_example_custom_field")]

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from nautobot.apps.jobs import BooleanVar, register_jobs
from nautobot_ssot.jobs.base import DataSource, DataTarget

from {{ cookiecutter.app_name }}.diffsync.adapters import {{ cookiecutter.system_of_record_slug }}, nautobot

from {{ cookiecutter.app_name }}.diffsync.adapters import {{ cookiecutter.system_of_record_camel }}RemoteAdapter, {{ cookiecutter.system_of_record_camel }}NautobotAdapter

name = "{{ cookiecutter.system_of_record }} SSoT" # pylint: disable=invalid-name

Expand Down

0 comments on commit 127f1d9

Please sign in to comment.