mirror of
https://github.com/bb-Ricardo/netbox-sync.git
synced 2026-05-08 11:00:12 -05:00
enhances NetBox version detection #446
This commit is contained in:
@@ -196,15 +196,29 @@ class NetBoxHandler:
|
||||
str: NetBox API version
|
||||
"""
|
||||
response = None
|
||||
result = None
|
||||
|
||||
try:
|
||||
response = self.session.get(
|
||||
self.url,
|
||||
f"{self.url}/status",
|
||||
timeout=self.settings.timeout,
|
||||
verify=self.settings.validate_tls_certs)
|
||||
except Exception as e:
|
||||
do_error_exit(f"NetBox connection: {e}")
|
||||
|
||||
result = str(response.headers.get("API-Version"))
|
||||
# noinspection PyBroadException
|
||||
try:
|
||||
result = grab(response.json(), "netbox-version").split("-")[0]
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if not isinstance(result, str):
|
||||
result = str(response.headers.get("API-Version"))
|
||||
|
||||
try:
|
||||
version.parse(result)
|
||||
except Exception as e:
|
||||
do_error_exit(f"Unable to parse NetBox version '{result}': {e}")
|
||||
|
||||
log.info(f"Successfully connected to NetBox '{self.settings.host_fqdn}'")
|
||||
log.debug(f"Detected NetBox API version: {result}")
|
||||
|
||||
Reference in New Issue
Block a user