Skip to content

Commit

Permalink
style: 🎨 fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
bile0026 committed Dec 18, 2024
1 parent 6a2cd6a commit 73cb825
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion nautobot_ssot/integrations/librenms/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
"cyberpower": "Cyberpower",
"opnsense": "Opnsense",
"epmp": "Cambium",
"tachyon": "Tachyon Networks"
"tachyon": "Tachyon Networks",
}
28 changes: 20 additions & 8 deletions nautobot_ssot/integrations/librenms/diffsync/adapters/librenms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@
from nautobot.dcim.models import Location, LocationType
from nautobot.extras.models import Status

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.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 (
is_running_tests,
normalize_gps_coordinates,
Expand Down Expand Up @@ -78,16 +84,18 @@ def load_device(self, device: dict):
new_device = self.device(
name=device[self.hostname_field],
device_id=device["device_id"],
location=device["location"] if device["location"] is not None else "Unknown",
location=(device["location"] if device["location"] is not None else "Unknown"),
role=device["type"] if device["type"] is not None else None,
serial_no=device["serial"] if device["serial"] is not None else "",
status=_status,
manufacturer=(
os_manufacturer_map.get(device["os"]) if os_manufacturer_map.get(device["os"]) is not None else "Unknown"
os_manufacturer_map.get(device["os"])
if os_manufacturer_map.get(device["os"]) is not None
else "Unknown"
),
device_type=device["hardware"] if device["hardware"] is not None else "Unknown",
device_type=(device["hardware"] if device["hardware"] is not None else "Unknown"),
platform=device["os"] if device["os"] is not None else "Unknown",
os_version=device["version"] if device["version"] is not None else "Unknown",
os_version=(device["version"] if device["version"] is not None else "Unknown"),
system_of_record=os.getenv("NAUTOBOT_SSOT_LIBRENMS_SYSTEM_OF_RECORD", "LibreNMS"),
)
self.add(new_device)
Expand Down Expand Up @@ -121,7 +129,11 @@ def load(self):
_site, _created = LocationType.objects.get_or_create(name="Site")
if _created:
_site.content_types.add(ContentType.objects.get(app_label="dcim", model="device"))
Location.objects.get_or_create(name="Unknown", location_type=_site, status=Status.objects.get(name="Active"))
Location.objects.get_or_create(
name="Unknown",
location_type=_site,
status=Status.objects.get(name="Active"),
)

if load_source != "file":
all_locations = self.lnms_api.get_librenms_locations()
Expand All @@ -133,4 +145,4 @@ def load(self):
for _location in all_locations["locations"]:
self.load_location(location=_location)
else:
self.job.logger.info('Location Sync Disabled. Skipping loading locations.')
self.job.logger.info("Location Sync Disabled. Skipping loading locations.")
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ def load(self):
"""Load data from Nautobot into DiffSync models."""
if self.job.sync_locations:
if self.job.debug:
self.job.logger.debug('Loading Nautobot Locations')
self.job.logger.debug("Loading Nautobot Locations")
self.load_location()

if self.job.debug:
self.job.logger.debug('Loading Nautobot Devices')
self.job.logger.debug("Loading Nautobot Devices")
self.load_device()
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ def create(cls, adapter, ids, attrs):
device_type=_device_type,
status=Status.objects.get_or_create(name=attrs["status"])[0],
role=ensure_role(role_name=attrs["role"], content_type=ORMDevice),
location=ORMLocation.objects.get(name=attrs["location"], location_type=LocationType.objects.get(name="Site")),
location=ORMLocation.objects.get(
name=attrs["location"], location_type=LocationType.objects.get(name="Site")
),
platform=_platform,
serial=attrs["serial_no"],
software_version=ensure_software_version(
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 @@ -4,7 +4,6 @@

from nautobot.core.signals import nautobot_database_ready
from nautobot.extras.choices import CustomFieldTypeChoices
from nautobot.dcim.models import LocationType

from nautobot_ssot.utils import create_or_update_custom_field

Expand Down
4 changes: 2 additions & 2 deletions nautobot_ssot/integrations/librenms/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def get_city_state_geocode(latitude: str, longitude: str):
geo_info.raise_for_status()
geo_json = geo_info.json()
city_info = {}
LOGGER.debug(f'Geocode response: {geo_json}')
LOGGER.debug(f"Geocode response: {geo_json}")
try:
if "Throttled!" not in geo_json.values() and isinstance(geo_json, dict):
if geo_json.get("statename"):
Expand All @@ -53,7 +53,7 @@ def get_city_state_geocode(latitude: str, longitude: str):
city_info["state"] = geo_json["osmtags"]["is_in_state"]
else:
city_info["state"] = "Unknown"
if geo_json.get("city") and 'Throttled!' not in geo_json["city"]:
if geo_json.get("city") and "Throttled!" not in geo_json["city"]:
city_info["city"] = geo_json["city"]
else:
city_info["city"] = "Unknown"
Expand Down

0 comments on commit 73cb825

Please sign in to comment.