Skip to content

Commit cec515f

Browse files
authored
#703 Handle "Failed to establish connection to NetBox" on older NetBox versions (#707)
* Add try/except for full version check
1 parent 53c04ca commit cec515f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

plugins/module_utils/netbox_utils.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,11 @@ def __init__(self, module, endpoint, nb_client=None):
591591
self.nb = nb_client
592592
try:
593593
self.version = self.nb.version
594-
self.full_version = self.nb.status().get("netbox-version")
594+
try:
595+
self.full_version = self.nb.status().get("netbox-version")
596+
except Exception:
597+
# For NetBox versions without /api/status endpoint
598+
self.full_version = f"{self.version}.0"
595599
except AttributeError:
596600
self.module.fail_json(msg="Must have pynetbox >=4.1.0")
597601

@@ -640,7 +644,11 @@ def _connect_netbox_api(self, url, token, ssl_verify, cert):
640644
nb.http_session = session
641645
try:
642646
self.version = nb.version
643-
self.full_version = nb.status().get("netbox-version")
647+
try:
648+
self.full_version = nb.status().get("netbox-version")
649+
except Exception:
650+
# For NetBox versions without /api/status endpoint
651+
self.full_version = f"{self.version}.0"
644652
except AttributeError:
645653
self.module.fail_json(msg="Must have pynetbox >=4.1.0")
646654
except Exception:

0 commit comments

Comments
 (0)