nautobot-app-ssot icon indicating copy to clipboard operation
nautobot-app-ssot copied to clipboard

Pass action value to `lookup_object` method to allow for conditional lookup based on action type

Open progala opened this issue 3 years ago • 2 comments

Environment

  • Nautobot version: 1.2.8
  • nautobot-ssot version: 1.1.2

Proposed Functionality

As a plugin developer I would like to be able to conditionally look up objects based on the action type applied to given diffsync record.

Use Case

As a plugin developer I want to specify that the object lookup should not happen for records that were deleted. I only want to perform object lookup for records that were created or updated.

progala avatar May 19 '22 15:05 progala

Any chance you can provide an actual example?

itdependsnetworks avatar May 23 '22 12:05 itdependsnetworks

Sure. I have a try-except in the lookup_object method where I log job warning message when lookup fails. But without knowing the type of action that trigerred the lookup I don't know if the lookup failure is genuine (create, update) or expected (delete).

If I knew the action type I could log warnings for genuine failures only. Right now each lookup failure for deleted objects will generate the warning message.

  try:
      return getattr(NautobotDiffSync, model_name)._nautobot_model.objects.get(
          _custom_field_data__netbox_id=int(unique_id)
      )
  except ObjectDoesNotExist:
      self.log_warning(message=lookup_failure_message)

progala avatar May 26 '22 09:05 progala