diff --git a/napalm_procurve/procurve.py b/napalm_procurve/procurve.py index f94c2a2..977fea9 100644 --- a/napalm_procurve/procurve.py +++ b/napalm_procurve/procurve.py @@ -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