Skip to content

Commit

Permalink
Add auto_probe option for JunOS devices (#1117)
Browse files Browse the repository at this point in the history
  • Loading branch information
alcm-b committed Feb 12, 2020
1 parent ec9906a commit 511efd6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/support/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ ____________________________________
* :code:`allow_agent` (ios, iosxr, nxos_ssh) - Paramiko argument, enable connecting to the SSH agent (default: ``False``).
* :code:`alt_host_keys` (ios, iosxr, nxos_ssh) - If ``True``, host keys will be loaded from the file specified in ``alt_key_file``.
* :code:`alt_key_file` (ios, iosxr, nxos_ssh) - SSH host key file to use (if ``alt_host_keys`` is ``True``).
* :code:`auto_probe` (junos) - A timeout in seconds, for which to probe the device. Probing determines if the device accepts remote connections. If `auto_probe` is set to ``0``, no probing will be done. (default: ``0``).
* :code:`auto_rollback_on_error` (ios) - Disable automatic rollback (certain versions of IOS support configure replace, but not rollback on error) (default: ``True``).
* :code:`config_lock` (iosxr, junos) - Lock the config during open() (default: ``False``).
* :code:`lock_disable` (junos) - Disable all configuration locking for management by an external system (default: ``False``).
Expand Down
8 changes: 5 additions & 3 deletions napalm/junos/junos.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from jnpr.junos.exception import ConfigLoadError
from jnpr.junos.exception import RpcTimeoutError
from jnpr.junos.exception import ConnectTimeoutError
from jnpr.junos.exception import ProbeError
from jnpr.junos.exception import LockError as JnprLockError
from jnpr.junos.exception import UnlockError as JnrpUnlockError

Expand Down Expand Up @@ -86,6 +87,7 @@ def __init__(self, hostname, username, password, timeout=60, optional_args=None)
self.keepalive = optional_args.get("keepalive", 30)
self.ssh_config_file = optional_args.get("ssh_config_file", None)
self.ignore_warning = optional_args.get("ignore_warning", False)
self.auto_probe = optional_args.get("auto_probe", 0)

# Define locking method
self.lock_disable = optional_args.get("lock_disable", False)
Expand Down Expand Up @@ -120,9 +122,9 @@ def __init__(self, hostname, username, password, timeout=60, optional_args=None)
def open(self):
"""Open the connection with the device."""
try:
self.device.open()
except ConnectTimeoutError as cte:
raise ConnectionException(cte.msg)
self.device.open(auto_probe=self.auto_probe)
except (ConnectTimeoutError, ProbeError) as cte:
raise ConnectionException(cte.msg) from cte
self.device.timeout = self.timeout
self.device._conn._session.transport.set_keepalive(self.keepalive)
if hasattr(self.device, "cu"):
Expand Down
2 changes: 1 addition & 1 deletion test/junos/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def facts(self):
def uptime(self):
return self._uptime

def open(self):
def open(self, auto_probe=0):
pass

def close(self):
Expand Down

0 comments on commit 511efd6

Please sign in to comment.