Update helpers.py to use netbox long / lat fields.

updated helper function get_device_location to use netbox's native location fields
This commit is contained in:
Seb Harrington 2024-04-20 21:25:38 +01:00 committed by GitHub
parent 03092bcf31
commit edada1df35
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -14,7 +14,10 @@ LatLon = tuple[float, float]
def get_device_location(device: Device) -> LatLon | None: def get_device_location(device: Device) -> LatLon | None:
"""Extract device geolocation from special custom field""" """If netbox longitude and latitude fields are populated for a device then use them."""
if device.longitude and device.latitude:
return (device.longitude, device.latitude)
"""... Otherwise extract device geolocation from special custom field"""
if location_cf := device.custom_field_data.get(LOCATION_CF_NAME): if location_cf := device.custom_field_data.get(LOCATION_CF_NAME):
return tuple(map(float, location_cf.replace(' ', '').split(',', maxsplit=1))) return tuple(map(float, location_cf.replace(' ', '').split(',', maxsplit=1)))