fix: avoid duplicate 'port' kwarg when netmiko_optional_args already contains it
Extracted _netmiko_kwargs() helper that strips port/timeout/disabled_algorithms from netmiko_optional_args before spreading, so explicit values always win. Used in both _try_ssh and _action_fix_snmp SSH fallback loop. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
0cab237b1d
commit
22b83cf174
+22
-24
@@ -244,23 +244,32 @@ class ProcurveDriver(SwitchDriver):
|
||||
logger.warning("REST API connect failed for %s — falling back to CLI", self.hostname)
|
||||
return False
|
||||
|
||||
def _netmiko_kwargs(self, legacy: bool = False) -> dict:
|
||||
"""Return kwargs for ConnectHandler, merging explicit fields with netmiko_optional_args.
|
||||
|
||||
Explicit fields (port, timeout, disabled_algorithms) take precedence and are
|
||||
excluded from the spread to avoid 'multiple values for keyword argument' errors.
|
||||
"""
|
||||
extra = {k: v for k, v in self.netmiko_optional_args.items()
|
||||
if k not in ("port", "timeout", "disabled_algorithms")}
|
||||
return dict(
|
||||
device_type=self.NETMIKO_DEVICE_TYPE,
|
||||
host=self.hostname,
|
||||
username=self.username,
|
||||
password=self.password,
|
||||
secret=self._secret,
|
||||
port=self.port,
|
||||
timeout=self.timeout,
|
||||
disabled_algorithms=_SSH_DISABLED_LEGACY if legacy else _SSH_DISABLED_STANDARD,
|
||||
**extra,
|
||||
)
|
||||
|
||||
def _try_ssh(self, legacy: bool = False) -> bool:
|
||||
"""Probe and connect via SSH. Returns True on success."""
|
||||
label = "SSH-legacy" if legacy else "SSH"
|
||||
logger.debug("Trying %s for %s", label, self.hostname)
|
||||
disabled = _SSH_DISABLED_LEGACY if legacy else _SSH_DISABLED_STANDARD
|
||||
try:
|
||||
conn = ConnectHandler(
|
||||
device_type=self.NETMIKO_DEVICE_TYPE,
|
||||
host=self.hostname,
|
||||
username=self.username,
|
||||
password=self.password,
|
||||
secret=self._secret,
|
||||
port=self.port,
|
||||
timeout=self.timeout,
|
||||
disabled_algorithms=disabled,
|
||||
**self.netmiko_optional_args,
|
||||
)
|
||||
conn = ConnectHandler(**self._netmiko_kwargs(legacy))
|
||||
self._device = conn
|
||||
self._transport = "ssh_legacy" if legacy else "ssh"
|
||||
logger.info("Connected to %s via %s", self.hostname, label)
|
||||
@@ -1114,19 +1123,8 @@ class ProcurveDriver(SwitchDriver):
|
||||
|
||||
ssh_error: str = ""
|
||||
for legacy in (False, True):
|
||||
disabled = _SSH_DISABLED_LEGACY if legacy else _SSH_DISABLED_STANDARD
|
||||
try:
|
||||
conn = ConnectHandler(
|
||||
device_type=self.NETMIKO_DEVICE_TYPE,
|
||||
host=self.hostname,
|
||||
username=self.username,
|
||||
password=self.password,
|
||||
secret=self._secret,
|
||||
port=self.port,
|
||||
timeout=self.timeout,
|
||||
disabled_algorithms=disabled,
|
||||
**self.netmiko_optional_args,
|
||||
)
|
||||
conn = ConnectHandler(**self._netmiko_kwargs(legacy))
|
||||
self._device = conn
|
||||
self._transport = "ssh_legacy" if legacy else "ssh"
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user