Skip to content
Open
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
1 change: 1 addition & 0 deletions changes/339.housekeeping
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Refactor `Sources.py` into a `sources` module with different files.
2 changes: 1 addition & 1 deletion nautobot_circuit_maintenance/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class CircuitMaintenanceFilterForm(NautobotFilterForm):
end_time = forms.DateTimeField(label="End time before", required=False, widget=DateTimePicker())


class CircuitMaintenanceBulkEditForm(TagsBulkEditFormMixin, NautobotBulkEditForm):
class CircuitMaintenanceBulkEditForm(NautobotBulkEditForm, TagsBulkEditFormMixin):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this not working properly?

"""Form for bulk editing Circuit Maintenances."""

pk = forms.ModelMultipleChoiceField(queryset=CircuitMaintenance.objects.all(), widget=forms.MultipleHiddenInput)
Expand Down
30 changes: 23 additions & 7 deletions nautobot_circuit_maintenance/handle_notifications/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
import uuid
from typing import List, Optional

from circuit_maintenance_parser import Maintenance, NotificationData, ProviderError, init_provider
from circuit_maintenance_parser import (
Maintenance,
NotificationData,
ProviderError,
init_provider,
)
from dateutil import parser
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
Expand All @@ -28,7 +33,8 @@
RawNotification,
)

from .sources import MaintenanceNotification, get_notifications
from .sources import get_notifications
from .sources.maintenance_notification import MaintenanceNotification
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this importable from .sources?


name = "Circuit Maintenance" # pylint: disable=invalid-name

Expand Down Expand Up @@ -62,7 +68,9 @@ def create_circuit_maintenance(
circuit_entry = Circuit.objects.filter(cid__iexact=circuit.circuit_id, provider=provider).last()
if circuit_entry:
circuit_impact_entry, created = CircuitImpact.objects.get_or_create(
maintenance=circuit_maintenance_entry, circuit=circuit_entry, defaults={"impact": circuit.impact}
maintenance=circuit_maintenance_entry,
circuit=circuit_entry,
defaults={"impact": circuit.impact},
)
if created:
job.logger.info(
Expand All @@ -88,7 +96,8 @@ def create_circuit_maintenance(

if not CircuitImpact.objects.filter(maintenance=circuit_maintenance_entry):
job.logger.warning(
"Circuit Maintenance has none Circuit IDs in the DB.", extra={"object": circuit_maintenance_entry}
"Circuit Maintenance has none Circuit IDs in the DB.",
extra={"object": circuit_maintenance_entry},
)

return circuit_maintenance_entry
Expand Down Expand Up @@ -233,7 +242,8 @@ def get_maintenances_from_notification(job: Job, notification: MaintenanceNotifi
parser_provider = init_provider(provider_type=provider_type)
if not parser_provider:
job.logger.warning(
f"Notification Parser not found for {notification.provider_type}", extra={"object": notification}
f"Notification Parser not found for {notification.provider_type}",
extra={"object": notification},
)
notification.source.tag_message(job, notification.msg_id, MessageProcessingStatus.PARSING_FAILED)
return None
Expand Down Expand Up @@ -291,7 +301,10 @@ def create_raw_notification(
stamp=parser.parse(notification.date),
)
# If the RawNotification was already created, we ignore it.
job.logger.debug(f"Raw notification already existed with ID: {raw_entry.id}", extra={"object": raw_entry})
job.logger.debug(
f"Raw notification already existed with ID: {raw_entry.id}",
extra={"object": raw_entry},
)
return None
except ObjectDoesNotExist:
try:
Expand Down Expand Up @@ -384,7 +397,10 @@ def get_since_reference(job: Job) -> int:
days=PLUGIN_SETTINGS.get("raw_notification_initial_days_since")
)
since_reference = int(since_reference.timestamp())
job.logger.info(f"Processing notifications since {since_reference}", extra={"object": last_raw_notification})
job.logger.info(
f"Processing notifications since {since_reference}",
extra={"object": last_raw_notification},
)
return since_reference


Expand Down
Loading
Loading