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

revamps SSoT cookie for contrib pattern #203

Merged
merged 2 commits into from
Dec 18, 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
6 changes: 5 additions & 1 deletion nautobot-app-ssot/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
"system_of_record": "System of Record",
"system_of_record_camel": "{{ cookiecutter.system_of_record.title().replace(' ', '').replace('_', '').replace('-', '') }}",
"system_of_record_slug": "{{ cookiecutter.system_of_record.lower().replace(' ', '_').replace('-', '_') }}",
"model_class_name": "None",
"direction_of_sync": [
"To Nautobot",
"From Nautobot"
],
"app_name": "nautobot_ssot_{{ cookiecutter.system_of_record.lower().replace(' ', '_').replace('-', '_') }}",
"verbose_name": "{{ cookiecutter.app_name.title().replace('_', ' ') }}",
"app_slug": "{{ cookiecutter.app_name.lower().replace(' ', '-').replace('_', '-') }}",
Expand All @@ -16,7 +21,6 @@
"max_nautobot_version": "2.9999",
"camel_name": "{{ cookiecutter.app_slug.title().replace(' ', '').replace('-', '') }}",
"project_short_description": "{{ cookiecutter.verbose_name }}",
"model_class_name": "None",
"open_source_license": [
"Apache-2.0",
"Not open source"
Expand Down
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 @@ -27,4 +27,18 @@ 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
raise NotImplementedError()


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

device = NautobotDevice

top_level = ["device"]

{% if cookiecutter.direction_of_sync == "From Nautobot" %}
def load(self):
"""Load data from Nautobot into DiffSync models."""
raise NotImplementedError()
{% endif %}

This file was deleted.

This file was deleted.

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

{% if cookiecutter.direction_of_sync == "From Nautobot" %}
from diffsync import DiffSyncModel
{% endif %}
from nautobot.dcim.models import Device
{% if cookiecutter.direction_of_sync == "To Nautobot" %}
from nautobot_ssot.contrib import CustomFieldAnnotation, NautobotModel
{% endif %}

class DeviceSSoTModel({{ "NautobotModel" if cookiecutter.direction_of_sync == "To Nautobot" else "DiffSyncModel" }}):
"""SSoT model for {{ cookiecutter.system_of_record }} devices."""

{% if cookiecutter.direction_of_sync == "To Nautobot" %}_model = Device{% endif %}
_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")]
{% if cookiecutter.direction_of_sync == "From Nautobot" %}
@classmethod
def create(cls, adapter, ids, attrs):
"""Create device in {{ cookiecutter.system_of_record }}."""
raise NotImplementedError("Device creation is not implemented.")

def update(self, attrs):
"""Update device in {{ cookiecutter.system_of_record }}."""
raise NotImplementedError("Device updates are not implemented.")

def delete(self):
"""Delete device in {{ cookiecutter.system_of_record }}."""
raise NotImplementedError("Device deletion is not implemented.")
{% endif %}

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