Skip to content

Commit

Permalink
Merge pull request #560 from nautobot/servicenow-nautobot2
Browse files Browse the repository at this point in the history
SSoT ServiceNow fixes and updates for Nautobot 2.0
  • Loading branch information
jdrew82 authored Nov 20, 2024
2 parents 70cb12f + e039a96 commit f781498
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions changes/449.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `delete_records` flag to the ServiceNow DataTarget job
1 change: 1 addition & 0 deletions changes/449.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix logic used for loading location records to make ServiceNow SSoT Nautobot 2.x compatible
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def load_locations(self):
ancestor = self.site_filter.parent
while ancestor is not None:
locations.insert(0, ancestor)
ancestor = ancestor.parent
else:
locations = Location.objects.all()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def load(self):
# Load all Nautobot ancestor records as well
# This is so in case the Nautobot ancestors exist in ServiceNow but aren't linked to the record,
# we link them together instead of creating new, redundant ancestor records in ServiceNow.
ancestor = self.site_filter.region
ancestor = self.site_filter.parent
while ancestor is not None:
try:
self.get(self.location, ancestor.name)
Expand Down
8 changes: 6 additions & 2 deletions nautobot_ssot/integrations/servicenow/jobs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""ServiceNow Data Target Job."""

from diffsync.enum import DiffSyncFlags
from django.core.exceptions import ObjectDoesNotExist
from django.templatetags.static import static
from django.urls import reverse
Expand All @@ -16,7 +17,7 @@
name = "SSoT - ServiceNow" # pylint: disable=invalid-name


class ServiceNowDataTarget(DataTarget, Job): # pylint: disable=abstract-method
class ServiceNowDataTarget(DataTarget, Job): # pylint: disable=abstract-method, too-many-instance-attributes
"""Job syncing data from Nautobot to ServiceNow."""

debug = BooleanVar(description="Enable for more verbose logging.")
Expand Down Expand Up @@ -79,11 +80,14 @@ def load_target_adapter(self):
self.target_adapter = ServiceNowDiffSync(client=snc, job=self, sync=self.sync, site_filter=self.site_filter)
self.target_adapter.load()

def run(self, dryrun, memory_profiling, site_filter, *args, **kwargs): # pylint:disable=arguments-differ
def run(self, dryrun, memory_profiling, delete_records, site_filter, *args, **kwargs): # pylint:disable=arguments-differ
"""Run sync."""
self.dryrun = dryrun
self.memory_profiling = memory_profiling
self.site_filter = site_filter
self.delete_records = delete_records
if not self.delete_records:
self.diffsync_flags |= DiffSyncFlags.SKIP_UNMATCHED_DST
super().run(dryrun, memory_profiling, *args, **kwargs)

def lookup_object(self, model_name, unique_id):
Expand Down

0 comments on commit f781498

Please sign in to comment.