Skip to content

Commit

Permalink
style: 🎨 formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bile0026 committed Dec 13, 2024
1 parent 143ca45 commit bad8734
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

from diffsync import DiffSync
from diffsync.exceptions import ObjectNotFound
from django.core.exceptions import ValidationError

from nautobot_ssot.integrations.librenms.constants import librenms_status_map, os_manufacturer_map
from nautobot_ssot.integrations.librenms.diffsync.models.librenms import LibrenmsDevice, LibrenmsLocation
from nautobot_ssot.integrations.librenms.utils import get_city_state_geocode, normalize_gps_coordinates, is_running_tests
from nautobot_ssot.integrations.librenms.utils import (
get_city_state_geocode,
is_running_tests,
normalize_gps_coordinates,
)
from nautobot_ssot.integrations.librenms.utils.librenms import LibreNMSApi


Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,16 @@
"""Nautobot Adapter for LibreNMS SSoT app."""

import os

from collections import defaultdict
from typing import Optional

from diffsync import DiffSync
from diffsync.enum import DiffSyncModelFlags
from diffsync.exceptions import ObjectNotFound
from django.core.exceptions import ValidationError
from django.db.models import ProtectedError
from django.db.utils import IntegrityError
from nautobot.dcim.models import Device as OrmDevice
from nautobot.dcim.models import Interface as OrmInterface
from nautobot.dcim.models import Location as OrmLocation
from nautobot.dcim.models import LocationType as OrmLocationType
from nautobot.extras.models import Relationship as OrmRelationship
from nautobot.extras.models import RelationshipAssociation as OrmRelationshipAssociation
from nautobot.extras.models import Status as OrmStatus
from nautobot.ipam.models import IPAddress as OrmIPAddress
from nautobot.ipam.models import IPAddressToInterface as OrmIPAddressToInterface
from nautobot.ipam.models import Namespace
from nautobot.ipam.models import Prefix as OrmPrefix
from nautobot.tenancy.models import Tenant as OrmTenant

from nautobot_ssot.integrations.librenms.utils import check_sor_field, get_sor_field_nautobot_object
from nautobot_ssot.integrations.librenms.diffsync.models.nautobot import (
NautobotDevice,
NautobotLocation,
)
from nautobot_ssot.jobs.base import DataTarget
from nautobot_ssot.integrations.librenms.utils import check_sor_field, get_sor_field_nautobot_object


class NautobotAdapter(DiffSync):
Expand Down
19 changes: 10 additions & 9 deletions nautobot_ssot/integrations/librenms/diffsync/models/nautobot.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
"""Nautobot DiffSync models for LibreNMS SSoT."""

from datetime import datetime
import os
from datetime import datetime

from django.contrib.contenttypes.models import ContentType

from nautobot.dcim.models import Device as ORMDevice
from nautobot.dcim.models import DeviceType, LocationType
from nautobot.dcim.models import Interface as ORMInterface
from nautobot.dcim.models import Location as ORMLocation
from nautobot.dcim.models import LocationType, DeviceType
from nautobot.dcim.models import Manufacturer as ORMManufacturer
from nautobot.dcim.models import Platform as ORMPlatform
from nautobot.dcim.models import SoftwareVersion as ORMSoftwareVersion
from nautobot.dcim.models import SoftwareImageFile as ORMSoftwareImageFile
from nautobot.extras.models import Status, Role
from nautobot_ssot.integrations.librenms.diffsync.models.base import Device, Location, Port
from nautobot.dcim.models import SoftwareVersion as ORMSoftwareVersion
from nautobot.extras.models import Role, Status

from nautobot_ssot.integrations.librenms.constants import os_manufacturer_map
from nautobot_ssot.integrations.librenms.utils.nautobot import add_software_lcm, assign_version_to_device, verify_platform
from nautobot_ssot.integrations.librenms.utils import get_city_state_geocode, check_sor_field
from nautobot_ssot.integrations.librenms.diffsync.models.base import Device, Location, Port
from nautobot_ssot.integrations.librenms.utils import check_sor_field, get_city_state_geocode
from nautobot_ssot.integrations.librenms.utils.nautobot import (
verify_platform,
)


