class OnboardingTask(BaseModel, ChangeLoggedModel):
"""The status of each onboarding Task is tracked in the OnboardingTask table."""
label = models.PositiveIntegerField(default=0, editable=False, help_text="Label for sorting tasks")
created_device = models.ForeignKey(to="dcim.Device", on_delete=models.SET_NULL, blank=True, null=True)
ip_address = models.CharField(max_length=255, help_text="primary ip address for the device", null=True)
site = models.ForeignKey(to="dcim.Site", on_delete=models.SET_NULL, blank=True, null=True)
role = models.ForeignKey(to="dcim.DeviceRole", on_delete=models.SET_NULL, blank=True, null=True)
device_type = models.CharField(
null=True, max_length=255, help_text="Device Type extracted from the device (optional)"
)
platform = models.ForeignKey(to="dcim.Platform", on_delete=models.SET_NULL, blank=True, null=True)
status = models.CharField(max_length=255, choices=OnboardingStatusChoices, help_text="Overall status of the task")
failed_reason = models.CharField(
max_length=255, choices=OnboardingFailChoices, help_text="Raison why the task failed (optional)", null=True
)
message = models.CharField(max_length=511, blank=True)
port = models.PositiveSmallIntegerField(help_text="Port to use to connect to the device", default=22)
timeout = models.PositiveSmallIntegerField(
help_text="Timeout period in sec to wait while connecting to the device", default=30
)
def __str__(self):
"""String representation of an OnboardingTask."""
return f"{self.site} | {self.ip_address}"
def get_absolute_url(self):
"""Provide absolute URL to an OnboardingTask."""
return reverse("plugins:nautobot_device_onboarding:onboardingtask", kwargs={"pk": self.pk})
def save(self, *args, **kwargs):
"""Overwrite method to get latest label value and update Task object."""
if not self.label:
latest_task = OnboardingTask.objects.all().order_by("-label").first()
self.label = (latest_task.label if latest_task else 0) + 1
super().save(*args, **kwargs)
objects = RestrictedQuerySet.as_manager()