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

Ssot snow delete function #263

Merged
merged 6 commits into from
Apr 16, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
made minor changes for linting tests
  • Loading branch information
collin-wicker committed Nov 7, 2023
commit 9ecff49855a8f33ab710605ce85d2c7d194c6223
8 changes: 5 additions & 3 deletions nautobot_ssot/integrations/servicenow/diffsync/models.py
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ def map_data_to_sn_record(self, data, mapping_entry, existing_record=None, clear
column_name = mapping["reference"]["column"]
if value is not None:
# if clear_cache is set to True then clear the cache for the object
if clear_cache==True:
if clear_cache:
self._sys_id_cache.setdefault(tablename, {}).setdefault(column_name, {})[value] = {}
# Look in the cache first
sys_id = self._sys_id_cache.get(tablename, {}).get(column_name, {}).get(value, None)
@@ -85,7 +85,7 @@ def update(self, attrs):
return self

def delete(self):
"""Delete an existing instance in ServiceNow if it does not exist in Nautobot. This code adds the ServiceNow object to the objects_to_delete[object_class] list. The actual delete occurs in the post-run method of adapter_servicenow.py."""
"""Delete an existing instance in ServiceNow if it does not exist in Nautobot. This code adds the ServiceNow object to the objects_to_delete dict of lists. The actual delete occurs in the post-run method of adapter_servicenow.py."""
entry = self.diffsync.mapping_data[self.get_type()]
sn_resource = self.diffsync.client.resource(api_path=f"/table/{entry['table']}")
query = self.map_data_to_sn_record(data=self.get_identifiers(), mapping_entry=entry)
@@ -100,7 +100,9 @@ def delete(self):
self.diffsync.job.logger.warning(f"{self._modelname} {self.get_identifiers()} will be deleted.")
_object = sn_resource.get(query=query)
self.diffsync.objects_to_delete[self._modelname].append(_object)
self.map_data_to_sn_record(data=self.get_identifiers(), mapping_entry=entry, clear_cache=True) # remove device cache
self.map_data_to_sn_record(
data=self.get_identifiers(), mapping_entry=entry, clear_cache=True
) # remove device cache
super().delete()
return self