def ensure_location(location_name: str, content_type, location_type_name: str = "Site"):
Expand Down Expand Up @@ -108,7 +109,7 @@ def update(self, attrs):
location.longitude = attrs["longitude"]
if "status" in attrs:
location.status = Status.objects.get(name=attrs["status"])
if "parent" in attrs and location.parent.name is not "Unknown":
if "parent" in attrs and location.parent.name != "Unknown":
location.parent = ensure_location(
location_name=attrs["parent"], content_type=ORMDevice, location_type_name="Region"
)
Expand Down
2 changes: 1 addition & 1 deletion nautobot_ssot/integrations/librenms/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os

from django.templatetags.static import static
from nautobot.apps.jobs import BooleanVar, ObjectVar, ChoiceVar
from nautobot.apps.jobs import BooleanVar, ChoiceVar, ObjectVar
from nautobot.core.celery import register_jobs
from nautobot.extras.choices import (
SecretsGroupAccessTypeChoices,
Expand Down
1 change: 0 additions & 1 deletion nautobot_ssot/integrations/librenms/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import importlib.util

from django.conf import settings
from nautobot.core.signals import nautobot_database_ready
from nautobot.extras.choices import CustomFieldTypeChoices

Expand Down
2 changes: 1 addition & 1 deletion nautobot_ssot/integrations/librenms/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def get_city_state_geocode(latitude: str, longitude: str):
# unauthenticated api limited to 1 request per second
time.sleep(2)
url = f"https://geocode.xyz/{latitude},{longitude}?json=1"
geo_info = requests.request(url=url, method="GET")
geo_info = requests.request(url=url, method="GET", timeout=30)
geo_info.raise_for_status()
geo_json = geo_info.json()
try:
Expand Down
5 changes: 2 additions & 3 deletions nautobot_ssot/integrations/librenms/utils/nautobot.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""Utility functions for working with Nautobot."""

"""Utility functions for working with Nautobot."""

from uuid import UUID

from django.contrib.contenttypes.models import ContentType
from netutils.lib_mapper import ANSIBLE_LIB_MAPPER_REVERSE, NAPALM_LIB_MAPPER_REVERSE
from nautobot.dcim.models import Device, Platform
from nautobot.extras.models import Relationship, RelationshipAssociation
from netutils.lib_mapper import ANSIBLE_LIB_MAPPER_REVERSE, NAPALM_LIB_MAPPER_REVERSE

try:
from nautobot_device_lifecycle_mgmt.models import SoftwareLCM
Expand Down
3 changes: 1 addition & 2 deletions nautobot_ssot/tests/librenms/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
from django.contrib.auth import get_user_model
from django.test import TestCase
from django.urls import reverse
from nautobot.users.models import Token
from rest_framework import status
from rest_framework.test import APIClient

from nautobot.users.models import Token

User = get_user_model()


Expand Down
3 changes: 2 additions & 1 deletion nautobot_ssot/tests/librenms/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Basic tests that do not require Django."""

import unittest
import os
import unittest

import toml


Expand Down
7 changes: 4 additions & 3 deletions nautobot_ssot/tests/librenms/test_librenms_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
from unittest.mock import MagicMock

from django.contrib.contenttypes.models import ContentType
from nautobot.extras.models import Job, JobResult
from nautobot.core.testing import TransactionTestCase
from nautobot_ssot_librenms.diffsync.adapters.librenms import LibrenmsAdapter
from nautobot_ssot_librenms.jobs import LibrenmsDataSource
from nautobot.extras.models import Job, JobResult

from nautobot_ssot.integrations.librenms.diffsync.adapters.librenms import LibrenmsAdapter
from nautobot_ssot.integrations.librenms.jobs import LibrenmsDataSource


def load_json(path):
Expand Down

0 comments on commit bad8734

Please sign in to comment.