diff --git a/napalm_opnsense/opnsense.py b/napalm_opnsense/opnsense.py index 4769975..0ee1c94 100644 --- a/napalm_opnsense/opnsense.py +++ b/napalm_opnsense/opnsense.py @@ -2454,15 +2454,21 @@ class OPNsenseDriver( time.sleep(5) # the install settles before its API answers return {"ok": result.get("status") == "ok", "output": f"os-net-snmp install: {result}"} - def _write_snmp_agent_config(self, settings: SnmpAgentSettingsDict) -> FixStepOutcomeDict: - community = settings["community"] + @staticmethod + def _check_snmp_community(community: str) -> None: if not community or any(c.isspace() or c in '"#' for c in community): raise ValueError("the community must be one word without quotes or #") - listen = settings.get("listen") or self.hostname + + def _snmp_listen_address(self, settings: SnmpAgentSettingsDict) -> str: try: - listen_val = str(ipaddress.ip_address(listen)) + return str(ipaddress.ip_address(settings.get("listen") or self.hostname)) except ValueError: - listen_val = "" # a DNS name binds nothing; snmpd then listens everywhere + return "" # a DNS name binds nothing; snmpd then listens everywhere + + def _write_snmp_agent_config(self, settings: SnmpAgentSettingsDict) -> FixStepOutcomeDict: + community = settings["community"] + self._check_snmp_community(community) + listen_val = self._snmp_listen_address(settings) general = {"enabled": "1", "community": community, "listen": listen_val} # Only what the caller gives: an empty one would blank the operator's. for key, field in self._SNMP_SYSTEM_FIELDS.items(): diff --git a/tests/quality_baseline.json b/tests/quality_baseline.json index 37fb471..e1f3188 100644 --- a/tests/quality_baseline.json +++ b/tests/quality_baseline.json @@ -57,7 +57,7 @@ "napalm_opnsense.resolver_mixin" ], "python_file_lines": { - "napalm_opnsense/opnsense.py": 3082 + "napalm_opnsense/opnsense.py": 3083 }, "untyped_public": [ "napalm_opnsense/opnsense.py::OPNsenseDriver.get_snmp_config"