feat: report the firmware Netgear offers, not a warning (0.4.0)
CI / test (3.10) (push) Failing after 16s
CI / test (3.11) (push) Successful in 23s
CI / test (3.12) (push) Successful in 26s
CI / test (3.10) (pull_request) Successful in 25s
CI / test (3.11) (pull_request) Successful in 23s
CI / test (3.12) (pull_request) Successful in 24s
CI / test (3.10) (push) Failing after 16s
CI / test (3.11) (push) Successful in 23s
CI / test (3.12) (push) Successful in 26s
CI / test (3.10) (pull_request) Successful in 25s
CI / test (3.11) (pull_request) Successful in 23s
CI / test (3.12) (pull_request) Successful in 24s
The Plus driver looked the newest firmware up in Netgear's download catalogue and named firmware_update_available itself. It now reports get_firmware_offer() (napalm-device-types 4.16 FirmwareOfferMixin): what runs, the newest offered, whether that is newer by Netgear's versioning, and the download link; netOrk names the warning (netOrk #1111). The Smart driver's empty get_device_warnings goes too. Requires napalm-device-types 4.16.0.
This commit is contained in:
1 parent
ff86370f2f
commit
c8c9642af0
5 files changed
+81
-47
No files matched your search
@@ -26,7 +26,7 @@ import threading
|
||||
import time
|
||||
from typing import Any
|
||||
|
||||
from napalm_device_types import FingerprintRule, SwitchDriver
|
||||
from napalm_device_types import FingerprintRule, FirmwareOfferMixin, SwitchDriver
|
||||
from napalm.base.exceptions import ConnectionException
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -144,7 +144,7 @@ def _fw_get_latest(model: str) -> str | None:
|
||||
return latest
|
||||
|
||||
|
||||
class NetgearPlusDriver(SwitchDriver):
|
||||
class NetgearPlusDriver(FirmwareOfferMixin, SwitchDriver):
|
||||
"""HTTP-based NAPALM driver for Netgear Plus Smart Managed switches."""
|
||||
|
||||
VENDOR = "Netgear"
|
||||
@@ -753,50 +753,29 @@ class NetgearPlusDriver(SwitchDriver):
|
||||
Returns None to indicate SNMP health monitoring is not supported."""
|
||||
return None
|
||||
|
||||
def get_device_warnings(self) -> list:
|
||||
"""Check for available firmware updates and return a warning if the
|
||||
device is not running the latest known firmware.
|
||||
def get_firmware_offer(self) -> dict | None:
|
||||
"""The firmware running and the newest Netgear offers for this model.
|
||||
|
||||
The latest version is looked up once per 24 hours (per model, per
|
||||
worker process) via lightweight HEAD requests against Netgear's
|
||||
download CDN. Returns an empty list when the model is unknown or
|
||||
when the check fails.
|
||||
The newest is looked up once per 24 hours (per model, per worker
|
||||
process) with HEAD requests against Netgear's download CDN. None when
|
||||
the model is unknown, a version cannot be read or compared, or the
|
||||
check fails. Whether an older firmware is a warning is the caller's to
|
||||
decide (napalm-device-types ``FirmwareOfferMixin``).
|
||||
"""
|
||||
warnings: list = []
|
||||
try:
|
||||
model_name: str = getattr(
|
||||
self._connector.switch_model, "MODEL_NAME", ""
|
||||
) or self._connector.switch_model.__class__.__name__
|
||||
current_fw: str = self._get_switch_infos().get("switch_firmware", "")
|
||||
|
||||
if not model_name or not current_fw:
|
||||
return warnings
|
||||
|
||||
latest_fw = _fw_get_latest(model_name)
|
||||
latest_fw = _fw_get_latest(model_name) if model_name and current_fw else None
|
||||
if latest_fw is None:
|
||||
return warnings
|
||||
|
||||
try:
|
||||
current_t = _fw_version_tuple(current_fw)
|
||||
latest_t = _fw_version_tuple(latest_fw)
|
||||
except ValueError:
|
||||
return warnings
|
||||
|
||||
if latest_t > current_t:
|
||||
warnings.append(
|
||||
{
|
||||
"code": "firmware_update_available",
|
||||
"meta": {
|
||||
"download_url": (
|
||||
f"{_FW_CDN_BASE}/{model_name}"
|
||||
f"/{model_name}_{latest_fw}.zip"
|
||||
),
|
||||
"latest_version": latest_fw,
|
||||
"current_version": current_fw,
|
||||
},
|
||||
}
|
||||
)
|
||||
return None
|
||||
newer = _fw_version_tuple(latest_fw) > _fw_version_tuple(current_fw)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return warnings
|
||||
return None
|
||||
return {
|
||||
"current_version": current_fw,
|
||||
"latest_version": latest_fw,
|
||||
"newer": newer,
|
||||
"download_url": f"{_FW_CDN_BASE}/{model_name}/{model_name}_{latest_fw}.zip",
|
||||
}
|
||||
Reference in new issue
Block a user