feat!: report the subscription as a license, not a warning (0.4.0)
CI / test (3.10) (push) Successful in 33s
CI / test (3.11) (push) Successful in 30s
CI / test (3.12) (push) Successful in 35s
CI / test (3.10) (pull_request) Successful in 32s
CI / test (3.11) (pull_request) Successful in 31s
CI / test (3.12) (pull_request) Successful in 34s
CI / test (3.10) (push) Successful in 33s
CI / test (3.11) (push) Successful in 30s
CI / test (3.12) (push) Successful in 35s
CI / test (3.10) (pull_request) Successful in 32s
CI / test (3.11) (pull_request) Successful in 31s
CI / test (3.12) (pull_request) Successful in 34s
get_device_warnings is gone; netOrk names the warnings from facts (netOrk #1111). lldpd and the pending updates were already facts (get_packages, get_available_updates). The subscription is now get_licenses() from napalm-device-types 4.14's LicenseMixin: one pve-subscription entry, the API status mapped to a LicenseStatus. The old check compared against "NotFound" while the API answers "notfound" (seen on all four nodes), so it never fired; the mapping is case-insensitive.
This commit is contained in:
1 parent
8cf334aaf5
commit
1100560f85
5 files changed
+102
-43
No files matched your search
@@ -30,6 +30,15 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
_JsonDict = dict[str, Any]
|
||||
|
||||
#: The subscription API's status (lower-cased) as a napalm-device-types
|
||||
#: ``LicenseStatus``; "new" and "suspended" have none of their own.
|
||||
_SUBSCRIPTION_STATUS = {
|
||||
"notfound": "none",
|
||||
"active": "active",
|
||||
"invalid": "invalid",
|
||||
"expired": "expired",
|
||||
}
|
||||
|
||||
|
||||
_PACKAGE_NAME = re.compile(r"^[a-zA-Z0-9][a-zA-Z0-9_.+:~-]*$")
|
||||
#: What may stand in an snmpd.conf value: no whitespace, no quote, no comment.
|
||||
@@ -344,51 +353,29 @@ class ProxmoxSystemMixin:
|
||||
return result
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# Device warnings
|
||||
# Licenses (napalm-device-types' LicenseMixin)
|
||||
# ------------------------------------------------------------------ #
|
||||
|
||||
def get_device_warnings(self) -> list[_JsonDict]:
|
||||
"""Return warnings for the Proxmox node.
|
||||
def get_licenses(self) -> list[_JsonDict]:
|
||||
"""The node's subscription, as the API reports it.
|
||||
|
||||
Currently detects:
|
||||
- lldpd not installed (LLDP neighbor discovery unavailable)
|
||||
- Available package updates (via Proxmox APT API)
|
||||
- Missing / invalid subscription
|
||||
A fact for the caller: whether running without one is a problem is not
|
||||
the driver's to say. An unreadable subscription reports nothing.
|
||||
"""
|
||||
warnings: list[_JsonDict] = []
|
||||
|
||||
# 0. LLDP daemon
|
||||
try:
|
||||
lldpd_path = self._exec_ssh_command("command -v lldpd 2>/dev/null").strip()
|
||||
if not lldpd_path:
|
||||
warnings.append({"code": "lldpd_not_installed"})
|
||||
except Exception as exc:
|
||||
logger.debug("Failed to check for lldpd: %s", exc)
|
||||
|
||||
# 1. Available package updates
|
||||
try:
|
||||
updates = self.get_available_updates()
|
||||
if updates:
|
||||
warnings.append({
|
||||
"code": "updates_available",
|
||||
"meta": {
|
||||
"count": len(updates),
|
||||
"packages": [u["name"] for u in updates],
|
||||
},
|
||||
})
|
||||
except Exception as exc:
|
||||
logger.debug("Failed to check available updates: %s", exc)
|
||||
|
||||
# 2. Subscription status
|
||||
try:
|
||||
sub = self._get_node_subscription()
|
||||
status = sub.get("status", "")
|
||||
if status in ("NotFound", "Invalid", "Expired"):
|
||||
warnings.append({"code": "no_subscription", "meta": {"status": status}})
|
||||
except Exception as exc:
|
||||
logger.debug("Failed to check subscription status: %s", exc)
|
||||
|
||||
return warnings
|
||||
sub = self._get_node_subscription()
|
||||
raw = str(sub.get("status", ""))
|
||||
if not raw:
|
||||
return []
|
||||
lic: _JsonDict = {
|
||||
"name": "pve-subscription",
|
||||
"status": _SUBSCRIPTION_STATUS.get(raw.lower(), "unknown"),
|
||||
"detail": sub.get("message") or raw,
|
||||
}
|
||||
if sub.get("productname"):
|
||||
lic["edition"] = sub["productname"]
|
||||
if sub.get("nextduedate"):
|
||||
lic["expires"] = sub["nextduedate"]
|
||||
return [lic]
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# Services (systemd, through napalm-device-types' SystemdServicesMixin)
|
||||
|
||||
Reference in new issue
Block a user