fix(facts): read the host name from the gateway's System page
driver / standard (pull_request) Successful in 16s
driver / lint (pull_request) Successful in 13s
driver / types (pull_request) Successful in 1m8s
driver / test (3.13) (pull_request) Successful in 1m5s
driver / test (3.12) (pull_request) Successful in 1m5s
driver / lowest (pull_request) Successful in 25s
driver / build (pull_request) Successful in 29s
driver / security (pull_request) Successful in 1m15s
CI / driver (pull_request) Successful in 2m37s
driver / publish (pull_request) Skipped

get_facts read HostName from getBasicInformation, which a VMG4005-B50A
does not send, and fell back to the address the driver connects to:
netOrk kept the gateway named 192.168.1.1. The gateway's own System page
reads host name and domain with GET /cgi-bin/System?oid=snmp, sealed like
a DAL answer; get_facts now reads them there. fqdn is the host name with
its domain. A gateway with no name set reports "", and get_facts raises
when the System page cannot be read.
This commit is contained in:
Christian Manivong committed 2026-11-12 16:42:47 +01:00
1 parent ca67c08736
commit 61a6e4f7ba
5 files changed
+149 -5

No files matched your search

+31 -3
View File
@@ -152,6 +152,7 @@ class ZyxelVMGDriver(ResidentialGatewayDriver):
_RSA_KEY_PATH = "getRSAPublickKey"
_BASIC_INFO_PATH = "getBasicInformation"
_DAL_PATH = "cgi-bin/DAL"
_SYSTEM_PATH = "cgi-bin/System?oid=snmp"
#: Discovery also fetches the DAL's key exchange, which answers without a login
#: (``open()`` needs it). The port answering is no evidence; the answer is (#13).
@@ -351,20 +352,47 @@ class ZyxelVMGDriver(ResidentialGatewayDriver):
return parse_page(self._fetch_page(page))
def get_facts(self) -> dict[str, Any]:
"""Return device facts such as model, serial, OS version, and uptime."""
"""Return device facts such as model, serial, OS version, and uptime.
The host name and domain are the ones on the gateway's System page;
``getBasicInformation`` does not carry them.
"""
info = self._device_info or {}
iface_list = list(self.get_interfaces().keys())
hostname, domain = self._system_name()
return {
"vendor": self.VENDOR,
"model": info.get("ModelName", ""),
"serial_number": info.get("SerialNumber", ""),
"os_version": info.get("SoftwareVersion", ""),
"hostname": info.get("HostName", self.hostname),
"fqdn": self.hostname,
"hostname": hostname,
"fqdn": f"{hostname}.{domain}" if hostname and domain else hostname,
"uptime": int(info.get("SystemUpTime", 0) or 0),
"interface_list": iface_list,
}
def _system_name(self) -> tuple[str, str]:
"""The gateway's host name and domain, as its System page reads them
(``GET /cgi-bin/System?oid=snmp``); raises when they cannot be read.
The answer is a one-entry list, sealed ``{"content", "iv"}`` like a DAL answer.
"""
text = self._fetch_page(self._SYSTEM_PATH)
if self._crypto is None:
raise ConnectionClosedException("Not connected")
try:
answer = json.loads(text)
if isinstance(answer, dict) and {"content", "iv"} <= answer.keys():
answer = self._crypto.decrypt_response(answer)
except (ValueError, TypeError, KeyError) as exc:
raise RuntimeError(f"{self._SYSTEM_PATH} on {self._base_url}: {exc}") from exc
if not isinstance(answer, list) or not answer or not isinstance(answer[0], dict):
raise RuntimeError(f"{self._SYSTEM_PATH} on {self._base_url} answered {answer!r}")
hostname, domain = (
str(answer[0].get(key) or "").strip() for key in ("HostName", "DomainName")
)
return hostname, domain
def _status_page(self) -> dict[str, Any]:
"""The DAL's ``cardpage_status``, decrypted; raises when it cannot be read.