From d60b3d3742d840b5ce24e4d757ce01c54fe9b990 Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Fri, 16 Oct 2026 15:18:45 +0200 Subject: [PATCH] feat: declare get_management_peer for choosing an SNMP agent's sources The caller has to name the sources an SNMP agent answers, and cannot reliably tell its own address as the device sees it (NAT, relays). SnmpAgentMixin now declares get_management_peer(): the address the device sees the management connection come from, or None. Optional: a driver that cannot tell does not implement it. --- napalm_device_types/fixes.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/napalm_device_types/fixes.py b/napalm_device_types/fixes.py index 9aa3a2b..33c2ea0 100644 --- a/napalm_device_types/fixes.py +++ b/napalm_device_types/fixes.py @@ -22,7 +22,7 @@ They replace ``run_device_action`` (docs/STRUCTURE.md): from __future__ import annotations -from typing import Any, Callable, List, Sequence, Tuple, TYPE_CHECKING +from typing import Any, Callable, List, Optional, Sequence, Tuple, TYPE_CHECKING from napalm_device_types.models import ( FixResultDict, @@ -77,7 +77,16 @@ class SnmpAgentMixin: ] ) - if TYPE_CHECKING: # pragma: no cover - the steps a driver implements + if TYPE_CHECKING: # pragma: no cover - declared for type checkers only + + def get_management_peer(self) -> Optional[str]: + """The address the device sees this management connection come from + (for SSH, the client side of ``SSH_CONNECTION``), or None when it cannot + tell. A fact for the caller choosing ``allowed_sources``; optional -- + a driver that cannot tell does not implement it.""" + ... + + # The steps a driver implements: def _install_snmp_agent(self) -> FixStepOutcomeDict: ...