diff --git a/nautobot_ssot/integrations/librenms/constants.py b/nautobot_ssot/integrations/librenms/constants.py index 2ede512b..a08b386b 100644 --- a/nautobot_ssot/integrations/librenms/constants.py +++ b/nautobot_ssot/integrations/librenms/constants.py @@ -23,5 +23,5 @@ "cyberpower": "Cyberpower", "opnsense": "Opnsense", "epmp": "Cambium", - "tachyon": "Tachyon Networks" + "tachyon": "Tachyon Networks", } diff --git a/nautobot_ssot/integrations/librenms/diffsync/adapters/librenms.py b/nautobot_ssot/integrations/librenms/diffsync/adapters/librenms.py index de7e27f6..01f034cf 100644 --- a/nautobot_ssot/integrations/librenms/diffsync/adapters/librenms.py +++ b/nautobot_ssot/integrations/librenms/diffsync/adapters/librenms.py @@ -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, @@ -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) @@ -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() @@ -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.") diff --git a/nautobot_ssot/integrations/librenms/diffsync/adapters/nautobot.py b/nautobot_ssot/integrations/librenms/diffsync/adapters/nautobot.py index 0743abfb..81f53af8 100644 --- a/nautobot_ssot/integrations/librenms/diffsync/adapters/nautobot.py +++ b/nautobot_ssot/integrations/librenms/diffsync/adapters/nautobot.py @@ -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() diff --git a/nautobot_ssot/integrations/librenms/diffsync/models/nautobot.py b/nautobot_ssot/integrations/librenms/diffsync/models/nautobot.py index b1b1842e..f96d6f30 100644 --- a/nautobot_ssot/integrations/librenms/diffsync/models/nautobot.py +++ b/nautobot_ssot/integrations/librenms/diffsync/models/nautobot.py @@ -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( diff --git a/nautobot_ssot/integrations/librenms/signals.py b/nautobot_ssot/integrations/librenms/signals.py index 76e7ab28..d9412fc4 100644 --- a/nautobot_ssot/integrations/librenms/signals.py +++ b/nautobot_ssot/integrations/librenms/signals.py @@ -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 diff --git a/nautobot_ssot/integrations/librenms/utils/__init__.py b/nautobot_ssot/integrations/librenms/utils/__init__.py index a282f4c0..0bfc7787 100644 --- a/nautobot_ssot/integrations/librenms/utils/__init__.py +++ b/nautobot_ssot/integrations/librenms/utils/__init__.py @@ -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"): @@ -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"