From b3be1f3094dd78d640d70019829b262fd2fb9997 Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 10 Jul 2026 11:26:38 +0200 Subject: [PATCH] Make Proxmox version probe non-fatal --- COMPATIBILITY.md | 1 + README.md | 2 ++ netbox_vmware_importer/__init__.py | 2 +- netbox_vmware_importer/sync.py | 27 +++++++++++++++++++++------ pyproject.toml | 2 +- 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 455ab57..9be31c9 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -15,3 +15,4 @@ | 0.2.1 | 4.4.0 | 4.6.x | | 0.2.2 | 4.4.0 | 4.6.x | | 0.2.3 | 4.4.0 | 4.6.x | +| 0.2.4 | 4.4.0 | 4.6.x | diff --git a/README.md b/README.md index ff995e6..f3880e6 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,8 @@ Bei selbstsignierten Proxmox-Zertifikaten `Validate SSL` deaktiviert lassen. Wen Der Proxmox-Client ignoriert Proxy-Umgebungsvariablen des NetBox-Dienstes, damit interne Proxmox-Adressen nicht versehentlich ueber einen HTTPS-Proxy laufen. +Der unauthentifizierte Proxmox-`version`-Probe ist nur diagnostisch. Wenn er haengt, versucht das Plugin den eigentlichen Login trotzdem. + Wenn Passwort-Login auf `access/ticket` haengt, zuerst den Realm im Benutzernamen pruefen (`root@pam`, `user@pve`, `user@ldaprealm`). Fuer produktive Imports ist ein Proxmox API-Token meistens stabiler als Passwort-Login. Wenn `Sync interval minutes` gesetzt ist, prueft ein Systemjob alle fuenf Minuten, welche Endpoints faellig sind, und stellt die eigentlichen Sync-Jobs in die Queue. diff --git a/netbox_vmware_importer/__init__.py b/netbox_vmware_importer/__init__.py index b9f40d5..96fcf42 100644 --- a/netbox_vmware_importer/__init__.py +++ b/netbox_vmware_importer/__init__.py @@ -5,7 +5,7 @@ class VMwareImporterConfig(PluginConfig): name = "netbox_vmware_importer" verbose_name = "Virtualization Importer" description = "Synchronize VMware vSphere and Proxmox VE virtual machines into NetBox." - version = "0.2.3" + version = "0.2.4" author = "Internal NetBox Team" base_url = "vmware-importer" min_version = "4.4.0" diff --git a/netbox_vmware_importer/sync.py b/netbox_vmware_importer/sync.py index 4787abb..f789e04 100644 --- a/netbox_vmware_importer/sync.py +++ b/netbox_vmware_importer/sync.py @@ -244,6 +244,13 @@ class ProxmoxClient: self.session = requests.Session() self.session.trust_env = False self.session.verify = self.endpoint.validate_ssl + self.session.headers.update( + { + "Accept": "application/json", + "Connection": "close", + "User-Agent": "netbox-vm-import/0.2", + } + ) if not self.endpoint.validate_ssl and InsecureRequestWarning is not None: requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning) @@ -262,8 +269,13 @@ class ProxmoxClient: self.session.close() def _probe_api_availability(self): - self._request("GET", "version") - self.api_probe_succeeded = True + try: + self._request("GET", "version", timeout=(5, 10)) + self.api_probe_succeeded = True + self.api_probe_error = "" + except ProxmoxConnectionError as exc: + self.api_probe_succeeded = False + self.api_probe_error = str(exc) def _authenticate_with_password(self): response = self._request( @@ -288,20 +300,23 @@ class ProxmoxClient: def _url(self, path): return f"{self.base_url}/{path.strip('/')}" - def _request(self, method, path, **kwargs): + def _request(self, method, path, timeout=None, **kwargs): url = self._url(path) + request_timeout = timeout or self.timeout try: - response = self.session.request(method, url, timeout=self.timeout, **kwargs) + response = self.session.request(method, url, timeout=request_timeout, **kwargs) response.raise_for_status() return response except requests.ConnectTimeout as exc: raise ProxmoxConnectionError( - f"Proxmox API {method} {path} connect timed out after {self.timeout[0]} seconds." + f"Proxmox API {method} {path} connect timed out after {request_timeout[0]} seconds." ) from exc except requests.ReadTimeout as exc: - detail = f"Proxmox API {method} {path} read timed out after {self.timeout[1]} seconds." + detail = f"Proxmox API {method} {path} read timed out after {request_timeout[1]} seconds." if path == "access/ticket" and self.api_probe_succeeded: detail += " API version endpoint responded, so the delay is likely in Proxmox authentication. Check username realm (e.g. root@pam), PAM/LDAP auth, two-factor auth, or use an API token." + elif getattr(self, "api_probe_error", "") and path != "version": + detail += f" Earlier unauthenticated version probe also failed: {self.api_probe_error}" raise ProxmoxConnectionError(detail) from exc except requests.exceptions.SSLError as exc: raise ProxmoxConnectionError( diff --git a/pyproject.toml b/pyproject.toml index 3aa254c..d6938f3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "netbox-vmware-importer" -version = "0.2.3" +version = "0.2.4" description = "NetBox plugin to synchronize VMware vSphere and Proxmox VE virtual machines into NetBox." readme = "README.md" requires-python = ">=3.12"